test
This commit is contained in:
parent
72875fdb28
commit
6334e3173a
@ -23,26 +23,32 @@ function update_script() {
|
|||||||
header_info
|
header_info
|
||||||
|
|
||||||
if [[ ! -d /opt/teamspeak-server ]]; then
|
if [[ ! -d /opt/teamspeak-server ]]; then
|
||||||
msg_error "No ${APP} Installation Found!"
|
msg_error "No ${APP} installation found!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RELEASE=$(curl -fsSL https://teamspeak.com/en/downloads/#server | sed -n '/teamspeak3-server_linux_amd64-/ { s/.*teamspeak3-server_linux_amd64-\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p; q }')
|
# define custom command to scrape version
|
||||||
|
local CUSTOM_CMD="curl -fsSL https://teamspeak.com/en/downloads/#server \
|
||||||
|
| sed -n '/teamspeak3-server_linux_amd64-/ { s/.*teamspeak3-server_linux_amd64-\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p; q }'"
|
||||||
|
|
||||||
if [ "${RELEASE}" != "$(cat ~/.teamspeak-server)" ] || [ ! -f ~/.teamspeak-server ]; then
|
if check_for_update "${APP}" "${CUSTOM_CMD}"; then
|
||||||
msg_info "Updating ${APP} LXC"
|
local release="$CHECK_UPDATE_RELEASE"
|
||||||
|
|
||||||
|
msg_info "Updating ${APP} LXC to v${release}"
|
||||||
$STD apk -U upgrade
|
$STD apk -U upgrade
|
||||||
$STD service teamspeak stop
|
$STD service teamspeak stop
|
||||||
curl -fsSL "https://files.teamspeak-services.com/releases/server/${RELEASE}/teamspeak3-server_linux_amd64-${RELEASE}.tar.bz2" -o ts3server.tar.bz2
|
|
||||||
tar -xf ./ts3server.tar.bz2
|
curl -fsSL "https://files.teamspeak-services.com/releases/server/${release}/teamspeak3-server_linux_amd64-${release}.tar.bz2" -o ts3server.tar.bz2
|
||||||
|
tar -xf ts3server.tar.bz2
|
||||||
cp -ru teamspeak3-server_linux_amd64/* /opt/teamspeak-server/
|
cp -ru teamspeak3-server_linux_amd64/* /opt/teamspeak-server/
|
||||||
rm -f ~/ts3server.tar.bz*
|
|
||||||
|
rm -f ts3server.tar.bz2
|
||||||
rm -rf teamspeak3-server_linux_amd64
|
rm -rf teamspeak3-server_linux_amd64
|
||||||
echo "${RELEASE}" >~/.teamspeak-server
|
|
||||||
|
echo "${release}" >~/.teamspeak-server
|
||||||
|
|
||||||
$STD service teamspeak start
|
$STD service teamspeak start
|
||||||
msg_ok "Updated Successfully"
|
msg_ok "Updated ${APP} successfully to v${release}"
|
||||||
else
|
|
||||||
msg_ok "No update required. ${APP} is already at ${RELEASE}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -1978,3 +1978,50 @@ EOF
|
|||||||
msg_ok "ClickHouse updated"
|
msg_ok "ClickHouse updated"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_for_update() {
|
||||||
|
local app="$1" # e.g. "wizarr"
|
||||||
|
local source="$2" # e.g. "org/repo" or custom command
|
||||||
|
local current_file="$HOME/.${app,,}"
|
||||||
|
|
||||||
|
msg_info "Check for update: $app"
|
||||||
|
|
||||||
|
# DNS check if GitHub
|
||||||
|
if [[ "$source" != *" "* ]] && [[ "$source" != http* ]]; then
|
||||||
|
if ! getent hosts api.github.com >/dev/null 2>&1; then
|
||||||
|
msg_error "Network error: cannot resolve api.github.com"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if ! command -v jq &>/dev/null; then
|
||||||
|
apt-get update -qq &>/dev/null && apt-get install -y jq &>/dev/null || {
|
||||||
|
msg_error "Failed to install jq"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# get release
|
||||||
|
local release=""
|
||||||
|
if [[ "$source" == *" "* ]] || [[ "$source" == http* ]]; then
|
||||||
|
release=$(eval "$source")
|
||||||
|
else
|
||||||
|
release=$(curl -fsSL "https://api.github.com/repos/$source/releases/latest" |
|
||||||
|
jq -r '.tag_name' | sed 's/^v//')
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$release" ]]; then
|
||||||
|
msg_error "Unable to determine latest release for $app"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# compare with local version
|
||||||
|
local current=""
|
||||||
|
[[ -f "$current_file" ]] && current=$(<"$current_file")
|
||||||
|
|
||||||
|
if [[ "$release" != "$current" ]] || [[ ! -f "$current_file" ]]; then
|
||||||
|
return 0 # update needed
|
||||||
|
else
|
||||||
|
msg_ok "$app is up to date (v$release)"
|
||||||
|
return 1 # no update
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user