diff --git a/retrieve/templates/linux/functions.sh b/retrieve/templates/linux/functions.sh index 1f15efb..3ced656 100644 --- a/retrieve/templates/linux/functions.sh +++ b/retrieve/templates/linux/functions.sh @@ -1,4 +1,58 @@ set -e +if which tput >/dev/null 2>&1; then + true +else + alias tput=true +fi + +throw_fatal() { + echo 2>&1 "[!] $1" + echo "[=] Fatal Exit. Don't give up. Good luck with the next try." + false +} + +throw_hint() { + echo "[>] $1" +} + +throw_info() { + echo "$(tput setab 2 2>/dev/null)$(tput setaf 7 2>/dev/null)[*]$(tput sgr 0 2>/dev/null) $1" +} + +throw_warning() { + echo "[:] $1" +} + +throw_debug() { + echo "$(tput setab 4 2>/dev/null)$(tput setaf 7 2>/dev/null)[-]$(tput sgr 0 2>/dev/null) $1" +} + +wait_for_rport() { + i=0 + while [ "$i" -lt 40 ]; do + pidof rport >/dev/null 2>&1 && return 0 + echo "$i waiting for rport process to come up ..." + sleep 0.2 + i=$((i + 1)) + done + return 1 +} + +is_rport_subprocess() { + if [ -n "$1" ]; then + SEARCH_PID=$1 + else + SEARCH_PID=$$ + fi + PARENT_PID=$(ps -o ppid= -p "$SEARCH_PID" | tr -d ' ') + PARENT_NAME=$(ps -p "$PARENT_PID" -o comm=) + if [ "$PARENT_NAME" = "rport" ]; then + return 0 + elif [ "$PARENT_PID" -eq 1 ]; then + return 1 + fi + is_rport_subprocess "$PARENT_PID" +} #--- FUNCTION ------------------------------------------------------------------------------------------------------- # NAME: is_available # DESCRIPTION: Check if a command is available on the system. diff --git a/retrieve/templates/linux/init.sh b/retrieve/templates/linux/init.sh index 4129d1e..b2fd964 100644 --- a/retrieve/templates/linux/init.sh +++ b/retrieve/templates/linux/init.sh @@ -8,7 +8,7 @@ exit_trap() { echo "" echo "An error occurred." echo "Try running in debug mode with 'sh -x ${MY_COMMAND}'" - echo "Ask for help on https://github.com/cloudradar-monitoring/rport-pairing/discussions/categories/help-needed " + echo "Ask for help on https://github.com/openrport/openrport-pairing/discussions/categories/help-needed " echo "" } trap exit_trap EXIT \ No newline at end of file diff --git a/retrieve/templates/linux/install.sh b/retrieve/templates/linux/install.sh index 660765c..9656b54 100755 --- a/retrieve/templates/linux/install.sh +++ b/retrieve/templates/linux/install.sh @@ -143,15 +143,15 @@ create_user() { abort "No command found to add a user" fi fi - test -e "$LOG_DIR" || mkdir -p "$LOG_DIR" - test -e /var/lib/rport/scripts || mkdir -p /var/lib/rport/scripts - chown "${USER}":root "$LOG_DIR" - chown "${USER}":root /var/lib/rport/scripts - chmod 0700 /var/lib/rport/scripts - chown "${USER}":root "$CONFIG_FILE" - chmod 0640 "$CONFIG_FILE" - chown root:root /usr/local/bin/rport - chmod 0755 /usr/local/bin/rport +# test -e "$LOG_DIR" || mkdir -p "$LOG_DIR" +# test -e /var/lib/rport/scripts || mkdir -p /var/lib/rport/scripts +# chown "${USER}":root "$LOG_DIR" +# chown "${USER}":root /var/lib/rport/scripts +# chmod 0700 /var/lib/rport/scripts +# chown "${USER}":root "$CONFIG_FILE" +# chmod 0640 "$CONFIG_FILE" +# chown root:root /usr/local/bin/rport +# chmod 0755 /usr/local/bin/rport } set_file_and_dir_owner() { @@ -326,12 +326,12 @@ install_client() { test_connection download_and_extract install_bin rport + create_user install_config rport prepare_config enable_lan_monitoring detect_interpreters set_file_and_dir_owner - create_user if is_available openrc; then create_openrc_service else