Implement more mod handling.

This commit is contained in:
Daniel Ceregatti 2022-07-22 22:19:33 -07:00
parent 1ba6a057c0
commit 401d857a7f

View file

@ -45,13 +45,8 @@ profile="-profiles=${HOME}/serverprofile/"
# No logs? This should read "-somelogs" # No logs? This should read "-somelogs"
logs="-nologs" logs="-nologs"
# Mods. WIP. This will have to come from another file, as the plan is to manage this with
# this very script.
# mods="@CF;@community-Online-Tools;@Banov;@SimpleAutorun"
mods=""
# Put them all together # Put them all together
dayzparameter=" -config=${config} -port=${port} -mod='${mods}' -freezecheck -fps=60 -BEpath=${HOME}/serverfiles/battleye ${profile} ${logs}" dayzparameter=" -config=${config} -port=${port} -freezecheck -fps=60 -BEpath=${HOME}/serverfiles/battleye ${profile} ${logs}"
# Base directories # Base directories
CFG_SRC_FILES="/files" CFG_SRC_FILES="/files"
@ -80,7 +75,7 @@ fi
declare -a workshopID declare -a workshopID
workshoplist="" workshoplist=""
workshopfolder="${SERVER_FILES}/steamapps/workshop/content/${dayz_id}" workshopfolder="${SERVER_FILES}/steamapps/workshop/content/${dayz_id}"
mod_command_line="" mod_command_line="-mod='"
# Other stuff # Other stuff
YES="${green}yes${default}" YES="${green}yes${default}"
@ -191,12 +186,12 @@ fn_start_dayz(){
trap ' trap '
report report
' EXIT ' EXIT
fn_workshop_mods fn_mod_cmd
cd ${SERVER_FILES} cd ${SERVER_FILES}
# Run the server. Allow docker to restart the container if the script exits with a code other than 0. This is so we can # Run the server. Allow docker to restart the container if the script exits with a code other than 0. This is so we can
# safely shut the container down without killing the server within. # safely shut the container down without killing the server within.
printf "[ ${green}DayZ${default} ] Server starting...\n" printf "[ ${green}DayZ${default} ] Server starting...\n"
./DayZServer $dayzparameter ./DayZServer ${dayzparameter} ${mod_command_line}
EXIT_CODE=$? EXIT_CODE=$?
printf "[ ${yellow}DayZ${default} ] Server exited. Exit code: ${EXIT_CODE}\n" printf "[ ${yellow}DayZ${default} ] Server exited. Exit code: ${EXIT_CODE}\n"
exit ${EXIT_CODE} exit ${EXIT_CODE}
@ -307,7 +302,7 @@ fn_update_dayz(){
printf "\nApplying update" printf "\nApplying update"
# run update # run update
fn_runupdate_dayz fn_runupdate_dayz
fn_workshop_mods fn_update_mods
else else
printf "\r[ ${green}OK${default} ] Checking for update:: No update available\n" printf "\r[ ${green}OK${default} ] Checking for update:: No update available\n"
printf "\nNo update available:\n" printf "\nNo update available:\n"
@ -331,27 +326,26 @@ fn_get_mods(){
fn_update_mods(){ fn_update_mods(){
fn_get_mods fn_get_mods
${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" ${workshoplist} +quit ${STEAMCMD} +force_install_dir ${SERVER_FILES} +login "${steamlogin}" ${workshoplist} +quit
echo
} }
fn_link_mods(){ fn_link_mod(){
for i in "${workshopID[@]}" MODNAME=$(cut -d '"' -f 2 <<< $(grep name ${workshopfolder}/${1}/meta.cpp))
do if [ ! -L "${SERVER_FILES}/@${MODNAME}" ]
ID=$(echo ${i} | cut -d: -f1) then
NAME=$(echo ${i} | cut -d: -f2) ln -s ${workshopfolder}/${1} "${SERVER_FILES}/@${MODNAME}"
ACTIVE=$(echo ${i} | cut -d: -f3) echo "Created symlink for mod id ${1}"
if [[ ${ID} =~ ^[0-9] ]] && [ $(expr length $i) -gt 7 ] && [ -d "${workshopfolder}/${ID}" ] else
then echo "Symlink for mod id ${1} already exists"
modname=$(cut -d '"' -f 2 <<< $(grep name ${workshopfolder}/${ID}/meta.cpp)) fi
if [ ! -d "${SERVER_FILES}/@${modname}" ]
then # find "${workshopfolder}/${1}" -depth -print -exec rename -f 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
ln -s ${workshopfolder}/${ID} "${SERVER_FILES}/@${modname}" &> /dev/null
fi
find "${workshopfolder}/${ID}" -depth -exec rename -f 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
fi
done
if ls ${SERVER_FILES}/@* 1> /dev/null 2>&1 if ls ${SERVER_FILES}/@* 1> /dev/null 2>&1
then then
cp -vu ${SERVER_FILES}/@*/keys/* "${SERVER_FILES}/keys/" > /dev/null 2>&1 echo "Copying key files..."
cp -vu "${workshopfolder}/*/Keys/*" "${SERVER_FILES}/keys/" 2> /dev/null
# cp -vu "${SERVER_FILES}/@*/{K,k}eys/*" "${SERVER_FILES}/keys/"
fi fi
} }
@ -359,6 +353,15 @@ fn_add_mod(){
if [ -d "${workshopfolder}/${1}" ] if [ -d "${workshopfolder}/${1}" ]
then then
echo -e "${yellow}Warning: The mod directory ${workshopfolder}/${1} already exists!${default}" echo -e "${yellow}Warning: The mod directory ${workshopfolder}/${1} already exists!${default}"
MODNAME=$(cut -d '"' -f 2 <<< $(grep name ${workshopfolder}/${1}/meta.cpp))
else
echo -e "${green}The mod directory ${workshopfolder}/${1} doesn't exist...${default}"
fi
if [ -L "${SERVER_FILES}/@${MODNAME}" ]
then
echo -e "${yellow}Warning: The mod symlink ${SERVER_FILES}/@${MODNAME} already exists!${default}"
else
echo -e "${green}The mod symlink ${SERVER_FILES}/@${MODNAME} doesn't exist...${default}"
fi fi
if grep -qP "\b${1}\b" "${WORKSHOP_CFG}" if grep -qP "\b${1}\b" "${WORKSHOP_CFG}"
then then
@ -368,14 +371,12 @@ fn_add_mod(){
echo "Adding mod id ${1}" echo "Adding mod id ${1}"
echo "${1}:MODNAME:1" >> ${WORKSHOP_CFG} echo "${1}:MODNAME:1" >> ${WORKSHOP_CFG}
fn_update_mods fn_update_mods
fn_link_mod ${1}
if [ -d "${workshopfolder}/${1}" ] if [ -d "${workshopfolder}/${1}" ]
then then
MODNAME=$(cut -d '"' -f 2 <<< $(grep name ${workshopfolder}/${1}/meta.cpp))
sed -i "${WORKSHOP_CFG}" -e "s/${1}:MODNAME/${1}:${MODNAME}/" sed -i "${WORKSHOP_CFG}" -e "s/${1}:MODNAME/${1}:${MODNAME}/"
echo
echo "Mod id ${1} - ${MODNAME} - added" echo "Mod id ${1} - ${MODNAME} - added"
else else
echo
echo "Installation failed! See above (You probably need to use a real Steam login)" echo "Installation failed! See above (You probably need to use a real Steam login)"
head -n-1 "${WORKSHOP_CFG}" > /tmp/workshop.cfg.tmp head -n-1 "${WORKSHOP_CFG}" > /tmp/workshop.cfg.tmp
mv /tmp/workshop.cfg.tmp "${WORKSHOP_CFG}" mv /tmp/workshop.cfg.tmp "${WORKSHOP_CFG}"
@ -389,7 +390,7 @@ fn_remove_mod(){
echo "Removing directory ${workshopfolder}/${1}" echo "Removing directory ${workshopfolder}/${1}"
rm -rf "${workshopfolder}/${1}" rm -rf "${workshopfolder}/${1}"
fi fi
if [ -s "${SERVER_FILES}/@${MODNAME}" ] if [ -L "${SERVER_FILES}/@${MODNAME}" ]
then then
echo "Removing symlink ${SERVER_FILES}/@${MODNAME}" echo "Removing symlink ${SERVER_FILES}/@${MODNAME}"
rm -f "${SERVER_FILES}/@${MODNAME}" rm -f "${SERVER_FILES}/@${MODNAME}"
@ -397,23 +398,55 @@ fn_remove_mod(){
if grep -q ${1} "${WORKSHOP_CFG}" if grep -q ${1} "${WORKSHOP_CFG}"
then then
echo "Removing workshop file entry" echo "Removing workshop file entry"
sed -i "${WORKSHOP_CFG}" -e "/${1}:${MODNAME}:\d/d" sed -i "${WORKSHOP_CFG}" -e "/${1}:/d"
fi fi
echo "Mod id ${1} - ${MODNAME} - removed" echo "Mod id ${1} - ${MODNAME} - removed"
} }
fn_activate_mod(){ fn_activate_mod(){
echo "Activcating mod id ${1}" fn_get_mods
for i in "${workshopID[@]}"
do
ID=$(echo ${i} | cut -d: -f1)
NAME=$(echo ${i} | cut -d: -f2)
ACTIVE=$(echo ${i} | cut -d: -f3)
if [[ ${ID} = ${1} ]]
then
if [[ ${ACTIVE} = "0" ]]
then
sed -i "${WORKSHOP_CFG}" -e 's/'${1}':\(.*\):0/'${1}':\1:1/'
echo "Activcated mod id ${1}"
else
echo "Mod id ${1} was already active"
fi
fi
done
} }
fn_deactivate_mod(){ fn_deactivate_mod(){
echo "Deactivcating mod id ${1}" fn_get_mods
for i in "${workshopID[@]}"
do
ID=$(echo ${i} | cut -d: -f1)
NAME=$(echo ${i} | cut -d: -f2)
ACTIVE=$(echo ${i} | cut -d: -f3)
if [[ ${ID} = ${1} ]]
then
if [[ ${ACTIVE} = "1" ]]
then
sed -i "${WORKSHOP_CFG}" -e 's/'${1}':\(.*\):1/'${1}':\1:0/'
echo "Dectivcated mod id ${1}"
else
echo "Mod id ${1} was already inactive"
fi
fi
done
} }
fn_list_mods(){ fn_list_mods(){
fn_get_mods fn_get_mods
spaces=" " spaces=" "
echo -e "ID\t\tName\t\t\tStatus\tURL" echo -e "ID\t\tName\t\t\tActive\tURL"
for i in "${workshopID[@]}" for i in "${workshopID[@]}"
do do
ID=$(echo ${i} | cut -d: -f1) ID=$(echo ${i} | cut -d: -f1)
@ -436,6 +469,7 @@ fn_mod_cmd(){
mod_command_line="${mod_command_line}@${modname};" mod_command_line="${mod_command_line}@${modname};"
fi fi
done done
mod_command_line="${mod_command_line}'"
} }
fn_workshop_mods(){ fn_workshop_mods(){
@ -450,7 +484,6 @@ fn_workshop_mods(){
fi fi
# Most mods require a valid Steam login. Not all will work with the anonymous user. # Most mods require a valid Steam login. Not all will work with the anonymous user.
fn_steamlogin_dayz fn_steamlogin_dayz
fn_get_mods
# Options # Options
case "${1}" in case "${1}" in
activate) activate)
@ -472,7 +505,6 @@ fn_workshop_mods(){
update) update)
echo "Updating mods..." echo "Updating mods..."
fn_update_mods fn_update_mods
fn_link_mods
;; ;;
**) **)
fn_usage fn_usage
@ -488,7 +520,8 @@ fn_status(){
INSTALLED="${NO}" INSTALLED="${NO}"
LOGGED_IN="${NO}" LOGGED_IN="${NO}"
RUNNING="${NO}" RUNNING="${NO}"
MOD_INSTALLED="${yellow}0${default}" fn_get_mods
MOD_INSTALLED="${green}${#workshopID[@]}${default}"
MOD_LIST="" MOD_LIST=""
# DayZ Server files installation # DayZ Server files installation
if [ -f "${SERVER_INSTALL_FILE}" ] if [ -f "${SERVER_INSTALL_FILE}" ]
@ -502,6 +535,8 @@ fn_status(){
if grep -q anonymous "${STEAM_LOGIN}" if grep -q anonymous "${STEAM_LOGIN}"
then then
ANONYMOUS="(as anonymous)" ANONYMOUS="(as anonymous)"
else
ANONYMOUS="(not anonymous)"
fi fi
fi fi
# Running or not # Running or not
@ -509,6 +544,7 @@ fn_status(){
then then
RUNNING="${YES}" RUNNING="${YES}"
fi fi
fn_mod_cmd
# Number of mods plus the list denoting on or off # Number of mods plus the list denoting on or off
echo -e " echo -e "
Status: Status:
@ -517,10 +553,15 @@ Status:
Server files installed: ${INSTALLED} Server files installed: ${INSTALLED}
Mods installed: ${MOD_INSTALLED}${MOD_LIST} Mods installed: ${MOD_INSTALLED}${MOD_LIST}
Server running: ${RUNNING} Server running: ${RUNNING}
Server command line:${dayzparameter}
Mod command line: ${mod_command_line}
" "
} }
case "${1}" in case "${1}" in
cmd)
fn_mod_cmd
;;
install) install)
fn_loadconfig_dayz fn_loadconfig_dayz
fn_install_dayz fn_install_dayz