-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharcaea-download.sh
executable file
·101 lines (90 loc) · 3.05 KB
/
arcaea-download.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
#!/bin/bash
set -xeu
URL='https://webapi.lowiro.com/webapi/serve/static/bin/arcaea/apk'
REQUIRED_PACKAGES=(curl jq wget unzip)
function write_diff_after_update(){
echo "Diff after updated from $current_version to $latest_version"
# compare file and content between downloaded files and current files
if [[ ! -d $HOME/arcaea-download/diff ]]; then
mkdir -p $HOME/arcaea-download/diff
fi
diff --color -bur /opt/arcaea /tmp/arcaea | tee $HOME/arcaea-download/diff/$current_version-$latest_version.diff
}
function check_package(){
for package in "${REQUIRED_PACKAGES[@]}"; do
if [[ ! $(which "$package") ]]; then
>&2 echo "Please install $package using your package manager."
exit 1
fi
done
}
function get_apk_url(){
webapi_response=$(curl -s $URL | jq)
# check if failed to get download link
if [[ $(echo $webapi_response | jq -r '.success') == 'false' ]]; then
>&2 echo "Failed to get download link."
exit 1
fi
}
function write_version(){
apk_version=$(echo $webapi_response | jq -r '.value.version')
echo $apk_version > $HOME/version.txt
}
function check_version(){
latest_version=$(echo $webapi_response | jq -r '.value.version')
if [[ -f version.txt ]]; then
current_version=$(cat $HOME/version.txt)
if [[ $latest_version == "$current_version" ]]; then
echo "You are already on the latest version."
is_latest=true
exit
elif [[ $latest_version != "$current_version" ]]; then
echo "New version available: $latest_version, current version: $current_version."
is_latest=false
fi
else
echo "version.txt not found."
current_version="0.0.0"
is_latest=false
fi
}
function download_apk(){
if [[ $is_latest == true ]]; then
echo "You are already on the latest version."
exit 0
fi
apk_url=$(echo $webapi_response | jq -r '.value.url')
wget -qO /tmp/arcaea-$latest_version.apk $apk_url
}
function uncompress_apk(){
if [[ ! -f /tmp/arcaea-$latest_version.apk ]]; then
>&2 echo "APK not found."
exit 1
fi
unzip -oqq /tmp/arcaea-$latest_version.apk -d /tmp/arcaea_apk
mkdir -p $HOME/arcaea-download/tree
tree /tmp/arcaea_apk > $HOME/arcaea-download/tree/$latest_version.txt
}
function move_assets(){
sudo mkdir -p /tmp/arcaea
echo "Copy assets from /tmp/arcaea_apk/assets to /tmp/arcaea/assets"
sudo cp -arf /tmp/arcaea_apk/assets /tmp/arcaea/
sudo mkdir -p /opt/arcaea
write_diff_after_update
sudo cp -arf /tmp/arcaea/assets /opt/arcaea
}
function cleanup(){
sudo rm -rf /tmp/arcaea{{-${latest_version}.,_}apk,}
}
function main(){
get_apk_url && check_package && check_version
if [[ $is_latest == true ]]; then
echo "You are already on the latest version."
exit 0
else
download_apk && uncompress_apk && move_assets &&
cleanup && write_version
fi
}
echo "Welcome to Arcaea downloader. This script will download the latest version of Arcaea."
main