forked from perber/leafwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
74 lines (61 loc) · 1.88 KB
/
Copy pathupdate.sh
File metadata and controls
74 lines (61 loc) · 1.88 KB
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
VERSION=""
PATH_TO_BINARY="/usr/local/bin/leafwiki"
RELEASE_LINK="https://github.com/perber/leafwiki/"
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
ARCH="amd64"
;;
arm64|aarch64)
ARCH="arm64"
;;
*)
echo "Unsupported architecture: $ARCH" >&2
exit 1
;;
esac
get_version(){
if [[ -z "$VERSION" ]]; then
LATEST_VERSION=$(curl -s https://api.github.com/repos/perber/leafwiki/releases/latest \
| grep '"tag_name":' \
| sed -E 's/.*"v([^"]+)".*/\1/')
VERSION=$LATEST_VERSION
if [[ -z "$LATEST_VERSION" || "$LATEST_VERSION" == "null" ]]; then
echo "Failed to determine the latest LeafWiki version from GitHub." >&2
exit 1
fi
fi
}
download_binary(){
TMP_FILE="/tmp/leafwiki-v${VERSION}-linux-${ARCH}"
wget -q -O "$TMP_FILE" "${RELEASE_LINK}releases/download/v${VERSION}/leafwiki-v${VERSION}-linux-${ARCH}" || {
echo "Download failed. Aborting update." >&2
exit 1
}
if [ ! -s "$TMP_FILE" ]; then
echo "Downloaded file is empty. Aborting update." >&2
rm -f "$TMP_FILE"
exit 1
fi
# Backup current binary
mv "$PATH_TO_BINARY" "${PATH_TO_BINARY}.bak"
# Install new binary
mv "$TMP_FILE" "$PATH_TO_BINARY"
chmod +x "$PATH_TO_BINARY"
}
EXIST=$(test -x $PATH_TO_BINARY && echo "true" || echo "false")
if [[ $EXIST == "false" ]]; then
echo "leafwiki is not present in /usr/local/bin/"
exit 1
fi
get_version
download_binary
systemctl daemon-reload
systemctl restart leafwiki
echo "======================================="
echo "== LeafWiki update completed! =="
echo "== =="
printf "== %-33s ==\n" "New Version: $VERSION"
echo "== =="
echo "======================================="