diff options
author | Cullum Smith <cullum@sacredheartsc.com> | 2024-07-11 21:25:13 -0400 |
---|---|---|
committer | Cullum Smith <cullum@sacredheartsc.com> | 2024-07-11 21:25:13 -0400 |
commit | 010a4bc91e745ef34175b521830f9c2b644cb0e6 (patch) | |
tree | 942b639b1a86e73679fcff312e3bf1562512ff14 | |
parent | 23447b9622b3e39fce4737aa913f830710618adf (diff) | |
download | infrastructure-010a4bc91e745ef34175b521830f9c2b644cb0e6.tar.gz |
make boxconf command line more intuitive, fix undef vars
-rwxr-xr-x | boxconf | 10 | ||||
-rw-r--r-- | lib/10-core | 2 | ||||
-rw-r--r-- | lib/30-files | 34 | ||||
-rw-r--r-- | lib/40-os | 6 |
4 files changed, 27 insertions, 25 deletions
@@ -5,7 +5,7 @@ set -eu PROGNAME=boxconf -USAGE="${PROGNAME} [-d] [-e VAR=VALUE]... [-o HOSTNAME] TARGET" +USAGE="${PROGNAME} [-d] [-e VAR=VALUE]... [-s SSH_HOST] HOSTNAME" BOXCONF_ROOT=$(dirname "$(readlink -f "$0")") usage(){ @@ -14,12 +14,12 @@ usage(){ exit 2 } -while getopts :hde:o:X _bc_opt; do +while getopts :hde:s:X _bc_opt; do case $_bc_opt in h) usage ;; d) set -x ;; e) eval "$OPTARG" ;; - o) BOXCONF_HOSTNAME=$OPTARG ;; + s) BOXCONF_SSH_HOST=$OPTARG ;; X) _bc_run=1 ;; :) usage "missing option value: -${OPTARG}" ;; ?) usage "unknown option: -${OPTARG}" ;; @@ -29,6 +29,8 @@ done shift $((OPTIND - 1)) [ $# -eq 1 ] || usage +BOXCONF_HOSTNAME=$1 + for _bc_lib in "${BOXCONF_ROOT}/lib"/*; do . "$_bc_lib" done @@ -36,5 +38,5 @@ done if [ -n "${_bc_run:-}" ]; then _boxconf_run else - _boxconf_deploy "$1" "${BOXCONF_HOSTNAME:-$1}" "$@" + _boxconf_deploy "${BOXCONF_SSH_HOST:-$1}" "$BOXCONF_HOSTNAME" "$@" fi diff --git a/lib/10-core b/lib/10-core index 8e01afc..d7280d9 100644 --- a/lib/10-core +++ b/lib/10-core @@ -221,7 +221,7 @@ _boxconf_deploy(){ # $2 = hostname used for configuration # $3..$N = original boxconf CLI args _bc_deploy_target=$1; shift - _bc_deploy_hostname=$2; shift + _bc_deploy_hostname=$1; shift _bc_stagedir=$(mktemp -d -t "boxconf-${_bc_deploy_hostname}") trap 'rm -rf -- "$_bc_stagedir"' HUP INT QUIT TERM ABRT EXIT diff --git a/lib/30-files b/lib/30-files index fb4bbee..767bbeb 100644 --- a/lib/30-files +++ b/lib/30-files @@ -3,23 +3,23 @@ _boxconf_try_files(){ # Get the highest precedence file for a given path. # $1 = target file path - for _bcsf_file in \ - "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_HOSTNAME}" \ - "${BOXCONF_FILE_DIR}${1}.${BOXCONF_HOSTNAME}" \ - "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}.${BOXCONF_OS_DISTRIBUTION}" \ - "${BOXCONF_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}.${BOXCONF_OS_DISTRIBUTION}" \ - "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_OS_DISTRIBUTION}.${BOXCONF_HOSTCLASS}" \ - "${BOXCONF_FILE_DIR}${1}.${BOXCONF_OS_DISTRIBUTION}.${BOXCONF_HOSTCLASS}" \ - "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}.${BOXCONF_OS_FAMILY}" \ - "${BOXCONF_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}.${BOXCONF_OS_FAMILY}" \ - "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_OS_FAMILY}.${BOXCONF_HOSTCLASS}" \ - "${BOXCONF_FILE_DIR}${1}.${BOXCONF_OS_FAMILY}.${BOXCONF_HOSTCLASS}" \ - "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}" \ - "${BOXCONF_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}" \ - "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_OS_DISTRIBUTION}" \ - "${BOXCONF_FILE_DIR}${1}.${BOXCONF_OS_DISTRIBUTION}" \ - "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_OS_FAMILY}" \ - "${BOXCONF_FILE_DIR}${1}.${BOXCONF_OS_FAMILY}" \ + for _bcsf_file in \ + "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_HOSTNAME}" \ + "${BOXCONF_FILE_DIR}${1}.${BOXCONF_HOSTNAME}" \ + "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}.${BOXCONF_DISTRO}" \ + "${BOXCONF_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}.${BOXCONF_DISTRO}" \ + "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_DISTRO}.${BOXCONF_HOSTCLASS}" \ + "${BOXCONF_FILE_DIR}${1}.${BOXCONF_DISTRO}.${BOXCONF_HOSTCLASS}" \ + "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}.${BOXCONF_OS}" \ + "${BOXCONF_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}.${BOXCONF_OS}" \ + "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_OS}.${BOXCONF_HOSTCLASS}" \ + "${BOXCONF_FILE_DIR}${1}.${BOXCONF_OS}.${BOXCONF_HOSTCLASS}" \ + "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}" \ + "${BOXCONF_FILE_DIR}${1}.${BOXCONF_HOSTCLASS}" \ + "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_DISTRO}" \ + "${BOXCONF_FILE_DIR}${1}.${BOXCONF_DISTRO}" \ + "${BOXCONF_SITE_FILE_DIR}${1}.${BOXCONF_OS}" \ + "${BOXCONF_FILE_DIR}${1}.${BOXCONF_OS}" \ "${BOXCONF_SITE_FILE_DIR}${1}.common" \ "${BOXCONF_FILE_DIR}${1}.common" do @@ -26,7 +26,7 @@ set_loader_conf(){ # Set the FreeBSD bootloader options in /boot/loader.conf. # The host will be rebooted if the file is changed. # $1..$N = bootloader options (as "name=value" strings) - [ "$BOXCONF_OS_FAMILY" = freebsd ] || bug 'set_loader_conf can only be used on FreeBSD' + [ "$BOXCONF_OS" = freebsd ] || bug 'set_loader_conf can only be used on FreeBSD' while [ $# -gt 0 ]; do grep -qxF "${1%%=*}=\"${1#*=}\"" /boot/loader.conf || BOXCONF_NEED_REBOOT=true @@ -50,7 +50,7 @@ x load_kernel_module(){ # Ensure the given kernel modules are loaded. # $1..$N = bootloader options (as "name=value" strings) - case $BOXCONF_OS_FAMILY in + case $BOXCONF_OS in freebsd) while [ $# -gt 0 ]; do kldstat -qn "$1" || kldload -v "$1" @@ -58,7 +58,7 @@ load_kernel_module(){ done ;; *) - die "load_kernel_module unimplemented for ${BOXCONF_OS_FAMILY}" + die "load_kernel_module unimplemented for ${BOXCONF_OS}" ;; esac } |