-
Notifications
You must be signed in to change notification settings - Fork 13
/
aurora.sh
110 lines (96 loc) · 2.48 KB
/
aurora.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
98
99
100
101
102
103
104
105
106
107
108
109
110
FILES_PATH=${FILES_PATH:-./}
CURRENT_VERSION=''
RELEASE_LATEST=''
get_current_version() {
CURRENT_VERSION=$(cat VERSION)
}
get_latest_version() {
# Get latest release version number
RELEASE_LATEST=$(curl -s https://api.github.com/repos/aurora-develop/aurora/releases/latest | jq -r '.tag_name')
if [[ -z "$RELEASE_LATEST" ]]; then
echo "error: Failed to get the latest release version, please check your network."
exit 1
fi
}
download_web() {
DOWNLOAD_LINK="https://github.com/aurora-develop/aurora/releases/latest/download/aurora-linux-amd64.tar.gz"
if ! wget -qO "$ZIP_FILE" "$DOWNLOAD_LINK"; then
echo 'error: Download failed! Please check your network or try again.'
return 1
fi
curl -s https://api.github.com/repos/aurora-develop/aurora/releases/latest | jq -r '.tag_name' > VERSION
return 0
}
decompression() {
tar -zxf "$1" -C "$TMP_DIRECTORY"
EXIT_CODE=$?
if [ ${EXIT_CODE} -ne 0 ]; then
"rm" -r "$TMP_DIRECTORY"
echo "removed: $TMP_DIRECTORY"
exit 1
fi
}
install_web() {
install -m 755 ${TMP_DIRECTORY}/aurora ${FILES_PATH}/app.js
}
run_web() {
killall app.js 2>/dev/null &
if [ "${PROXY_URL}" != "" ]; then
export PROXY_URL=${PROXY_URL}
fi
if [ "${Authorization}" != "" ]; then
export Authorization=${Authorization}
fi
export SERVER_PORT=8080
exec ./app.js 2>&1 &
}
generate_argo(){
cat > argo.sh << EOF
check_file() {
[ ! -e cloudflared ] && wget -O cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x cloudflared
}
run_argo() {
chmod +x cloudflared && nohup ./cloudflared tunnel --edge-ip-version auto --protocol http2 run --token ${ARGO_AUTH} 2>/dev/null 2>&1 &
}
if [ "${ARGO_AUTH}" != "" ]; then
check_file
run_argo
fi
EOF
}
generate_autodel() {
cat > auto_del.sh << EOF
while true; do
rm -rf /app/.git
sleep 5
done
EOF
}
generate_autodel
generate_argo
[ -e auto_del.sh ] && bash auto_del.sh &
if [ "${ARGO_AUTH}" != "" ]; then
bash argo.sh &
fi
TMP_DIRECTORY="$(mktemp -d)"
ZIP_FILE="${TMP_DIRECTORY}/aurora-linux-amd64.tar.gz"
get_current_version
get_latest_version
if [ "${RELEASE_LATEST}" = "${CURRENT_VERSION}" ]; then
"rm" -rf "$TMP_DIRECTORY"
run_web
exit
fi
download_web
EXIT_CODE=$?
if [ ${EXIT_CODE} -eq 0 ]; then
:
else
"rm" -r "$TMP_DIRECTORY"
run_web
exit
fi
decompression "$ZIP_FILE"
install_web
"rm" -rf "$TMP_DIRECTORY"
run_web