websoft9/install/update_appstore.sh

85 lines
2.8 KiB
Bash
Raw Normal View History

2023-06-15 09:40:06 +08:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
function error_exit {
echo "$1" 1>&2
exit 1
}
trap 'error_exit "Please push issue to: https://github.com/Websoft9/StackHub/issues"' ERR
urls=(
https://ghproxy.com/https://github.com
https://github.com
https://gitee.com
)
function fastest_url() {
urls=("$@")
fastest_url=""
fastest_time=0
for url in "${urls[@]}"; do
if curl --output /dev/null --silent --head --fail --max-time 3 "$url"; then
data="url is available"
else
continue
fi
time=$(curl --connect-timeout 3 -s -w '%{time_total}\n' -o /dev/null $url)
if (( $(echo "$time < $fastest_time || $fastest_time == 0" | bc -l) )); then
fastest_time=$time
fastest_url=$url
fi
done
echo "$fastest_url"
}
LibraryUpdate(){
2023-06-17 16:34:48 +08:00
echo "auto_update start..." >> /tmp/auto_update.txt
2023-06-21 09:07:40 +08:00
if [ ! -f /data/library/install/version.json ]; then
old_library_version="0.0.1"
else
old_library_version=$(cat /data/library/install/version.json | jq .VERSION | tr -d '"')
fi
2023-06-15 09:40:06 +08:00
latest_library_version=$(curl https://websoft9.github.io/docker-library/install/version.json | jq .VERSION | tr -d '"')
2023-06-21 16:22:53 +08:00
2023-06-15 09:40:06 +08:00
if [ "$old_library_version" \< "$latest_library_version" ]; then
echo "start to update Library..."
2023-06-21 16:22:53 +08:00
release_version=$(curl https://websoft9.github.io/stackhub-web/CHANGELOG.md | head -n 1 |cut -d' ' -f2)
2023-06-15 09:40:06 +08:00
fastest=$(fastest_url "${urls[@]}")
echo "fasturl is: "$fastest
2023-06-21 16:22:53 +08:00
cd /tmp && rm -rf /tmp/library /tmp/stackhub-web
2023-06-15 09:40:06 +08:00
if [[ $fastest == *gitee.com* ]]; then
echo "update from gitee"
wget $fastest/websoft9/docker-library/repository/archive/$latest_library_version
unzip $latest_library_version
mv docker-library* library
rm -f $latest_library_version
2023-06-21 16:22:53 +08:00
wget $fastest/websoft9/stackhub-web/repository/archive/$release_version
2023-06-15 09:40:06 +08:00
unzip $release_version
2023-06-21 16:22:53 +08:00
mv stackhub-web* stackhub-web
2023-06-15 09:40:06 +08:00
rm -f $release_version
else
echo "update from github"
wget $fastest/websoft9/docker-library/archive/refs/tags/$latest_library_version.zip
unzip $latest_library_version.zip
mv docker-library* library
rm -f $latest_library_version.zip
2023-06-21 16:22:53 +08:00
wget $fastest/websoft9/stackhub-web/archive/refs/tags/$release_version.zip
2023-06-15 09:40:06 +08:00
unzip $release_version.zip
2023-06-21 16:22:53 +08:00
mv stackhub-web* stackhub-web
2023-06-15 09:40:06 +08:00
rm -f $release_version.zip
fi
rm -rf /data/library && cp -r /tmp/library /data
2023-06-21 16:22:53 +08:00
rm -rf /usr/share/cockpit/appstore/static/data && cp -r /tmp/stackhub-web/plugins/appstore/build/static/data /usr/share/cockpit/appstore/static
rm -rf /usr/share/cockpit/myapps/static/logos && cp -r /tmp/stackhub-web/plugins/myapps/build/static/logos /usr/share/cockpit/myapps/static
2023-06-15 09:40:06 +08:00
else
echo "Library is not need to update"
fi
2023-06-20 15:24:14 +08:00
rm $0
2023-06-15 09:40:06 +08:00
}
2023-06-15 14:28:03 +08:00
LibraryUpdate