Browse Source

Improving update functions

pull/914/head
Daniel Gibbs 9 years ago
parent
commit
f7121a30e0
  1. 4
      lgsm/functions/command_update.sh
  2. 38
      lgsm/functions/update_steamcmd.sh
  3. 248
      lgsm/functions/update_ts3.sh

4
lgsm/functions/command_update.sh

@ -13,4 +13,6 @@ if [ "${gamename}" == "Teamspeak 3" ]; then
update_ts3.sh update_ts3.sh
elif [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then elif [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
update_steamcmd.sh update_steamcmd.sh
fi fi
core_exit.sh

38
lgsm/functions/update_steamcmd.sh

@ -6,9 +6,8 @@ lgsm_version="210516"
# Description:Handles updating using steamCMD. # Description:Handles updating using steamCMD.
fn_steamcmd_dl(){ fn_update_steamcmd_dl(){
cd "${rootdir}" cd "${rootdir}/steamcmd"
cd "steamcmd"
# Detects if unbuffer command is available. # Detects if unbuffer command is available.
if [ $(command -v stdbuf) ]; then if [ $(command -v stdbuf) ]; then
@ -83,7 +82,7 @@ fn_appmanifest_check(){
fi fi
} }
fn_logupdaterequest(){ fn_update_request_log(){
# Checks for server update requests from server logs. # Checks for server update requests from server logs.
fn_print_dots "Checking for update: Server logs" fn_print_dots "Checking for update: Server logs"
fn_script_log "Checking for update: Server logs" fn_script_log "Checking for update: Server logs"
@ -104,11 +103,13 @@ fn_logupdaterequest(){
unset updateonstart unset updateonstart
check_status.sh check_status.sh
if [ "${status}" != "0" ]; then if [ "${status}" != "0" ]; then
exitbypass=1
command_stop.sh command_stop.sh
update_dl.sh fn_update_steamcmd_dl
exitbypass=1
command_start.sh command_start.sh
else else
update_dl.sh fn_update_steamcmd_dl
fi fi
alert="update" alert="update"
alert.sh alert.sh
@ -118,7 +119,7 @@ fn_logupdaterequest(){
fi fi
} }
fn_steamcmdcheck(){ fn_update_steamcmd_check(){
fn_appmanifest_check fn_appmanifest_check
# Checks for server update from SteamCMD # Checks for server update from SteamCMD
fn_print_dots "Checking for update: SteamCMD" fn_print_dots "Checking for update: SteamCMD"
@ -183,11 +184,11 @@ fn_steamcmdcheck(){
if [ "${status}" != "0" ]; then if [ "${status}" != "0" ]; then
exitbypass=1 exitbypass=1
command_stop.sh command_stop.sh
fn_steamcmd_dl fn_update_steamcmd_dl
exitbypass=1 exitbypass=1
command_start.sh command_start.sh
else else
fn_steamcmd_dl fn_update_steamcmd_dl
fi fi
alert="update" alert="update"
alert.sh alert.sh
@ -205,4 +206,21 @@ fn_steamcmdcheck(){
} }
fn_steamcmdcheck if [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
# Goldsource servers bypass checks as fn_update_steamcmd_check does not work for appid 90 servers.
# forceupdate bypasses checks
check_status.sh
if [ "${status}" != "0" ]; then
exitbypass=1
command_stop.sh
fn_update_steamcmd_dl
exitbypass=1
command_start.sh
else
fn_update_steamcmd_dl
fi
else
fn_update_request_log
fn_update_steamcmd_check
fi
core_exit.sh

248
lgsm/functions/update_ts3.sh

@ -12,137 +12,135 @@ fn_update_ts3_dl(){
} }
fn_update_ts3_check(){ # Checks for server update from teamspeak.com using a mirror dl.4players.de.
# Checks for server update from teamspeak.com using a mirror dl.4players.de. fn_print_dots "Checking for update: teamspeak.com"
fn_print_dots "Checking for update: teamspeak.com" fn_script_log_info "Checking for update: teamspeak.com"
fn_script_log_info "Checking for update: teamspeak.com" sleep 1
# Gets currentbuild info
# Checks currentbuild info is available, if fails a server restart will be forced to generate logs.
if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
fn_print_fail "Checking for update: teamspeak.com"
sleep 1 sleep 1
fn_print_fail_nl "Checking for update: teamspeak.com: No logs with server version found"
# Gets currentbuild info fn_script_log_warn "Checking for update: teamspeak.com: No logs with server version found"
# Checks currentbuild info is available, if fails a server restart will be forced to generate logs. sleep 2
fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
fn_script_log_warn "Checking for update: teamspeak.com: Forcing server restart"
sleep 2
exitbypass=1
command_stop.sh
exitbypass=1
command_start.sh
sleep 1
# Check again and exit on failure.
if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
fn_print_fail "Checking for update: teamspeak.com" fn_print_fail_nl "Checking for update: teamspeak.com: Still No logs with server version found"
sleep 1 fn_script_log_fatal "Checking for update: teamspeak.com: Still No logs with server version found"
fn_print_fail_nl "Checking for update: teamspeak.com: No logs with server version found" core_exit.sh
fn_script_log_warn "Checking for update: teamspeak.com: No logs with server version found" fi
sleep 2 fi
fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
fn_script_log_warn "Checking for update: teamspeak.com: Forcing server restart" currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}')
sleep 2
exitbypass=1 # Gets the teamspeak server architecture.
command_stop.sh info_distro.sh
exitbypass=1 if [ "${arch}" == "x86_64" ]; then
command_start.sh ts3arch="amd64"
sleep 1 elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
# Check again and exit on failure. ts3arch="x86"
if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then else
fn_print_fail_nl "Checking for update: teamspeak.com: Still No logs with server version found" echo ""
fn_script_log_fatal "Checking for update: teamspeak.com: Still No logs with server version found" fn_print_failure "unknown or unsupported architecture: ${arch}"
core_exit.sh fn_script_log_fatal "unknown or unsupported architecture: ${arch}"
fi core_exit.sh
fi
# Gets availablebuild info.
# Grabs all version numbers but not in correct order.
wget "http://dl.4players.de/ts/releases/?C=M;O=D" -q -O -| grep -i dir | egrep -o '<a href=\".*\/\">.*\/<\/a>' | egrep -o '[0-9\.?]+'|uniq > .ts3_version_numbers_unsorted.tmp
# Sort version numbers
cat .ts3_version_numbers_unsorted.tmp | sort -r --version-sort -o .ts3_version_numbers_sorted.tmp
# Finds directory with most recent server version.
while read ts3_version_number; do
wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
if [ $? -eq 0 ]; then
availablebuild="${ts3_version_number}"
# Break while-loop, if the latest release could be found.
break
fi fi
done < .ts3_version_numbers_sorted.tmp
currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}') # Tidy up
rm -f ".ts3_version_numbers_unsorted.tmp"
rm -f ".ts3_version_numbers_sorted.tmp"
# Gets the teamspeak server architecture. # Checks availablebuild info is available
info_distro.sh if [ -z "${availablebuild}" ]; then
if [ "${arch}" == "x86_64" ]; then fn_print_fail "Checking for update: teamspeak.com"
ts3arch="amd64" sleep 1
elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
ts3arch="x86" fn_script_log_fatal "Failure! Checking for update: teamspeak.com: Not returning version info"
else core_exit.sh
echo "" else
fn_print_failure "unknown or unsupported architecture: ${arch}" fn_print_ok "Checking for update: teamspeak.com"
fn_script_log_fatal "unknown or unsupported architecture: ${arch}" fn_script_log_pass "Checking for update: teamspeak.com"
core_exit.sh sleep 1
fi fi
# Gets availablebuild info. # Removes dots so if can compare version numbers
currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
# Grabs all version numbers but not in correct order. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
wget "http://dl.4players.de/ts/releases/?C=M;O=D" -q -O -| grep -i dir | egrep -o '<a href=\".*\/\">.*\/<\/a>' | egrep -o '[0-9\.?]+'|uniq > .ts3_version_numbers_unsorted.tmp
# Sort version numbers
cat .ts3_version_numbers_unsorted.tmp | sort -r --version-sort -o .ts3_version_numbers_sorted.tmp
# Finds directory with most recent server version.
while read ts3_version_number; do
wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
if [ $? -eq 0 ]; then
availablebuild="${ts3_version_number}"
# Break while-loop, if the latest release could be found.
break
fi
done < .ts3_version_numbers_sorted.tmp
# Tidy up
rm -f ".ts3_version_numbers_unsorted.tmp"
rm -f ".ts3_version_numbers_sorted.tmp"
# Checks availablebuild info is available
if [ -z "${availablebuild}" ]; then
fn_print_fail "Checking for update: teamspeak.com"
sleep 1
fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
fn_script_log_fatal "Failure! Checking for update: teamspeak.com: Not returning version info"
core_exit.sh
else
fn_print_ok "Checking for update: teamspeak.com"
fn_script_log_pass "Checking for update: teamspeak.com"
sleep 1
fi
# Removes dots so if can compare version numbers if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]') echo -e "\n"
availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]') echo -e "Update available:"
sleep 1
if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then echo -e " Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m"
echo -e "\n" echo -e " Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m"
echo -e "Update available:" echo -e ""
sleep 1 sleep 1
echo -e " Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m" echo ""
echo -e " Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m" echo -en "Applying update.\r"
echo -e "" sleep 1
sleep 1 echo -en "Applying update..\r"
echo "" sleep 1
echo -en "Applying update.\r" echo -en "Applying update...\r"
sleep 1 sleep 1
echo -en "Applying update..\r" echo -en "\n"
sleep 1 fn_script_log "Update available"
echo -en "Applying update...\r" fn_script_log "Current build: ${currentbuild}"
sleep 1 fn_script_log "Available build: ${availablebuild}"
echo -en "\n" fn_script_log "${currentbuild} > ${availablebuild}"
fn_script_log "Update available"
fn_script_log "Current build: ${currentbuild}" unset updateonstart
fn_script_log "Available build: ${availablebuild}"
fn_script_log "${currentbuild} > ${availablebuild}" check_status.sh
if [ "${status}" == "0" ]; then
unset updateonstart fn_update_ts3_dl
exitbypass=1
check_status.sh command_start.sh
if [ "${status}" == "0" ]; then exitbypass=1
fn_update_ts3_dl command_stop.sh
exitbypass=1
command_start.sh
exitbypass=1
command_stop.sh
else
exitbypass=1
command_stop.sh
fn_update_ts3_dl
exitbypass=1
command_start.sh
fi
alert="update"
alert.sh
else else
echo -e "\n" exitbypass=1
echo -e "No update available:" command_stop.sh
echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m" fn_update_ts3_dl
echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m" exitbypass=1
echo -e "" command_start.sh
fn_print_ok_nl "No update available"
fn_script_log_info "Current build: ${currentbuild}"
fn_script_log_info "Available build: ${availablebuild}"
fi fi
} alert="update"
alert.sh
else
echo -e "\n"
echo -e "No update available:"
echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
echo -e ""
fn_print_ok_nl "No update available"
fn_script_log_info "Current build: ${currentbuild}"
fn_script_log_info "Available build: ${availablebuild}"
fi

Loading…
Cancel
Save