41 lines
1.7 KiB
Bash
Executable file
41 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env zsh
|
|
|
|
# author: Daniel Sommer <daniel.sommer@velvettear.de>
|
|
# license: MIT
|
|
|
|
ariang="/srv/ariang"
|
|
user="nginx"
|
|
|
|
[[ ! -e "$ariang" ]] && printf "> error: directory '"$ariang"' does not exist\n" 1>&2 && exit 1
|
|
|
|
file="$(find $ariang -type f -iname 'aria-ng*.min.js' -exec realpath {} \;)"
|
|
[[ -z "$file" ]] && printf "> error: could not determine file to extract the current version from\n" 1>&2 && exit 1
|
|
current_version="$(awk -F'buildVersion:"|\",buildCommit' '{print $2}' "$file" | xargs | cut -d "v" -f2)"
|
|
[[ -z "$current_version" ]] && printf "> error: could not determine current version\n" 1>&2 && exit 1
|
|
|
|
latest_release="$(curl -s -L https://api.github.com/repos/mayswind/AriaNg/releases/latest | grep tag_name | cut -d "\"" -f4 | cut -d "v" -f2)"
|
|
[[ -z "$latest_release" ]] && printf "> error: could not determine latest release\n" 1>&2 && exit 1
|
|
|
|
[[ "$current_version" == "$latest_release" ]] && printf "> current version '"$current_version"' is already up to date\n" && exit 0
|
|
|
|
tmp="$(mktemp -d)"
|
|
printf "> downloading latest release '"$latest_release"' to temporary directory '"$tmp"'..."
|
|
curl -s -L -o "$tmp/ariang-$latest_release.zip" "https://github.com/mayswind/AriaNg/releases/download/$latest_release/AriaNg-$latest_release.zip" &> /dev/null
|
|
[[ "$?" != "0" ]] && printf " error!\n" 1>&2 && exit 1
|
|
printf " done!\n"
|
|
|
|
printf "> extracting downloaded archive..."
|
|
cd "$tmp"
|
|
unzip "ariang-$latest_release.zip" &> /dev/null
|
|
[[ "$?" != "0" ]] && printf " error!\n" 1>&2 && exit 1
|
|
rm -rf "ariang-$latest_release.zip" &> /dev/null
|
|
printf " done!\n"
|
|
|
|
printf "> moving extracted files..."
|
|
rm -rf "$ariang" &> /dev/null
|
|
mv "$tmp" "$ariang" &> /dev/null
|
|
printf " done!\n"
|
|
|
|
printf "> setting correct permissions..."
|
|
chown -R "$user":"$user" "$ariang"
|
|
printf " done!\n"
|