-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
78 lines (62 loc) · 2.03 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
75
76
77
78
#!/bin/bash
bfg_update() {
bfg_check_environment
(
set -e
cd "$BFG_SHELL_HOME"
if [ -n "$(git status --porcelain)" ]; then
echo
echo "ERROR!"
echo
echo "The state of the repository in \$BFG_SHELL_HOME is dirty."
echo "Please clean the working tree before updating."
echo
exit 1
fi
echo
echo "Checking for updates..."
git fetch
LOCAL_BRANCH=$(git symbolic-ref --short HEAD)
LOCAL_COMMIT_COUNT=$(git rev-list --count HEAD)
CURRENT_COMMIT_HASH=$(git rev-parse --short HEAD)
NEW_COMMIT_HASH=$(git rev-parse --short origin)
REMOTE_COMMIT_COUNT=$(git rev-list --count origin)
echo
echo "Update check complete."
echo
echo "You are on the $LOCAL_BRANCH branch."
echo
echo "Local is at #$LOCAL_COMMIT_COUNT (hash $CURRENT_COMMIT_HASH)."
echo "Remote is at #$REMOTE_COMMIT_COUNT (hash $NEW_COMMIT_HASH)."
echo
if [ ! "$REMOTE_COMMIT_COUNT" -gt "$LOCAL_COMMIT_COUNT" ]; then
echo "No update is available."
echo
return 1
fi
echo "You can see a diff of the changes and list of commits here:"
printf "https://github.com/BenJetson/bfg_shell/compare/%s...%s\n" \
"$CURRENT_COMMIT_HASH" "$NEW_COMMIT_HASH"
echo
while true; do
printf "Would you like to update? [y/n]: "
read -r REPLY
case $REPLY in
[yY]) echo ; break ;;
[nN]) echo ; echo "Abort!"; echo; exit 1 ;;
*) printf " \033[31m %s \n\033[0m" "invalid input"
esac
done
echo "Fast forwarding changes..."
echo
git pull --ff-only
) || return $?
bfg_source "init"
bfg_init
(
bfg_source "splash"
bfg_splash
)
echo "Your BFG Shell installation has been updated."
echo "For release notes, see the GitHub page."
}