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