From eda9d5ffbe7b048019911f03393131067c5b8f7b Mon Sep 17 00:00:00 2001 From: PrincessPi3 Date: Fri, 22 May 2026 23:21:17 -0600 Subject: [PATCH] 1779513677 --- References/Quick-and-Dirty-Methods-Bash.md | 59 +++++++++++++++++ customscripts/debian-setup.sh | 77 ++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 customscripts/debian-setup.sh diff --git a/References/Quick-and-Dirty-Methods-Bash.md b/References/Quick-and-Dirty-Methods-Bash.md index 8cd6e7b..e030bb7 100644 --- a/References/Quick-and-Dirty-Methods-Bash.md +++ b/References/Quick-and-Dirty-Methods-Bash.md @@ -12,6 +12,65 @@ RESET='\033[0m' # No Color (RESET) # usage echo -e "$PINKpinktext here$RESET" ``` +standard peak safety with error handling for shell scripts + shell script header to exit on error, failed piping, or unset variable while allowing err trap and custom trapping for error +```bash +#!/bin/bash +# set safety optinonz +set -o errexit # fail on error +set -o errtrace # run trace on error +set -o pipefail # fail on pipe fail +set -o nounset # fail on unset var + +# save here to use in error_handle function +num_of_args="$#" +all_args="$@" + +# Define the cleanup function +error_handle() { + # CRITICAL: Capture the exit status code before ANY other command runs + local exit_code=$? + local script_path="$(realpath $0)" + local hr='====================================================' + echo + echo $hr + echo -e "🚨 \033[0;31m FATAL ERROR DETECTED \033[0m" + echo $hr + echo "-> Script : $0" + echo "-> Num Script Args : $num_of_args" + echo "-> Script Args : $all_args" + echo "-> Shell : $SHELL" + echo "-> Script Path : $script_path" + echo "-> Script (full) : $SHELL $script_path $all_args" + echo "-> User : $USER" + echo "-> Working Directory : $PWD" + echo "-> Failed Command : $BASH_COMMAND" + echo "-> Line Number : $LINENO" + echo "-> Exit Status : $exit_code" + echo "-> Seconds Elapsed : $SECONDS" + echo "-> Date Failed : $(date)" + # Generate a professional, clean stack traceback + echo "-> Stack Trace" + printf "\t" # to intent da stack trace + local frame=0 + # Loop backwards through the function execution stack array + while caller $frame; do + printf "\t" # to indenet da stack trace + frame=$((frame + 1)) + done + + # closing niceties + echo + echo $hr + echo + + # exit with last failcode + exit "$exit_code" +} + +trap error_handle ERR +``` + show every set variale and its value (one liner) ```bash for v in $(compgen -v); do echo "$v:$$v"; done diff --git a/customscripts/debian-setup.sh b/customscripts/debian-setup.sh new file mode 100644 index 0000000..7211e18 --- /dev/null +++ b/customscripts/debian-setup.sh @@ -0,0 +1,77 @@ +#!/bin/bash +set -euo pipefall + +# to give pass/fail output from da commmands +## usage like checkcode $? +checkcode () { + if [ -z "$1" ]; then + echo -e "\n\e[31mERROR!\033[0m chkcode missing return code paramater\n" + exit 1 + else + retcode=$1 + fi + + if [ $retcode -ne 0 ]; then + echo -e "\t\e[31mERROR!\033[0m Response Code: $retcode" + else + echo -e "\t\e[1;32mOK!\e[0m" + fi +} + +echo "apt: START" +echo "apt: updating" +sudo apt update &> /dev/null +checkcode $? +echo "apt: running dist-upgrade" +sudo apt dist-upgrade -y &> /dev/null +checkcode $? +echo "apt: install packages" +sudo apt install -y gawk curl wget git gh build-essential scrypt openssl argon2 qbittorrent xfce4 apache2 php php-cli php-bz2 php-crypt-gpg php-curl php-date php-db php-decimal php-doc php-email-validator php-enum php-facedetect &> /dev/null +checkcode $? +echo "apt: autoremoving" +sudo apt autoremove -y &> /dev/null +checkcode $? +echo "apt: FINISHED" + +echo "pyenv: START" +echo "pyenv: installin" +curl -fsSL https://pyenv.run | bash &> /dev/null +checkcode $? +echo "pyenv: adding exports to ~/.bashrc" +echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc +checkcode $? +echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc +checkcode $? +echo 'eval "$(pyenv init - bash)"' >> ~/.bashrc +checkcode $? +echo "pyenv: sourcing to ~/.bashrc" +source ~/.bashrc +checkcode $? +echo "pyenv: installing latest python3" +pyenv install 3:latest &> /dev/null +checkcode $? +echo "pyenv: setting latest python3 as global" +pyenv global 3:latest &> /dev/null +checkcode $? +echo "pyenv: FINISHED" + +echo "ble.sh: START" +echo "ble.sh: changing directory to /tmp" +cd /tmp +checkcode $? +echo "ble.sh: downloading" +git clone --recursive --depth 1 --shallow-submodules --single-branch -b master https://github.com/akinomyoga/ble.sh.git &> /dev/null +checkcode $? +echo "ble.sh: building and installing" +make -C ble.sh install PREFIX=~/.local &> /dev/null +checkcode $? +echo "ble.sh: setting up ~/.bashrc file" +echo '# ble.sh' >> ~/.bashrc +checkcode $? +echo 'source -- ~/.local/share/blesh/ble.sh' >> ~/.bashrc +checkcode $? +echo 'ble.sh: sourcing ~/.bashrc' +checkcode $? +source ~/.bashrc +checkcode $? +echo "ble.sh: FINISH"