-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathupgrade-install.sh
executable file
·97 lines (79 loc) · 2.69 KB
/
upgrade-install.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
# set -x
TARGET_VERSION="$1"
TARGET_PATH="$2"
GITHUB_RELEASE_NAME="$3"
echo "Target Version: $TARGET_VERSION"
echo "Target Path: $TARGET_PATH"
echo "GitHub Release Name: $GITHUB_RELEASE_NAME"
echo ""
SHASUM_COMMAND=""
if command -v shasum > /dev/null; then
SHASUM_COMMAND="shasum -a 256"
elif command -v sha256sum > /dev/null; then
SHASUM_COMMAND="sha256sum"
else
echo "Failed to find shasum or sha256sum command."
exit 1
fi
tmp_dir=$(mktemp -d -t homebridge-ui-update.XXXXXXX)
if ! [ "$tmp_dir" ]; then
echo "Failed to create temporary directory."
exit 1
fi
echo "Downloading SHASUMS256.txt..."
if ! curl -fsSL# -o "$tmp_dir/SHASUMS256.txt" \
https://github.com/homebridge/homebridge-config-ui-x/releases/download/"${GITHUB_RELEASE_NAME}"/SHASUMS256.txt; then
echo "Failed to download SHASUMS256.txt"
exit 1
fi
echo "Downloading homebridge-config-ui-x-${TARGET_VERSION}.tar.gz..."
if ! curl -fL# -o "$tmp_dir/homebridge-config-ui-x-${TARGET_VERSION}.tar.gz" \
https://github.com/homebridge/homebridge-config-ui-x/releases/download/"${GITHUB_RELEASE_NAME}"/homebridge-config-ui-x-"${TARGET_VERSION}".tar.gz; then
echo "Failed to download homebridge-config-ui-x-${TARGET_VERSION}.tar.gz"
exit 1
fi
echo "Verifying download..."
if ! cd "$tmp_dir"; then
echo "Failed to change directory to $tmp_dir"
exit 1
fi
if ! $SHASUM_COMMAND -c SHASUMS256.txt; then
echo "Download failed integrity check."
rm -rf "$tmp_dir"
exit 1
fi
echo ""
if [ ! -d "$TARGET_PATH" ]; then
mkdir -p "$TARGET_PATH"
fi
echo "Creating backup..."
if [ -d "$TARGET_PATH/lib/node_modules/homebridge-config-ui-x" ]; then
mv "$TARGET_PATH/lib/node_modules/homebridge-config-ui-x" "$TARGET_PATH/lib/node_modules/.homebridge-config-ui-x.bak"
fi
echo ""
echo "Extracting..."
if ! tar --no-same-owner -xvmf "$tmp_dir/homebridge-config-ui-x-${TARGET_VERSION}.tar.gz" -C "$TARGET_PATH"; then
echo "Failed to extract."
mv "$TARGET_PATH/lib/node_modules/.homebridge-config-ui-x.bak" "$TARGET_PATH/lib/node_modules/homebridge-config-ui-x"
rm -rf "$tmp_dir"
exit 1
fi
echo ""
echo "Running post-install scripts..."
if ! cd "$TARGET_PATH/lib/node_modules/homebridge-config-ui-x"; then
echo "Failed to change directory to $TARGET_PATH/lib/node_modules/homebridge-config-ui-x"
exit 1
fi
if ! npm rebuild --foreground-scripts --unsafe-perm @homebridge/node-pty-prebuilt-multiarch; then
echo "Failed to rebuild."
mv "$TARGET_PATH/lib/node_modules/.homebridge-config-ui-x.bak" "$TARGET_PATH/lib/node_modules/homebridge-config-ui-x"
rm -rf "$tmp_dir"
exit 1
fi
echo ""
echo "Cleaning up..."
rm -rf "$TARGET_PATH/lib/node_modules/.homebridge-config-ui-x.bak"
rm -rf "$tmp_dir"
echo ""
echo "Installed v${TARGET_VERSION}"