Browse Source

refactor: improve log directory creation

- Changed the variable `checklogs` from being set to `1` to being set to `true`.
- Improved the logic for creating log directories and files.
- Added more informative console output for each step of the process.
- Refactored code to use conditional statements instead of nested if statements.
- Removed unnecessary print statements.

This commit improves the way log directories are created and handles cases where logs already exist. It also provides clearer console output during the process.
feature/dst-changes
Daniel Gibbs 2 years ago
parent
commit
6f636b31b5
  1. 2
      lgsm/modules/check_logs.sh
  2. 96
      lgsm/modules/install_logs.sh
  3. 11
      lgsm/modules/install_server_dir.sh

2
lgsm/modules/check_logs.sh

@ -10,7 +10,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_check_logs() {
fn_print_dots "Checking for log files"
fn_print_info_nl "Checking for log files: Creating log files"
checklogs=1
checklogs=true
install_logs.sh
}

96
lgsm/modules/install_logs.sh

@ -7,81 +7,103 @@
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
if [ "${checklogs}" != "1" ]; then
if [ -z "${checklogs}" ]; then
echo -e ""
echo -e "${lightyellow}Creating log directories${default}"
echo -e "================================="
fi
fn_sleep_time
# Create LinuxGSM logs.
echo -en "installing log dir: ${logdir}..."
mkdir -p "${logdir}"
if [ $? != 0 ]; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fn_sleep_time
fi
echo -en "installing LinuxGSM log dir: ${lgsmlogdir}..."
mkdir -p "${lgsmlogdir}"
if [ $? != 0 ]; then
fn_print_fail_eol_nl
core_exit.sh
echo -en "creating log directory [ ${logdir} ]..."
if [ ! -d "${logdir}" ]; then
if ! mkdir -p "${logdir}"; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
else
fn_print_ok_eol_nl
fn_print_skip_eol_nl
fi
echo -en "creating LinuxGSM log: ${lgsmlog}..."
touch "${lgsmlog}"
if [ $? != 0 ]; then
fn_print_fail_eol_nl
core_exit.sh
echo -en "creating script log directory [ ${lgsmlogdir} ]..."
if [ ! -d "${lgsmlogdir}" ]; then
if ! mkdir -p "${lgsmlogdir}"; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
else
fn_print_ok_eol_nl
fn_print_skip_eol_nl
fi
# Create Console logs.
if [ "${consolelogdir}" ]; then
echo -en "installing console log dir: ${consolelogdir}..."
mkdir -p "${consolelogdir}"
if [ $? != 0 ]; then
echo -en "creating script log [ ${lgsmlog} ]..."
if [ ! -f "${lgsmlog}" ]; then
if ! touch "${lgsmlog}"; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
echo -en "creating console log: ${consolelog}..."
if ! touch "${consolelog}"; then
else
fn_print_skip_eol_nl
fi
echo -en "creating console log directory [ ${consolelogdir} ]..."
if [ ! -d "${consolelogdir}" ]; then
if ! mkdir -p "${consolelogdir}"; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
else
fn_print_skip_eol_nl
fi
# Create Game logs.
if [ "${gamelogdir}" ] && [ ! -d "${gamelogdir}" ]; then
echo -en "installing game log dir: ${gamelogdir}..."
if ! mkdir -p "${gamelogdir}"; then
echo -en "creating console log [ ${consolelog} ] ..."
if [ ! -f "${consolelog}" ]; then
if ! touch "${consolelog}"; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
else
fn_print_skip_eol_nl
fi
if [ -n "${gamelogdir}" ]; then
echo -en "creating game log directory [ ${gamelogdir} ]..."
if [ ! -d "${gamelogdir}" ]; then
if ! mkdir -p "${gamelogdir}"; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
else
fn_print_skip_eol_nl
fi
fi
# Symlink to gamelogdir
# unless gamelogdir is within logdir.
# e.g serverfiles/log is not within log/: symlink created
# log/server is in log/: symlink not created
if [ "${gamelogdir}" ]; then
if [ "${gamelogdir:0:${#logdir}}" != "${logdir}" ]; then
echo -en "creating symlink to game log dir: ${logdir}/server -> ${gamelogdir}..."
if [ -n "${gamelogdir}" ] && [ "${gamelogdir:0:${#logdir}}" != "${logdir}" ]; then
echo -en "creating symlink to game log dir [ ${logdir}/server -> ${gamelogdir} ]..."
# if path does not exist or does not match gamelogdir
if [ ! -h "${logdir}/server" ] || [ "$(readlink -f "${logdir}/server")" != "${gamelogdir}" ]; then
if ! ln -nfs "${gamelogdir}" "${logdir}/server"; then
fn_print_fail_eol_nl
core_exit.sh
else
fn_print_ok_eol_nl
fi
else
fn_print_skip_eol_nl
fi
fi

11
lgsm/modules/install_server_dir.sh

@ -11,10 +11,17 @@ echo -e ""
echo -e "${lightyellow}Server Directory${default}"
echo -e "================================="
fn_sleep_time
echo -en "checking ${serverfiles} exists..."
if [ -d "${serverfiles}" ]; then
fn_print_warning_nl "A server is already installed here."
fn_print_warn_eol_nl
echo -e "\n* A game server is already exists at this location.\n"
else
fn_print_ok_eol_nl
fi
pwd
if [ -z "${autoinstall}" ]; then
if ! fn_prompt_yn "Continue?" Y; then
exitcode=0

Loading…
Cancel
Save