-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·75 lines (64 loc) · 1.41 KB
/
update.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# RL Labs update script
export RL_SCRIPTS_SRC="$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
set -e
if [ "$EUID" -ne 0 ]; then
echo "ERROR: This script must be run as root!" >&2
exit
fi
DO_FETCH=1
FORCE=
BRANCH=master
while [[ $# -gt 0 ]]; do
case "$1" in
--no-fetch)
DO_FETCH=0 ;;
--force)
FORCE=1 ;;
--branch)
BRANCH="$2"; shift ;;
*)
echo "Invalid argument: $1" >&2
exit 1 ;;
esac
shift
done
if [[ "$DO_FETCH" == "1" ]]; then
(
cd "$RL_SCRIPTS_SRC"
remote=update
remote_branch=update/$BRANCH
echo "Fetching from $remote..."
git fetch "$remote"
if git merge-base --is-ancestor $remote_branch HEAD; then
echo 'Already up-to-date'
exit 0
fi
if [[ "$FORCE" == "1" ]]; then
git reset --hard
fi
if [[ "$(git rev-parse --abbrev-ref HEAD)" != "$BRANCH" ]]; then
if git rev-parse --verify "$BRANCH" &>/dev/null; then
git checkout "$BRANCH"
else
git checkout -b "$BRANCH" "$remote_branch"
exit 0
fi
fi
if git merge-base --is-ancestor HEAD "$remote_branch"; then
echo 'Fast-forward possible. Merging...'
git merge --ff-only --stat "$remote_branch"
else
echo 'Fast-forward not possible. Resetting...'
git reset --hard "$remote_branch"
fi
)
fi
# run post-update hook
(
_RL_INTERNAL="rlrullz"
export RL_SCRIPTS_SRC
. "$RL_SCRIPTS_SRC/_post-update.sh"
)
rm -f "${RL_SCRIPTS_SRC}/.update-required"
echo "Lab scripts updated successfully!"