Skip to content

feat: update refactor #4146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lgsm/config-default/config-lgsm/ut99server/_default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ glibc="2.1"
# Edit with care

## Game Server Directories
systemdir="${serverfiles}/System"
systemdir="${serverfiles}/System64"
executabledir="${systemdir}"
executable="./ucc-bin"
servercfgdir="${systemdir}"
Expand Down
4 changes: 2 additions & 2 deletions lgsm/functions/alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn_alert_update() {
alertemoji="🎮"
alertsound="1"
alerturl="not enabled"
alertbody="${gamename} received update"
alertbody="${gamename} received update: ${remotebuildversion}"
}

fn_alert_check_update() {
Expand All @@ -69,7 +69,7 @@ fn_alert_check_update() {
alertemoji="🎮"
alertsound="1"
alerturl="not enabled"
alertbody="${gamename} update available"
alertbody="${gamename} update available: ${remotebuildversion}"
}

fn_alert_permissions() {
Expand Down
11 changes: 6 additions & 5 deletions lgsm/functions/command_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,17 @@ fn_backup_migrate_olddir() {
fn_script_log_info "${rootdir}/backups > ${backupdir}"
mv "${rootdir}/backups/"* "${backupdir}" 2> /dev/null
exitcode=$?
if [ "${exitcode}" -eq 0 ]; then
if [ "${exitcode}" == 0 ]; then
rmdir "${rootdir}/backups" 2> /dev/null
exitcode=$?
fi
if [ "${exitcode}" -eq 0 ]; then
fn_print_ok_nl "Backup directory is being migrated"
fn_script_log_pass "Backup directory is being migrated"
else
if [ "${exitcode}" != 0 ]; then
fn_print_error_nl "Backup directory is being migrated"
fn_script_log_error "Backup directory is being migrated"
else

fn_print_ok_nl "Backup directory is being migrated"
fn_script_log_pass "Backup directory is being migrated"
fi
fi
fi
Expand Down
28 changes: 19 additions & 9 deletions lgsm/functions/command_check_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@ fn_print_dots ""
check.sh
core_logs.sh

if [ "${appid}" ]; then
core_steamcmd.sh

check_steamcmd.sh

fn_update_steamcmd_localbuild
fn_update_steamcmd_remotebuild
fn_update_steamcmd_compare
elif [ "${shortname}" == "ts3" ]; then
if [ "${shortname}" == "ts3" ]; then
update_ts3.sh
elif [ "${shortname}" == "mc" ]; then
update_minecraft.sh
elif [ "${shortname}" == "mcb" ]; then
update_minecraft_bedrock.sh
elif [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then
update_papermc.sh
elif [ "${shortname}" == "fctr" ]; then
update_factorio.sh
elif [ "${shortname}" == "mta" ]; then
update_mta.sh
elif [ "${shortname}" == "jk2" ]; then
update_jediknight2.sh
elif [ "${shortname}" == "vints" ]; then
update_vintagestory.sh
elif [ "${shortname}" == "ut99" ]; then
update_ut99.sh
else
update_steamcmd.sh
fi

core_exit.sh
4 changes: 1 addition & 3 deletions lgsm/functions/command_install_resources_mta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn_firstcommand_set

fn_install_resources() {
echo -e ""
echo -e "Installing Default Resources"
echo -e "${lightyellow}Installing Default Resources${default}"
echo -e "================================="
fn_fetch_file "http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip" "" "" "" "${tmpdir}" "mtasa-resources-latest.zip" "nochmodx" "norun" "noforce" "nohash"
fn_dl_extract "${tmpdir}" "mtasa-resources-latest.zip" "${resourcesdir}"
Expand All @@ -30,5 +30,3 @@ else
fn_print_warning_nl "Default resources are not installed when using ./${selfname} auto-install."
fn_print_information_nl "To install default resources use ./${selfname} install"
fi

core_exit.sh
4 changes: 2 additions & 2 deletions lgsm/functions/command_mods_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ fn_remove_cfg_files() {
filetopreserve=$(echo -e "${modkeepfiles}" | awk -F ';' -v x=${preservefilesindex} '{ print $x }')
echo -e " * serverfiles/${filetopreserve}"
# If it matches an existing file that have been extracted delete the file.
if [ -f "${extractdir}/${filetopreserve}" ] || [ -d "${extractdir}/${filetopreserve}" ]; then
rm -r "${extractdir:?}/${filetopreserve}"
if [ -f "${extractdest}/${filetopreserve}" ] || [ -d "${extractdest}/${filetopreserve}" ]; then
rm -r "${extractdest:?}/${filetopreserve}"
# Write the file path in a tmp file, to rebuild a full file list as it is rebuilt upon update.
if [ ! -f "${modsdir}/.removedfiles.tmp" ]; then
touch "${modsdir}/.removedfiles.tmp"
Expand Down
2 changes: 2 additions & 0 deletions lgsm/functions/command_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ elif [ "${shortname}" == "jk2" ]; then
update_jediknight2.sh
elif [ "${shortname}" == "vints" ]; then
update_vintagestory.sh
elif [ "${shortname}" == "ut99" ]; then
update_ut99.sh
else
update_steamcmd.sh
fi
Expand Down
82 changes: 53 additions & 29 deletions lgsm/functions/core_dl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# hash: Optional, set an hash sum and will compare it against the file.
#
# Downloads can be defined in code like so:
# fn_fetch_file "${remote_fileurl}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${hash}"
# fn_fetch_file "http://example.com/file.tar.bz2" "/some/dir" "file.tar.bz2" "chmodx" "run" "forcedl" "10cd7353aa9d758a075c600a6dd193fd"
# fn_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${hash}"
# fn_fetch_file "http://example.com/file.tar.bz2" "http://example.com/file2.tar.bz2" "file.tar.bz2" "file2.tar.bz2" "/some/dir" "file.tar.bz2" "chmodx" "run" "forcedl" "10cd7353aa9d758a075c600a6dd193fd"

functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

Expand Down Expand Up @@ -124,7 +124,7 @@ fn_dl_steamcmd() {
echo -en "Please provide content log to LinuxGSM developers https://linuxgsm.com/steamcmd-error"
fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Unknown error occured"
fi
elif [ "${exitcode}" != "0" ]; then
elif [ "${exitcode}" != 0 ]; then
fn_print_error2_nl "${commandaction} ${selfname}: ${remotelocation}: Exit code: ${exitcode}"
fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Exit code: ${exitcode}"
else
Expand All @@ -146,12 +146,12 @@ fn_clear_tmp() {
if [ -d "${tmpdir}" ]; then
rm -rf "${tmpdir:?}/"*
local exitcode=$?
if [ "${exitcode}" == 0 ]; then
fn_print_ok_eol_nl
fn_script_log_pass "clearing LinuxGSM tmp directory"
else
if [ "${exitcode}" != 0 ]; then
fn_print_error_eol_nl
fn_script_log_error "clearing LinuxGSM tmp directory"
else
fn_print_ok_eol_nl
fn_script_log_pass "clearing LinuxGSM tmp directory"
fi
fi
}
Expand Down Expand Up @@ -202,39 +202,64 @@ fn_dl_hash() {

# Extracts bzip2, gzip or zip files.
# Extracts can be defined in code like so:
# fn_dl_extract "${local_filedir}" "${local_filename}" "${extractdir}"
# fn_dl_extract "${local_filedir}" "${local_filename}" "${extractdest}" "${extractsrc}"
# fn_dl_extract "/home/gameserver/lgsm/tmp" "file.tar.bz2" "/home/gamserver/serverfiles"
fn_dl_extract() {
local_filedir="${1}"
local_filename="${2}"
extractdir="${3}"
extractdest="${3}"
extractsrc="${4}"
# Extracts archives.
echo -en "extracting ${local_filename}..."
mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
if [ ! -d "${extractdir}" ]; then
mkdir "${extractdir}"

if [ ! -d "${extractdest}" ]; then
mkdir "${extractdest}"
fi
if [ ! -f "${local_filedir}/${local_filename}" ]; then
fn_print_fail_eol_nl
echo -en "file ${local_filedir}/${local_filename} not found"
fn_script_log_fatal "Extracting ${local_filename}"
fn_script_log_fatal "File ${local_filedir}/${local_filename} not found"
core_exit.sh
fi
mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
if [ "${mime}" == "application/gzip" ] || [ "${mime}" == "application/x-gzip" ]; then
extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdir}")
if [ -n "${extractsrc}" ]; then
extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
else
extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdest}")
fi
elif [ "${mime}" == "application/x-bzip2" ]; then
extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdir}")
if [ -n "${extractsrc}" ]; then
extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
else
extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdest}")
fi
elif [ "${mime}" == "application/x-xz" ]; then
extractcmd=$(tar -xf "${local_filedir}/${local_filename}" -C "${extractdir}")
if [ -n "${extractsrc}" ]; then
extractcmd=$(tar -Jxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
else
extractcmd=$(tar -Jxf "${local_filedir}/${local_filename}" -C "${extractdest}")
fi
elif [ "${mime}" == "application/zip" ]; then
extractcmd=$(unzip -qo -d "${extractdir}" "${local_filedir}/${local_filename}")
if [ -n "${extractsrc}" ]; then
extractcmd=$(unzip -qoj -d "${extractdest}" "${local_filedir}/${local_filename}" "${extractsrc}"/*)
else
extractcmd=$(unzip -qo -d "${extractdest}" "${local_filedir}/${local_filename}")
fi
fi
local exitcode=$?
if [ "${exitcode}" != 0 ]; then
fn_print_fail_eol_nl
fn_script_log_fatal "Extracting download"
fn_script_log_fatal "Extracting ${local_filename}"
if [ -f "${lgsmlog}" ]; then
echo -e "${extractcmd}" >> "${lgsmlog}"
fi
echo -e "${extractcmd}"
core_exit.sh
else
fn_print_ok_eol_nl
fn_script_log_pass "Extracting download"
fn_script_log_pass "Extracting ${local_filename}"
fi
}

Expand Down Expand Up @@ -360,21 +385,21 @@ fn_fetch_file() {
trap fn_fetch_trap INT
# Larger files show a progress bar.
if [ "${local_filename##*.}" == "bz2" ] || [ "${local_filename##*.}" == "gz" ] || [ "${local_filename##*.}" == "zip" ] || [ "${local_filename##*.}" == "jar" ] || [ "${local_filename##*.}" == "xz" ]; then
echo -en "downloading ${local_filename}..."
echo -e "downloading ${local_filename}..."
fn_sleep_time
echo -en "\033[1K"
curlcmd=$(curl --connect-timeout 10 --progress-bar --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
local exitcode=$?
echo -en "downloading ${local_filename}..."
else
curlcmd=$(curl --connect-timeout 10 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
local exitcode=$?
echo -en "fetching ${fileurl_name} ${local_filename}...\c"
curlcmd=$(curl --connect-timeout 10 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}" 2>&1)
fi
local exitcode=$?

# Download will fail if downloads a html file.
if [ -f "${local_filedir}/${local_filename}" ]; then
if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
rm -f "${local_filedir:?}/${local_filename:?}"
if head -n 1 "${local_filedir}/${local_filename}" | grep -q "DOCTYPE"; then
rm "${local_filedir:?}/${local_filename:?}"
local exitcode=2
fi
fi
Expand All @@ -384,22 +409,21 @@ fn_fetch_file() {
if [ ${counter} -ge 2 ]; then
fn_print_fail_eol_nl
if [ -f "${lgsmlog}" ]; then
fn_script_log_fatal "Downloading ${local_filename}"
fn_script_log_fatal "Downloading ${local_filename}..."
fn_script_log_fatal "${fileurl}"
fi
core_exit.sh
else
fn_print_error_eol_nl
if [ -f "${lgsmlog}" ]; then
fn_script_log_error "Downloading ${local_filename}"
fn_script_log_error "Downloading ${local_filename}..."
fn_script_log_error "${fileurl}"
fi
fi
else
fn_print_ok_eol
echo -en "\033[2K\\r"
fn_print_ok_eol_nl
if [ -f "${lgsmlog}" ]; then
fn_script_log_pass "Downloading ${local_filename}"
fn_script_log_pass "Downloading ${local_filename}..."
fi

# Make file executable if chmodx is set.
Expand Down
2 changes: 1 addition & 1 deletion lgsm/functions/core_exit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fi

if [ "${exitbypass}" ]; then
unset exitbypass
elif [ "${exitcode}" ] && [ "${exitcode}" != "0" ]; then
elif [ "${exitcode}" != "0" ]; then
# List LinuxGSM version in logs
fn_script_log_info "LinuxGSM version: ${version}"
if [ "${exitcode}" == "1" ]; then
Expand Down
5 changes: 5 additions & 0 deletions lgsm/functions/core_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ update_vintagestory.sh() {
fn_fetch_function
}

update_ut99.sh() {
functionfile="${FUNCNAME[0]}"
fn_fetch_function
}

fn_update_functions.sh() {
functionfile="${FUNCNAME[0]}"
fn_fetch_function
Expand Down
12 changes: 7 additions & 5 deletions lgsm/functions/core_getopt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ currentopt+=("${cmd_update_linuxgsm[@]}")

# Exclude noupdate games here.
if [ "${shortname}" == "jk2" ] || [ "${engine}" != "idtech3" ]; then
if [ "${shortname}" != "bf1942" ] && [ "${shortname}" != "bfv" ] && [ "${engine}" != "idtech2" ] && [ "${engine}" != "iw2.0" ] && [ "${engine}" != "iw3.0" ] && [ "${engine}" != "quake" ] && [ "${shortname}" != "samp" ] && [ "${shortname}" != "ut2k4" ] && [ "${shortname}" != "ut99" ]; then
currentopt+=("${cmd_update[@]}")
if [ "${shortname}" != "bf1942" ] && [ "${shortname}" != "bfv" ] && [ "${engine}" != "idtech2" ] && [ "${engine}" != "iw2.0" ] && [ "${engine}" != "iw3.0" ] && [ "${engine}" != "quake" ] && [ "${shortname}" != "samp" ] && [ "${shortname}" != "ut2k4" ]; then
currentopt+=("${cmd_update[@]}" "${cmd_check_update[@]}")
# force update for SteamCMD or Multi Theft Auto only.
if [ "${appid}" ] || [ "${shortname}" == "mta" ]; then
currentopt+=("${cmd_force_update[@]}")
Expand All @@ -75,8 +75,8 @@ if [ "${shortname}" == "jk2" ] || [ "${engine}" != "idtech3" ]; then
fi

# Validate and check-update command.
if [ "${appid}" ] || [ "${shortname}" == "ts3" ]; then
currentopt+=("${cmd_validate[@]}" "${cmd_check_update[@]}")
if [ "${appid}" ]; then
currentopt+=("${cmd_validate[@]}")
fi

# Backup.
Expand All @@ -102,10 +102,12 @@ if [ "${shortname}" == "ts3" ]; then
currentopt+=("${cmd_change_password[@]}")
fi

# Unreal exclusive.
# Rust exclusive.
if [ "${shortname}" == "rust" ]; then
currentopt+=("${cmd_fullwipe[@]}" "${cmd_mapwipe[@]}")
fi

# Unreal exclusive.
if [ "${engine}" == "unreal2" ]; then
if [ "${shortname}" == "ut2k4" ]; then
currentopt+=("${cmd_install_cdkey[@]}" "${cmd_map_compressor_u2[@]}")
Expand Down
Loading