-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgitupdate.sh
executable file
·59 lines (53 loc) · 1.38 KB
/
gitupdate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Scriptacular - gitupdate.sh
# Compare SHA-1 between local and remote repositories, git pull + FF merge in local if they differ
# Copyright 2013 Christopher Simpkins
# MIT License
#run in directory of script to make relative command paths work
cd "${0%/*}"
# Default to working directory
LOCAL_REPO="."
# Default to git pull with FF merge in quiet mode
GIT_COMMAND="git pull --quiet"
STOP_BOT="./stop_update.sh"
START_BOT="./start.sh"
# User messages
GU_ERROR_FETCH_FAIL="Unable to fetch the remote repository."
GU_ERROR_UPDATE_FAIL="Unable to update the local repository."
GU_ERROR_NO_GIT="This directory has not been initialized with Git."
GU_INFO_REPOS_EQUAL="The local repository is current. No update is needed."
GU_SUCCESS_REPORT="Update complete."
if [ $# -eq 1 ]; then
LOCAL_REPO="$1"
cd "$LOCAL_REPO"
fi
if [ -d ".git" ]; then
# update remote tracking branch
git remote update >&-
if (( $? )); then
echo $GU_ERROR_FETCH_FAIL >&2
exit 1
else
LOCAL_SHA=$(git rev-parse --verify HEAD)
REMOTE_SHA=$(git rev-parse --verify FETCH_HEAD)
if [ $LOCAL_SHA = $REMOTE_SHA ]; then
#no output on fail-if-no-updates to not generate cron mails
exit 0
else
cd ${0%/*}
$STOP_BOT
$GIT_COMMAND
$START_BOT
if (( $? )); then
echo $GU_ERROR_UPDATE_FAIL >&2
exit 1
else
echo $GU_SUCCESS_REPORT
fi
fi
fi
else
echo $GU_ERROR_NO_GIT >&2
exit 1
fi
exit 0