-
Notifications
You must be signed in to change notification settings - Fork 9
/
update
executable file
·85 lines (71 loc) · 2.32 KB
/
update
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
79
80
81
82
83
84
85
#!/bin/bash
BRANCH="main"
if [ -n "$1" ] && [ "$1" == "--dev" ]; then
BRANCH="dev"
fi
SUIBASE_DIR="$HOME/suibase"
if [ -d "$HOME/sui-base" ] && [ ! -d "$SUIBASE_DIR" ]; then
("$HOME/sui-base/repair")
fi
cd "$SUIBASE_DIR" || {
echo "suibase not found. Please install it first."
exit 1
}
_LOCALNET_CMD_OUTPUT=$("$SUIBASE_DIR/scripts/localnet")
_CUR_VER=$(echo "$_LOCALNET_CMD_OUTPUT" | { head -n 1; cat >/dev/null 2>&1; } | sed 's/.*suibase \(.*\)/\1/g')
# Check if there are significant local changes. If any, protect the user
# from doing further git operations.
# shellcheck disable=SC2126
if [ ! "$(git status --porcelain | grep -vE "Cargo.lock|Move.lock|\?\?|Cargo.toml|Move.toml|Suibase.toml|package.json|index.js|update" | wc -l)" -eq "0" ]; then
if [ -n "$_CUR_VER" ]; then
echo "Current version $_CUR_VER"
echo
fi
echo "Git changes detected in ~/suibase."
echo
echo "Please commit or stash them before updating suibase."
echo
echo "Do 'git status' in ~/suibase to see changes."
exit 1
fi
# Get latest from remote
git remote update >/dev/null 2>&1
# Switch branch (as needed)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "$BRANCH" ]; then
echo "Switching to branch $BRANCH"
git checkout $BRANCH >/dev/null 2>&1
fi
V1=$(git rev-parse HEAD)
V2=$(git rev-parse '@{u}')
if [ "$V1" != "$V2" ]; then
echo "Updating..."
# Does more than needed, but should recover from most operator errors...
(cd "$SUI_REPO_DIR" && git fetch >/dev/null)
(cd "$SUI_REPO_DIR" && git reset --hard origin/$BRANCH >/dev/null)
(cd "$SUI_REPO_DIR" && git merge "origin/$BRANCH" >/dev/null)
# TODO Should stop services while update and restart only the ones that were running.
# Check for repair/update (noop if no change needed).
("$SUIBASE_DIR/repair")
_LOCALNET_CMD_OUTPUT=$("$SUIBASE_DIR/scripts/localnet")
_NEW_VER=$(echo "$_LOCALNET_CMD_OUTPUT" | { head -n 1; cat >/dev/null 2>&1; } | sed 's/.*suibase \(.*\)/\1/g')
if [ -n "$_CUR_VER" ]; then
echo "Old version $_CUR_VER"
fi
if [ -n "$_NEW_VER" ]; then
echo "New version $_NEW_VER"
fi
echo
echo -n "suibase updated successfully"
else
if [ -n "$_CUR_VER" ]; then
echo "Current version $_CUR_VER"
fi
echo
echo -n "suibase is already up to date"
fi
if [ $BRANCH == "dev" ]; then
echo " (dev)"
else
echo
fi