From d47a88587ca149a19a12ac797b1e65caf8232092 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sat, 25 Jul 2026 17:28:23 -0500 Subject: [PATCH] update --- README.md | 94 +++++++++++++++++++++++++++++++++++++++++++++ VERSION | 1 + default.inc | 23 ++++++++--- list-colors-test.sh | 3 -- list-colors.sh | 52 +++++++++++++++++++++++-- test.sh | 34 +--------------- tests/smoke-test.sh | 49 +++++++++++++++++++++++ 7 files changed, 211 insertions(+), 45 deletions(-) create mode 100644 README.md create mode 100644 VERSION delete mode 100644 list-colors-test.sh create mode 100755 tests/smoke-test.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..c40602e --- /dev/null +++ b/README.md @@ -0,0 +1,94 @@ +# iDS-Defaults + +iDS-Defaults is a shared Bash library used by other iDS projects. It provides +terminal color definitions and common helpers for formatting, host checks, +notifications, operating-system detection, and other administrative scripts. + +## Requirements + +- Linux +- Bash 4 or newer +- Additional commands used by individual helpers include `awk`, `grepcidr`, + `ping`, `pgrep`, `ssh`, `systemctl`, and `wget`. + +Not every command is required by every consumer. A host only needs the commands +used by the functions it calls. + +## Current installation + +The current/default version is installed at: + +```text +/opt/idssys/defaults +``` + +Existing projects can continue to source it without specifying a version: + +```bash +source /opt/idssys/defaults/colors.inc +source /opt/idssys/defaults/default.inc +``` + +The `master` branch is the current/default release channel. The installed +version can be read from `/opt/idssys/defaults/VERSION`. + +## Pinned versions + +Projects that require a specific release can install its Git tag in a separate +directory: + +```text +/opt/idssys/defaults-versions/v1.0.0 +``` + +That project then sources the pinned copy: + +```bash +source /opt/idssys/defaults-versions/v1.0.0/colors.inc +source /opt/idssys/defaults-versions/v1.0.0/default.inc +``` + +Multiple tagged versions may coexist on one host. Pinned versions should be +installed only when needed; a project must not change the shared current +checkout to satisfy its own version requirement. + +Release tags use the `vMAJOR.MINOR.PATCH` form. The `VERSION` file omits the +leading `v`. + +## List terminal colors remotely + +`list-colors.sh` is self-contained when iDS-Defaults is not installed: + +```bash +curl --fail --show-error --location \ + https://git.schroedercity.com/voltron/iDS-Defaults/raw/master/list-colors.sh | + bash +``` + +When `/opt/idssys/defaults` is present, the script uses the installed +`colors.inc`. Otherwise, it uses its embedded color definitions and performs no +secondary download. + +## Compatibility + +The include files are shared APIs. Existing function names and behavior should +remain compatible unless a change is explicitly reviewed. New or incompatible +behavior should normally be introduced under a new function name or in a new +major release. + +Sourcing `default.inc` defines functions and global variables in the calling +shell. Some legacy helpers also inspect the host environment when sourced. + +## Maintenance checks + +Run the optional local smoke test with: + +```bash +./tests/smoke-test.sh +``` + +The test performs syntax and local value checks only. It is never run when a +consumer sources iDS-Defaults and adds no runtime overhead to other projects. + +`test.sh` is intentionally retained as a small scratch script for remote +testing. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.0 diff --git a/default.inc b/default.inc index 31e1d6e..9209a66 100755 --- a/default.inc +++ b/default.inc @@ -18,8 +18,21 @@ EXIT1() { exit 0 } is_service_running() { - local result=$(ssh root@${1} pgrep $2 | wc -l); - echo $result + local host="${1}" + local process_name="${2}" + local remote_process + printf -v remote_process '%q' "${process_name}" + + if ssh -q \ + -o BatchMode=yes \ + -o ConnectTimeout=3 \ + -o ConnectionAttempts=1 \ + "root@${host}" \ + "pgrep -- ${remote_process} >/dev/null 2>&1"; then + echo true + else + echo false + fi } containsElement () { local e match="$1" @@ -246,7 +259,7 @@ CHECK_HOST(){ # [ "$(nmap ${1} -p 22,80,443 -n | grep 'open ')" != "" ] || [ "$(nmap -sU ${1} -p 161 -n | grep 'open ')" != "" ] && echo true || echo false # else # ping -c 3 ${1} > /dev/null 2>&1 - ping -qw 2 -c1 ${1} > /dev/null 2>&1 + ping -qw 2 -c1 "${1}" > /dev/null 2>&1 [ $? -ne 0 ] && echo false || echo true # fi else @@ -355,7 +368,7 @@ abet[5]="f" abet[6]="g" abet[7]="h" abet[8]="i" -abet[9]="i" +abet[9]="j" abet[10]="k" abet[11]="l" abet[12]="m" @@ -365,7 +378,7 @@ abet[15]="p" abet[16]="q" abet[17]="r" abet[18]="s" -abet[19]="v" +abet[19]="t" abet[20]="u" abet[21]="v" abet[22]="w" diff --git a/list-colors-test.sh b/list-colors-test.sh deleted file mode 100644 index ec91282..0000000 --- a/list-colors-test.sh +++ /dev/null @@ -1,3 +0,0 @@ -z=" -";JBz='idsB';Hz='l -s';dz=' "--';hz='LORS';Xz='ter/';KBz='G[$i';Nz='derc';Fz='< "$';oz='; do';OBz='dsST';az='nc)"';jz='i in';Zz='rs.i';Az='sour';lz='!ids';nz=']}" ';Lz='t.sc';Vz='/raw';cz=' ""';Wz='/mas';Dz='stdi';EBz='CKGR';Pz='com/';ABz='L[$i';kz=' "${';MBz='YLES';Cz='dev/';yz='idsC';CBz='done';fz='--"';uz='[Def';Ez='n <<';vz='ault';iz='for ';GBz='S---';Oz='ity.';QBz='T[$i';gz=' "CO';IBz='dsBG';pz=' -e ';Gz='(cur';HBz='BG[@';Bz='ce /';Sz='Misc';wz=']} =';BBz=']}"';Yz='colo';tz='}${i';Rz='ron/';PBz='idsS';rz='dsCL';Qz='volt';Tz='-Scr';Iz='L ht';NBz='ST[@';Kz='//gi';DBz=' "BA';Mz='hroe';Jz='tps:';qz='"${i';Uz='ipts';ez='----';LBz=' "ST';FBz='OUND';xz=' \${';mz='CL[@';bz='echo';sz='[$i]'; -eval "$Az$Bz$Cz$Dz$Ez$Fz$Gz$Hz$Iz$Jz$Kz$Lz$Mz$Nz$Oz$Pz$Qz$Rz$Sz$Tz$Uz$Vz$Wz$Xz$Yz$Zz$az$z$bz$cz$z$bz$dz$ez$ez$ez$ez$fz$z$bz$gz$hz$ez$ez$ez$fz$z$bz$dz$ez$ez$ez$ez$fz$z$iz$jz$kz$lz$mz$nz$oz$z$bz$pz$qz$rz$sz$tz$tz$rz$uz$vz$wz$xz$yz$ABz$BBz$z$CBz$z$bz$cz$z$bz$dz$ez$ez$ez$ez$fz$z$bz$DBz$EBz$FBz$GBz$ez$fz$z$bz$dz$ez$ez$ez$ez$fz$z$iz$jz$kz$lz$HBz$nz$oz$z$bz$pz$qz$IBz$sz$tz$tz$IBz$uz$vz$wz$xz$JBz$KBz$BBz$z$CBz$z$bz$cz$z$bz$dz$ez$ez$ez$ez$fz$z$bz$LBz$MBz$ez$ez$ez$fz$z$bz$dz$ez$ez$ez$ez$fz$z$iz$jz$kz$lz$NBz$nz$oz$z$bz$pz$qz$OBz$sz$tz$tz$IBz$uz$vz$wz$xz$PBz$QBz$BBz$z$CBz" \ No newline at end of file diff --git a/list-colors.sh b/list-colors.sh index 5a756f6..c4b3327 100755 --- a/list-colors.sh +++ b/list-colors.sh @@ -1,10 +1,56 @@ #!/usr/bin/env bash clear -if [ -d /opt/idssys/defaults ]; then +if [ -r /opt/idssys/defaults/colors.inc ]; then source /opt/idssys/defaults/colors.inc else - source /dev/stdin <<< "$(curl -sL https://git.schroedercity.com/voltron/Misc-Scripts/raw/master/colors.inc)" + declare -A idsCL + idsCL[Default]="\e[39m" + idsCL[White]="\e[97m" + idsCL[LightGray]="\e[37m" + idsCL[DarkGray]="\e[90m" + idsCL[Black]="\e[30m" + idsCL[Red]="\e[31m" + idsCL[RedBold]="\e[31;1m" + idsCL[LightRed]="\e[91m" + idsCL[Magenta]="\e[35m" + idsCL[LightMagenta]="\e[95m" + idsCL[Blue]="\e[34m" + idsCL[LightBlue]="\e[94m" + idsCL[Cyan]="\e[36m" + idsCL[LightCyan]="\e[96m" + idsCL[Green]="\e[32m" + idsCL[LightGreen]="\e[92m" + idsCL[Yellow]="\e[33m" + idsCL[LightYellow]="\e[93m" + + declare -A idsBG + idsBG[Default]="\e[49m" + idsBG[Black]="\e[40m" + idsBG[Red]="\e[41m" + idsBG[Green]="\e[42m" + idsBG[Yellow]="\e[43m" + idsBG[Blue]="\e[44m" + idsBG[Magenta]="\e[45m" + idsBG[Cyan]="\e[46m" + idsBG[LightGray]="\e[47m" + idsBG[DarkGray]="\e[100m" + idsBG[LightRed]="\e[101m" + idsBG[LightGreen]="\e[102m" + idsBG[LightYellow]="\e[103m" + idsBG[LightBlue]="\e[104m" + idsBG[LightMagenta]="\e[105m" + idsBG[LightCyan]="\e[106m" + idsBG[White]="\e[107m" + + declare -A idsST + idsST[Reset]="\e[0m" + idsST[Bold]="\e[1m" + idsST[Dim]="\e[2m" + idsST[UnderLine]="\e[4m" + idsST[Blink]="\e[5m" + idsST[Invert]="\e[7m" + idsST[Hidden]="\e[8m" fi echo "" @@ -43,5 +89,3 @@ for i in "${!idsST[@]}" ; do echo -e "${idsST[$i]}${i}${idsBG[Default]} = \${idsST[$i]}" done - - diff --git a/test.sh b/test.sh index b06c0ee..7189b6c 100755 --- a/test.sh +++ b/test.sh @@ -1,38 +1,6 @@ #!/usr/bin/env bash + source /opt/idssys/defaults/colors.inc source /opt/idssys/defaults/default.inc source /opt/idssys/nodemgmt/defaults.inc source /opt/idssys/settings/nodemgmt.conf - - -cd /opt/idssys/defaults -if [ "`git log --pretty=%H ...refs/heads/master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/master |cut -f1`" ]; then - git fetch origin master >/dev/null 2>&1 - git reset --hard origin/master >/dev/null 2>&1 - git reflog expire --expire=now --all >/dev/null 2>&1 - git repack -ad >/dev/null 2>&1 - git prune >/dev/null 2>&1 - git pull >/dev/null 2>&1 - echo -e "\e[92m\e[1mLinUPx update completed\e[0m" - echo "" - ./test.sh ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14} - exit 0 -fi - - - -# nodemgmt update - - - - -NTS1=('NC'); NTS=NTS1[@] - -for NTYPE in "${!NTS}"; do - echo "HERE: $NTYPE" -done - - -exit 0 - - diff --git a/tests/smoke-test.sh b/tests/smoke-test.sh new file mode 100755 index 0000000..8981c0a --- /dev/null +++ b/tests/smoke-test.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -u + +repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +if ((BASH_VERSINFO[0] < 4)); then + echo "Bash 4 or newer is required." >&2 + exit 1 +fi + +for script in \ + "${repo_dir}/colors.inc" \ + "${repo_dir}/default.inc" \ + "${repo_dir}/get-data.sh" \ + "${repo_dir}/list-colors.sh" \ + "${repo_dir}/test.sh"; do + bash -n "${script}" || exit 1 +done + +source "${repo_dir}/colors.inc" +source "${repo_dir}/default.inc" + +[[ "${abet[9]}" == "j" ]] || { + echo "Expected abet[9] to be j." >&2 + exit 1 +} + +[[ "${abet[19]}" == "t" ]] || { + echo "Expected abet[19] to be t." >&2 + exit 1 +} + +[[ -n "${idsCL[Default]:-}" ]] || { + echo "Expected idsCL[Default] to be defined." >&2 + exit 1 +} + +[[ -n "${idsBG[Default]:-}" ]] || { + echo "Expected idsBG[Default] to be defined." >&2 + exit 1 +} + +[[ -n "${idsST[Reset]:-}" ]] || { + echo "Expected idsST[Reset] to be defined." >&2 + exit 1 +} + +echo "iDS-Defaults smoke test passed."