From 18f047b9ca1e0ef50e8872957b25919351dadfc7 Mon Sep 17 00:00:00 2001 From: "Lockszmith (kateryna)" Date: Sat, 21 Sep 2024 14:15:20 -0400 Subject: [PATCH] Introducing ID to sz.env load, better handling of truenas specific code --- _home/dot_bashrc | 10 +++++----- _home/private_dot_config/sz.env/ID_truenas_scale.env | 8 ++++++++ _home/private_dot_config/sz.env/PATH_truestuff.env | 2 +- _home/private_dot_config/sz.env/executable__.load.sh | 5 ++++- _home/private_dot_config/sz.env/zzz_bash_post.env | 12 ++++++++++++ 5 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 _home/private_dot_config/sz.env/ID_truenas_scale.env create mode 100644 _home/private_dot_config/sz.env/zzz_bash_post.env diff --git a/_home/dot_bashrc b/_home/dot_bashrc index 52e331e..13ebe78 100644 --- a/_home/dot_bashrc +++ b/_home/dot_bashrc @@ -16,9 +16,9 @@ [ -z "${DBG_SHRC}" ] || echo "Exiting .bashrc" # This will prevent atuin's setup script from adding itself: atuin init bash -eval "${SZ_ENV_BASH_LOAD_PREEXEC}" -if [[ -n "${BLE_VERSION-}" ]]; then - [[ -n "${DBG}" ]] && echo "attaching ble.sh" - ble-attach -fi +#eval "${SZ_ENV_BASH_LOAD_PREEXEC}" +#if [[ -n "${BLE_VERSION-}" ]]; then +# [[ -n "${DBG}" ]] && echo "attaching ble.sh" +# ble-attach +#fi diff --git a/_home/private_dot_config/sz.env/ID_truenas_scale.env b/_home/private_dot_config/sz.env/ID_truenas_scale.env new file mode 100644 index 0000000..8aa90e1 --- /dev/null +++ b/_home/private_dot_config/sz.env/ID_truenas_scale.env @@ -0,0 +1,8 @@ +#!/usr/bin/env -S bash -c 'echo "Not a user script. source(aka .) only"' + +function is_truenas() { + local TRUENAS_TARGET="truenas.target" + [ "$(systemctl get-default)" = "$TRUENAS_TARGET" ] \ + && [ "$(systemctl is-active "$TRUENAS_TARGET")" = "active" ] +} + diff --git a/_home/private_dot_config/sz.env/PATH_truestuff.env b/_home/private_dot_config/sz.env/PATH_truestuff.env index 2178998..88e9bea 100644 --- a/_home/private_dot_config/sz.env/PATH_truestuff.env +++ b/_home/private_dot_config/sz.env/PATH_truestuff.env @@ -1,6 +1,6 @@ #!/usr/bin/env -S bash -c 'echo "Not a user script. source(aka .) only"' -if is_cmd midclt; then +if is_truenas && is_cmd midclt && [ -z "$SCALE_POOL" ]; then export SCALE_POOL="$(midclt call "kubernetes.config" 2>/dev/null | jq -r '.pool')" [ -d "/mnt/$SCALE_POOL" ] || unset SCALE_POOL fi diff --git a/_home/private_dot_config/sz.env/executable__.load.sh b/_home/private_dot_config/sz.env/executable__.load.sh index 5ad2e54..c32c27a 100644 --- a/_home/private_dot_config/sz.env/executable__.load.sh +++ b/_home/private_dot_config/sz.env/executable__.load.sh @@ -48,11 +48,14 @@ if is_sourced; then # The following constructs a list of load_next ... commands ALL_ENV_FILES="$( find ~/.config/sz.env -xdev -type d -not -name '*.off' \ + -exec sh -c ' + find "$1" -xdev -maxdepth 1 -type f -name "ID_*.env" | sort + ' shell '{}' ';' \ -exec sh -c ' find "$1" -xdev -maxdepth 1 -type f -name "PATH_*.env" | sort ' shell '{}' ';' \ -exec sh -c ' - find "$1" -xdev -maxdepth 1 -type f -name "*.env" -not -name "PATH_*" -print | sort + find "$1" -xdev -maxdepth 1 -type f -name "*.env" -not -name "ID_*" -not -name "PATH_*" -print | sort ' shell '{}' ';' \ | sed -e 's/^/load_next "/; s/$/";/' )" diff --git a/_home/private_dot_config/sz.env/zzz_bash_post.env b/_home/private_dot_config/sz.env/zzz_bash_post.env new file mode 100644 index 0000000..9139b36 --- /dev/null +++ b/_home/private_dot_config/sz.env/zzz_bash_post.env @@ -0,0 +1,12 @@ +#!/usr/bin/env -S bash -c 'echo "Not a user script. source(aka .) only"' + +BASE_SHELL=${BASE_SHELL:-${SHELL##*/}} + +if [[ "${BASE_SHELL}" == "bash" ]]; then + eval "${SZ_ENV_BASH_LOAD_PREEXEC}" + if [[ -n "${BLE_VERSION-}" ]]; then + [[ -n "${DBG}" ]] && echo "attaching ble.sh" + ble-attach + fi +fi +