Skip to content

Commit

Permalink
Add printing debug function
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro OSIAS committed Oct 6, 2023
1 parent 611a83b commit fbe1739
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
54 changes: 54 additions & 0 deletions retrieve/templates/linux/functions.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion retrieve/templates/linux/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 10 additions & 10 deletions retrieve/templates/linux/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fbe1739

Please sign in to comment.