From e9a75919511e6afdd0e4be6b378bdeeeb5f03f4b Mon Sep 17 00:00:00 2001 From: root Date: Thu, 6 Aug 2026 18:02:59 +0200 Subject: [PATCH] install_dehydrated.sh: add debug code. --- install_dehydrated.sh | 56 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/install_dehydrated.sh b/install_dehydrated.sh index 65f3d70..174308e 100755 --- a/install_dehydrated.sh +++ b/install_dehydrated.sh @@ -1,5 +1,10 @@ #!/usr/bin/env bash +script_name="$(basename $(realpath $0))" + +LOCK_DIR="/tmp/${script_name%%.*}.LOCK" +log_file="${LOCK_DIR}/${script_name%%.*}.log" + _DH_INSTALL_DIR=/usr/local/dehydrated _DH_CONF_DIR=/etc/dehydrated _DH_BASE_DIR=/var/lib/dehydrated @@ -16,6 +21,13 @@ ERR_MSG_TOO_MANY_CERTS="too many certificates already issued" # ------------- # --- Some functions # ------------- +clean_up() { + + # Perform program exit housekeeping + rm -rf "$LOCK_DIR" + exit $1 +} + echononl(){ echo X\\c > /tmp/shprompt$$ if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then @@ -32,7 +44,7 @@ fatal(){ echo "" echo -e "\t\033[31m\033[1mInstalllation wird abgebrochen\033[m\033[m" echo "" - exit 1 + clean_up 1 } error(){ @@ -77,6 +89,40 @@ containsElement () { return 1 } + +# ------------- +# - Job is already running? +# ------------- + +# - If job already runs, stop execution.. +# - +if mkdir "$LOCK_DIR" 2> /dev/null ; then + + # - Remove lockdir when the script finishes, or when it receives a signal + # - + trap clean_up SIGHUP SIGINT SIGTERM + +else + + msg="A previos instance of script \"`basename $0`\" seems already be running." + + echo "" + if $terminal ; then + echo -e "[ \033[31m\033[1mFatal\033[m ]: $msg" + echo "" + echo -e " \033[31m\033[1mScript was interupted\033[m!" + else + echo " [ Fatal ]: $msg" + echo "" + echo " Script was interupted!" + fi + echo + + exit 1 + +fi + + clear echo "" echo -e "\033[21G\033[32mInstallation script for dehydrated\033[m" @@ -920,11 +966,15 @@ if [[ -d "$DH_INSTALL_DIR" ]]; then rm -rf ${DH_INSTALL_DIR}.$_date fi else - git clone https://github.com/lukas2511/dehydrated.git $DH_INSTALL_DIR > /dev/null 2>&1 + git clone https://github.com/lukas2511/dehydrated.git $DH_INSTALL_DIR > $log_file 2>&1 if [[ $? -eq 0 ]] ; then echo_ok else echo_failed + echo -e "\n Command was: + git clone https://github.com/lukas2511/dehydrated.git $DH_INSTALL_DIR\n" + error "$(cat "$log_file")" + echo "" fatal "Cloning git repositors \"dehydrated.git\" failed!. Exciting install script.." fi fi @@ -4216,4 +4266,4 @@ if [[ -f "${DH_BASE_DIR}/tools/dh_tlsgen.sh.$_date" ]]; then fi echo "" -exit 0 +clean_up 0