parent
2ece9d1bf5
commit
c1efe61711
|
@ -1,88 +1,75 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#Custom TS update script. There are 'better' update scripts out there.
|
# Custom TS update script. There are 'better' update scripts out there.
|
||||||
|
|
||||||
##########################
|
# Ensure required commands are available
|
||||||
# Requires jq #
|
command -v jq >/dev/null 2>&1 || { echo >&2 "jq is required but it's not installed. Aborting."; exit 1; }
|
||||||
# sudo apt install jq -y #
|
command -v curl >/dev/null 2>&1 || { echo >&2 "curl is required but it's not installed. Aborting."; exit 1; }
|
||||||
##########################
|
command -v wget >/dev/null 2>&1 || { echo >&2 "wget is required but it's not installed. Aborting."; exit 1; }
|
||||||
|
|
||||||
####################################### VARIABLES #####################################
|
# VARIABLES
|
||||||
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
|
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
|
||||||
tsdir=/home/teamspeak/
|
TS_DIR=/home/teamspeak/
|
||||||
|
|
||||||
|
# FUNCTIONS
|
||||||
|
|
||||||
#################################### FUNCTIONS ##################################
|
|
||||||
get_versions() {
|
get_versions() {
|
||||||
server=$(curl -Ls 'https://www.teamspeak.com/versions/server.json' | jq ".linux.x86_64")
|
server_info=$(curl -Ls 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86_64')
|
||||||
remote_version=$(printf '%s' "$server" | jq -r '.version')
|
remote_version=$(jq -r '.version' <<< "$server_info")
|
||||||
echo $remote_version
|
echo "$remote_version"
|
||||||
|
|
||||||
local_version=$(grep -Eom1 'Server Release \S*' "CHANGELOG" | cut -b 16-)
|
local_version=$(grep -Eom1 'Server Release \S*' "CHANGELOG" | cut -b 16-)
|
||||||
echo $local_version
|
echo "$local_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
download() {
|
download() {
|
||||||
wget https://files.teamspeak-services.com/releases/server/$remote_version/teamspeak3-server_linux_amd64-$remote_version.tar.bz2 -O TS.tar.bz2
|
wget "https://files.teamspeak-services.com/releases/server/$remote_version/teamspeak3-server_linux_amd64-$remote_version.tar.bz2" -O TS.tar.bz2
|
||||||
}
|
}
|
||||||
|
|
||||||
db_backup(){
|
db_backup() {
|
||||||
mkdir $tsdir/TS_Update/db_backup
|
mkdir -p "$TS_DIR/TS_Update/db_backup"
|
||||||
cp $tsdir/ts3server.sqlitedb $tsdir/TS_Update/db_backup/
|
cp "$TS_DIR/ts3server.sqlitedb" "$TS_DIR/TS_Update/db_backup/"
|
||||||
}
|
}
|
||||||
|
|
||||||
extract(){
|
extract() {
|
||||||
mkdir temp
|
mkdir -p temp
|
||||||
tar xf TS.tar.bz2 -C temp/
|
tar xf TS.tar.bz2 -C temp/
|
||||||
}
|
}
|
||||||
|
|
||||||
move(){
|
move() {
|
||||||
cp -rf temp/teamspeak3-server_linux_amd64/* $tsdir
|
cp -rf temp/teamspeak3-server_linux_amd64/* "$TS_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_ts(){
|
stop_ts() {
|
||||||
echo "Waiting for Teamspeak to save."
|
echo "Stopping Teamspeak server."
|
||||||
screen -p 0 -S teamspeak -X eval "stuff serverprocessstop\015"
|
screen -p 0 -S teamspeak -X stuff "serverprocessstop$(printf '\r')"
|
||||||
screen -S teamspeak -p 0 -X stuff "serverprocessstop^M"
|
|
||||||
sleep 15
|
sleep 15
|
||||||
screen -X -S teamspeak quit
|
screen -X -S teamspeak quit
|
||||||
}
|
}
|
||||||
|
|
||||||
clean_up(){
|
clean_up() {
|
||||||
rm -rf temp/
|
rm -rf temp/ TS.tar.bz2
|
||||||
chown -R teamspeak:teamspeak $tsdir
|
chown -R teamspeak:teamspeak "$TS_DIR"
|
||||||
rm -f TS.tar.bz2
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start_ts(){
|
start_ts() {
|
||||||
cd $tsdir
|
cd "$TS_DIR"
|
||||||
screen -dmS teamspeak ./teamspeak.sh
|
screen -dmS teamspeak ./teamspeak.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# MAIN SCRIPT
|
||||||
|
|
||||||
############################################################# RUN IT ! ##########################################
|
|
||||||
|
|
||||||
get_versions
|
get_versions
|
||||||
if [ $remote_version = $local_version ];
|
|
||||||
then
|
if [ "$remote_version" = "$local_version" ]; then
|
||||||
echo "No update needed!" && exit 0
|
echo "No update needed!"
|
||||||
else
|
exit 0
|
||||||
echo
|
else
|
||||||
echo "Update required"
|
echo "Update required"
|
||||||
echo
|
echo "Starting update"
|
||||||
sleep 0.5
|
download
|
||||||
echo
|
stop_ts
|
||||||
echo "Starting Update"
|
extract
|
||||||
echo
|
move
|
||||||
download
|
clean_up
|
||||||
stop_ts
|
start_ts
|
||||||
extract
|
|
||||||
move
|
|
||||||
clean_up
|
|
||||||
start_ts
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
exit
|
|
Loading…
Reference in New Issue