Skip to content

Commit

Permalink
Move all local variables to under main
Browse files Browse the repository at this point in the history
  • Loading branch information
klightspeed committed Aug 5, 2018
1 parent e38b1c3 commit c8c0f9a
Showing 1 changed file with 65 additions and 57 deletions.
122 changes: 65 additions & 57 deletions tools/arkmanager
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ arkstRootUseEnv=''
arkstGlobalCfgFile='/etc/arkmanager/arkmanager.cfg'
arkstUserCfgFile='.arkmanager.cfg'

#--------------------
# Installation
#--------------------

doUpgradeTools() {
local sudo=sudo
if [ $(id -u) == 0 -o "$steamcmd_user" == "--me" ]; then
Expand Down Expand Up @@ -204,63 +208,6 @@ if [ "$(id -u)" == "0" ]; then
exit 0
fi

#---------------------
# Variables
#---------------------

# Global variables
if [ -f "${arkstGlobalCfgFile}" ]; then
source "${arkstGlobalCfgFile}"
fi

if [ -f "${HOME}/${arkstUserCfgFile}" ]; then
source "${HOME}/${arkstUserCfgFile}"
fi

if [ -n "${serverbasedir}" && -d "${serverbasedir}" ]; then
cd "${serverbasedir}"
elif [ -d "${HOME}" ]; then
cd "${HOME}"
elif [ -d "${steamcmdroot}" ]; then
cd "${steamcmdroot}"
elif [[ ! -d "${PWD}" || ! -r "${PWD}" || ! -x "${PWD}" ]]; then
cd /
fi

lsof=lsof
if [ -x /usr/sbin/lsof ]; then
lsof=/usr/sbin/lsof
fi

# Local variables
instver=""
bnumber=""
GREEN="\\033[1;32m"
RED="\\033[1;31m"
YELLOW="\\e[0;33m"
NORMAL="\\033[0;39m"
maxOpenFiles=100000

# Set TERM to "dumb" if TERM is not set
export TERM=${TERM:-dumb}

arkmanagerLog="arkmanager.log" # here are logged the actions performed by arkmanager
arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer

appid="${appid:-376030}"
mod_appid="${mod_appid:-346110}"
install_bindir="${install_bindir:-${0%/*}}"
install_libexecdir="${install_libexecdir:-${install_bindir%/*}/libexec/arkmanager}"
steamcmd_workshoplog="${steamcmd_workshoplog:-${HOME}/Steam/logs/workshop_log.txt}"

if [ "$steamcmd_user" == "--me" ]; then
install_datadir="${install_datadir:-${HOME}/.share/local/arkmanager}"
else
install_datadir="${install_datadir:-${install_bindir%/*}/share/arkmanager}"
fi

declare -A modsrcdirs

#---------------------
# functions
#---------------------
Expand Down Expand Up @@ -1752,6 +1699,7 @@ doUpdate() {
local appbeta=
local appbetapass=
local mapfile=
declare -A modsrcdirs
for arg in "$@"; do
case "$arg" in
Expand Down Expand Up @@ -3117,6 +3065,58 @@ useConfig() {
arkupdatetimefile="${arkupdatetimefile:-${arkserverdir}/Saved/.ark-update.time}"
}
loadGlobalConfig() {
if [ -f "${arkstGlobalCfgFile}" ]; then
source "${arkstGlobalCfgFile}"
fi
if [ -f "${HOME}/${arkstUserCfgFile}" ]; then
source "${HOME}/${arkstUserCfgFile}"
fi
lsof=lsof
if [ -x /usr/sbin/lsof ]; then
lsof=/usr/sbin/lsof
fi
# Local variables
GREEN="\\033[1;32m"
RED="\\033[1;31m"
YELLOW="\\e[0;33m"
NORMAL="\\033[0;39m"
maxOpenFiles=100000
# Set TERM to "dumb" if TERM is not set
export TERM=${TERM:-dumb}
arkmanagerLog="arkmanager.log" # here are logged the actions performed by arkmanager
arkserverLog="arkserver.log" # here is logged the output of ShooterGameServer
appid="${appid:-376030}"
mod_appid="${mod_appid:-346110}"
install_bindir="${install_bindir:-${0%/*}}"
install_libexecdir="${install_libexecdir:-${install_bindir%/*}/libexec/arkmanager}"
steamcmd_workshoplog="${steamcmd_workshoplog:-${HOME}/Steam/logs/workshop_log.txt}"
if [ "$steamcmd_user" == "--me" ]; then
install_datadir="${install_datadir:-${HOME}/.share/local/arkmanager}"
else
install_datadir="${install_datadir:-${install_bindir%/*}/share/arkmanager}"
fi
}
setScriptWorkingDir() {
if [[ -n "${serverbasedir}" && -d "${serverbasedir}" ]]; then
cd "${serverbasedir}"
elif [ -d "${HOME}" ]; then
cd "${HOME}"
elif [ -d "${steamcmdroot}" ]; then
cd "${steamcmdroot}"
elif [[ ! -d "${PWD}" || ! -r "${PWD}" || ! -x "${PWD}" ]]; then
cd /
fi
}
addArkOpt() {
local optname="${1%%=*}"
local optval="${1#*=}"
Expand Down Expand Up @@ -3243,6 +3243,11 @@ EOE
#---------------------
main(){
# Global variables
loadGlobalConfig
setScriptWorkingDir
# check the configuration and throw errors or warnings if needed
checkConfig
Expand Down Expand Up @@ -3456,6 +3461,7 @@ main(){
checkForModUpdate "${options[@]}"
;;
installmod)
declare -A modsrcdirs
doInstallMod "${args[@]}"
;;
enablemod)
Expand All @@ -3465,6 +3471,7 @@ main(){
doDisableMod "${args[@]}"
;;
installmods)
declare -A modsrcdirs
doInstallAllMods
;;
uninstallmods)
Expand All @@ -3474,6 +3481,7 @@ main(){
doUninstallMod "${args[@]}"
;;
reinstallmod)
declare -A modsrcdirs
doUninstallMod "${args[@]}"
doInstallMod "${args[@]}"
;;
Expand Down

0 comments on commit c8c0f9a

Please sign in to comment.