Skip to content
Permalink
Browse files

feat: rm command best practices (#2729)

  • Loading branch information
dgibbs64 committed Mar 10, 2020
1 parent d106384 commit 3a6f7f903485e843dff7a3210fb77f999fbcdea0
@@ -12,7 +12,7 @@ fn_alert_log(){
info_config.sh
info_messages.sh
if [ -f "${alertlog}" ]; then
rm "${alertlog}"
rm -f "${alertlog:?}"
fi

{
@@ -17,12 +17,12 @@ fn_backup_trap(){
echo -en "backup ${backupname}.tar.gz..."
fn_print_canceled_eol_nl
fn_script_log_info "Backup ${backupname}.tar.gz: CANCELED"
rm -f "${backupdir}/${backupname}.tar.gz" | tee -a "${lgsmlog}"
rm -f "${backupdir:?}/${backupname}.tar.gz" | tee -a "${lgsmlog}"
echo -en "backup ${backupname}.tar.gz..."
fn_print_removed_eol_nl
fn_script_log_info "Backup ${backupname}.tar.gz: REMOVED"
# Remove lock file.
rm -f "${tmpdir}/.backup.lock"
rm -f "${tmpdir:?}/.backup.lock"
core_exit.sh
}

@@ -153,7 +153,7 @@ fn_backup_compression(){
fn_script_log_pass "Backup created: ${backupname}.tar.gz, total size $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}')"
fi
# Remove lock file
rm -f "${tmpdir}/.backup.lock"
rm -f "${tmpdir:?}/.backup.lock"
}

# Clear old backups according to maxbackups and maxbackupdays variables.
@@ -11,7 +11,7 @@ local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
# Trap to remove lockfile on quit.
fn_lockfile_trap(){
# Remove lockfile.
rm -f "${rootdir}/${lockselfname}"
rm -f "${rootdir:?}/${lockselfname}"
# resets terminal. Servers can sometimes mess up the terminal on exit.
reset
fn_print_ok_nl "Closing debug"
@@ -9,7 +9,7 @@ local commandaction="Dev-Debug"
local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")

if [ -f "${rootdir}/.dev-debug" ]; then
rm "${rootdir}/.dev-debug"
rm "${rootdir:?}/.dev-debug"
fn_print_ok_nl "Disabled dev-debug"
fn_script_log_info "Disabled dev-debug"
else
@@ -207,21 +207,21 @@ echo -e "Required Librarys"
echo -e "================================="
sort "${tmpdir}/.depdetect_readelf" | uniq
echo -en "\n"
rm -f "${tmpdir}/.depdetect_centos_line"
rm -f "${tmpdir}/.depdetect_centos_list"
rm -f "${tmpdir}/.depdetect_centos_list_uniq"

rm -f "${tmpdir}/.depdetect_debian_line"
rm -f "${tmpdir}/.depdetect_debian_list"
rm -f "${tmpdir}/.depdetect_debian_list_uniq"

rm -f "${tmpdir}/.depdetect_ubuntu_line"
rm -f "${tmpdir}/.depdetect_ubuntu_list"
rm -f "${tmpdir}/.depdetect_ubuntu_list_uniq"

rm -f "${tmpdir}/.depdetect_readelf"
rm -f "${tmpdir}/.depdetect_readelf_uniq"
rm -f "${tmpdir}/.depdetect_unknown"
rm -f "${tmpdir}/.depdetect_unknown_uniq"
rm -f "${tmpdir:?}/.depdetect_centos_line"
rm -f "${tmpdir:?}/.depdetect_centos_list"
rm -f "${tmpdir:?}/.depdetect_centos_list_uniq"

rm -f "${tmpdir:?}/.depdetect_debian_line"
rm -f "${tmpdir:?}/.depdetect_debian_list"
rm -f "${tmpdir:?}/.depdetect_debian_list_uniq"

rm -f "${tmpdir:?}/.depdetect_ubuntu_line"
rm -f "${tmpdir:?}/.depdetect_ubuntu_list"
rm -f "${tmpdir:?}/.depdetect_ubuntu_list_uniq"

rm -f "${tmpdir:?}/.depdetect_readelf"
rm -f "${tmpdir:?}/.depdetect_readelf_uniq"
rm -f "${tmpdir:?}/.depdetect_unknown"
rm -f "${tmpdir:?}/.depdetect_unknown_uniq"

core_exit.sh
@@ -70,8 +70,8 @@ do
echo -e ""
echo -e "All required GLIBC versions"
cat "${tmpdir}/detect_glibc_${glibc_check_var}.tmp" | sort | uniq | sort -r --version-sort
rm "${tmpdir}/detect_glibc_${glibc_check_var}.tmp"
rm "${tmpdir}/detect_glibc_files_${glibc_check_var}.tmp"
rm -f "${tmpdir:?}/detect_glibc_${glibc_check_var}.tmp"
rm -f "${tmpdir:?}/detect_glibc_files_${glibc_check_var}.tmp"
else
fn_print_information_nl "glibc is not required"
fi
@@ -84,7 +84,7 @@ echo -e "Final glibc Requirement"
echo -e "================================="
if [ -f "${tmpdir}/detect_glibc_highest.tmp" ]; then
cat "${tmpdir}/detect_glibc_highest.tmp" | sort | uniq | sort -r --version-sort | head -1
rm "${tmpdir}/detect_glibc_highest.tmp"
rm -f "${tmpdir:?}/detect_glibc_highest.tmp"
else
fn_print_information_nl "glibc is not required"
fi
@@ -55,7 +55,7 @@ echo -e "Not Found"
echo -e "================================="
cat "${tmpdir}/detect_ldd_not_found.tmp"

rm "${tmpdir}/detect_ldd.tmp"
rm "${tmpdir}/detect_ldd_not_found.tmp"
rm -f "${tmpdir:?}/detect_ldd.tmp"
rm -f "${tmpdir:?}/detect_ldd_not_found.tmp"

core_exit.sh
@@ -67,7 +67,7 @@ fn_clear_old_fastdl(){
# Clearing old FastDL.
if [ -d "${fastdldir}" ]; then
echo -en "clearing existing FastDL directory ${fastdldir}..."
rm -R "${fastdldir:?}"
rm -fR "${fastdldir:?}"
exitcode=$?
if [ ${exitcode} -ne 0 ]; then
fn_print_fail_eol_nl
@@ -147,7 +147,7 @@ fn_human_readable_file_size(){
fn_fastdl_preview(){
# Remove any file list.
if [ -f "${tmpdir}/fastdl_files_to_compress.txt" ]; then
rm -f "${tmpdir}/fastdl_files_to_compress.txt"
rm -f "${tmpdir:?}/fastdl_files_to_compress.txt"
fi
echo -e "analysing required files"
fn_script_log_info "Analysing required files"
@@ -228,7 +228,7 @@ fn_fastdl_preview(){
fi
echo -e "about to compress ${totalfiles} files, total size $(fn_human_readable_file_size ${filesizetotal} 0)"
fn_script_log_info "${totalfiles} files, total size $(fn_human_readable_file_size ${filesizetotal} 0)"
rm "${tmpdir}/fastdl_files_to_compress.txt"
rm -f "${tmpdir:?}/fastdl_files_to_compress.txt"
if ! fn_prompt_yn "Continue?" Y; then
fn_script_log "User exited"
core_exit.sh
@@ -276,7 +276,7 @@ fn_fastdl_gmod(){
# Clear addons directory in fastdl.
echo -en "clearing addons dir from fastdl dir..."
fn_sleep_time
rm -R "${fastdldir:?}/addons"
rm -fR "${fastdldir:?}/addons"
exitcode=$?
if [ ${exitcode} -ne 0 ]; then
fn_print_fail_eol_nl
@@ -379,7 +379,7 @@ fn_fastdl_gmod_dl_enforcer(){
# Clear old lua file.
if [ -f "${luafastdlfullpath}" ]; then
echo -en "removing existing download enforcer: ${luafastdlfile}..."
rm "${luafastdlfullpath:?}"
rm -f "${luafastdlfullpath:?}"
exitcode=$?
if [ ${exitcode} -ne 0 ]; then
fn_print_fail_eol_nl
@@ -68,7 +68,7 @@ while [ "${modfileline}" -le "${modsfilelistsize}" ]; do
# If file or directory exists, then remove it.

if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then
rm -rf "${modinstalldir:?}/${currentfileremove}"
rm -rf "${modinstalldir:?}/${currentfileremove:?}"
((exitcode=$?))
if [ ${exitcode} -ne 0 ]; then
fn_script_log_fatal "Removing ${modinstalldir}/${currentfileremove}"
@@ -91,7 +91,7 @@ fn_sleep_time
# Remove file list.
echo -en "removing ${modcommand}-files.txt..."
fn_sleep_time
rm -rf "${modsdir}/${modcommand}-files.txt"
rm -rf "${modsdir:?}/${modcommand}-files.txt"
local exitcode=$?
if [ ${exitcode} -ne 0 ]; then
fn_script_log_fatal "Removing ${modsdir}/${modcommand}-files.txt"
@@ -44,7 +44,7 @@ fn_bad_postdetailslog() {

# Remove any existing postdetails.log file.
if [ -f "${postdetailslog}" ]; then
rm -f "${postdetailslog}"
rm -f "${postdetailslog:?}"
fi

# Rather than a one-pass sed parser, default to using a temporary directory.
@@ -159,7 +159,7 @@ fn_sleep_time
fn_print_ok "${servername}"
fn_script_log_pass "Started ${servername}"
fi
rm "${lgsmlogdir}/.${selfname}-tmux-error.tmp"
rm "${lgsmlogdir:?}/.${selfname}-tmux-error.tmp"
echo -en "\n"
}

@@ -242,7 +242,7 @@ info_config.sh
fn_stop_pre_check
# Remove lockfile.
if [ -f "${rootdir}/${lockselfname}" ]; then
rm -f "${rootdir}/${lockselfname}"
rm -f "${rootdir:?}/${lockselfname}"
fi

if [ -z "${exitbypass}" ]; then
@@ -20,7 +20,7 @@ if [ -z "${legacymode}" ]; then
if [ "${config_file_diff}" != "" ]; then
fn_print_update_eol_nl
fn_script_log_info "checking config _default.cfg: UPDATE"
rm -f "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg"
rm -f "${configdirdefault:?}/config-lgsm/${gameservername}/_default.cfg"
fn_fetch_config "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "_default.cfg" "nochmodx" "norun" "noforce" "nomd5"
alert="config"
alert.sh
@@ -34,7 +34,7 @@ if [ -z "${legacymode}" ]; then
if [ "${tmp_script_diff}" != "" ]; then
fn_print_update_eol_nl
fn_script_log_info "checking linuxgsm.sh: UPDATE"
rm -f "${tmpdir}/linuxgsm.sh"
rm -f "${tmpdir:?}/linuxgsm.sh"
fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nomd5"
# Compare selfname against linuxgsm.sh in the tmp dir. Ignoring server specific vars.
else
@@ -87,7 +87,7 @@ if [ -n "${functionsdir}" ]; then
fn_print_fail_eol_nl
echo -en " removing unknown function ${functionfile}...\c"
fn_script_log_fatal "removing unknown function ${functionfile}"
if ! rm -f "${functionfile}"; then
if ! rm -f "${functionfile:?}"; then
fn_print_fail_eol_nl
core_exit.sh
else
@@ -21,7 +21,7 @@ if ! fn_prompt_yn "Start compression?" Y; then
return
fi
mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
rm -rfv "${serverfiles}/Maps/"*.ut2.uz2
rm -rfv "${serverfiles:?}/Maps/"*.ut2.uz2
cd "${systemdir}" || exit
for map in "${serverfiles}/Maps/"*; do
./ucc-bin compress "${map}" --nohomedir
@@ -21,7 +21,7 @@ if ! fn_prompt_yn "Start compression?" Y; then
return
fi
mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
rm -rfv "${serverfiles}/Maps/"*.unr.uz
rm -rfv "${serverfiles:?}/Maps/"*.unr.uz
cd "${systemdir}" || exit
for map in "${serverfiles}/Maps/"*; do
./ucc-bin compress "${map}" --nohomedir
@@ -105,7 +105,7 @@ fn_fetch_trap(){
fn_print_canceled_eol_nl
fn_script_log_info "Downloading ${local_filename}...CANCELED"
fn_sleep_time
rm -f "${local_filedir}/${local_filename}"
rm -f "${local_filedir:?}/${local_filename}"
echo -en "downloading ${local_filename}..."
fn_print_removed_eol_nl
fn_script_log_info "Downloading ${local_filename}...REMOVED"
@@ -94,7 +94,7 @@ fn_install_server_files_steamcmd(){
find "${serverfiles}" -type d -print0 | grep -Ez '[^/]{30}$' | xargs -0 rm -rf
fi
if [ "${counter}" -ge "9" ]; then
rm -rf "${steamcmddir}"
rm -rf "${steamcmddir:?}"
check_steamcmd.sh
fi

@@ -440,7 +440,7 @@ fn_mods_create_tmp_dir(){
fn_mods_clear_tmp_dir(){
if [ -d "${modstmpdir}" ]; then
echo -en "clearing mod download directory ${modstmpdir}..."
rm -r "${modstmpdir}"
rm -fr "${modstmpdir:?}"
exitcode=$?
if [ ${exitcode} -ne 0 ]; then
fn_print_fail_eol_nl
@@ -454,7 +454,7 @@ fn_mods_clear_tmp_dir(){
fi
# Clear temp file list as well.
if [ -f "${modsdir}/.removedfiles.tmp" ]; then
rm "${modsdir}/.removedfiles.tmp"
rm -f "${modsdir:?}/.removedfiles.tmp"
fi
}

@@ -156,7 +156,7 @@ fn_appmanifest_check(){
fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
for appfile in ${appmanifestfile}; do
rm "${appfile}"
rm -f "${appfile:?}"
done
appmanifestfilewc1="${appmanifestfilewc}"
fn_appmanifest_info
@@ -16,7 +16,7 @@ while IFS= read -r -d $'\0' line; do
echo "${diffoutput}"
echo ""
fi
rm defaultcfgtemp.txt
rm -f defaultcfgtemp.txt
done

echo -e ""
@@ -36,7 +36,7 @@ while IFS= read -r -d $'\0' line; do
echo "${diffoutput}"
echo ""
fi
rm defaultcfgtemp.txt
rm -f defaultcfgtemp.txt
done

echo -e ""
@@ -56,5 +56,5 @@ while IFS= read -r -d $'\0' line; do
echo "${diffoutput}"
echo ""
fi
rm defaultcfgtemp.txt
rm -f defaultcfgtemp.txt
done
@@ -1013,6 +1013,6 @@ requiredstatus="OFFLINE"
fn_setstatus
if [ ! -v TRAVIS ]; then
fn_print_info "Tidying up directories."
rm -rfv "${serverfiles}"
rm -rfv "${serverfiles:?}"
fi
core_exit.sh
@@ -829,7 +829,7 @@ echo -e "Command: ./jc2server update"
requiredstatus="OFFLINE"
fn_setstatus
fn_print_info_nl "removed appmanifest_${appid}.acf."
rm --verbose "${serverfiles}/steamapps/appmanifest_${appid}.acf"
rm --verbose "${serverfiles:?}/steamapps/appmanifest_${appid}.acf"
(
exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
BASH_XTRACEFD="5"
@@ -1174,6 +1174,6 @@ requiredstatus="OFFLINE"
fn_setstatus
if [ ! -v TRAVIS ]; then
fn_print_info "Tidying up directories."
rm -rfv "${serverfiles}"
rm -rfv "${serverfiles:?}"
fi
core_exit.sh
@@ -1060,6 +1060,6 @@ requiredstatus="OFFLINE"
fn_setstatus
if [ ! -v TRAVIS ]; then
fn_print_info "Tidying up directories."
rm -rfv "${serverfiles}"
rm -rfv "${serverfiles:?}"
fi
core_exit.sh
@@ -1013,6 +1013,6 @@ requiredstatus="OFFLINE"
fn_setstatus
if [ ! -v TRAVIS ]; then
fn_print_info "Tidying up directories."
rm -rfv "${serverfiles}"
rm -rfv "${serverfiles:?}"
fi
core_exit.sh

0 comments on commit 3a6f7f9

Please sign in to comment.
You can’t perform that action at this time.