From 343a048be4b32d18540c6531048d2b9a006774ae Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sat, 3 Aug 2019 13:55:50 -0400 Subject: [PATCH] shellcheck, better automated upgrades --- .gitconfig | 3 +- brc | 13 +-- btrbk-run | 2 +- btrfsmaint | 2 +- certbot-renew-hook | 2 +- check-subvol-stale | 6 +- conflink | 14 ++-- demohost-mount | 2 +- desktop-20-autostart.sh | 2 +- small-backup => disabled/small-backup | 0 distro-begin | 7 +- distro-end | 79 +++++++++++++++---- distro-pkgs | 6 -- filesystem/etc/X11/Xsession.d/98iank | 6 +- filesystem/usr/local/bin/mailtest-check | 4 +- filesystem/usr/local/bin/mycheckrestart | 17 ++++ .../{zelous-unattended-reboot => myupgrade} | 14 ++++ i3-sway/gen | 2 +- install-my-scripts | 4 +- keyscript-off | 2 +- keyscript-on | 2 +- machine_specific/kd/filesystem/etc/cron.d/kd | 12 --- mail-route | 2 +- mail-setup | 9 +-- mymimes | 2 +- path_add-function | 2 +- pkgs | 1 + primary-setup | 4 +- radicale-setup | 6 +- rootsshsync | 2 +- schrootupdate | 2 +- switch-mail-host | 4 +- system-status | 12 +-- trusted-network | 2 +- untrusted-network | 2 +- 35 files changed, 157 insertions(+), 94 deletions(-) rename small-backup => disabled/small-backup (100%) create mode 100755 filesystem/usr/local/bin/mycheckrestart rename filesystem/usr/local/bin/{zelous-unattended-reboot => myupgrade} (56%) delete mode 100755 machine_specific/kd/filesystem/etc/cron.d/kd diff --git a/.gitconfig b/.gitconfig index 186dac4..89d0171 100644 --- a/.gitconfig +++ b/.gitconfig @@ -27,7 +27,8 @@ helper = cache ignoreSubmodules = dirty tool = meld # gitinspector complained -renamelimit = 5000 +#renamelimit = 5000 +renames = copy [gitreview] username = iank diff --git a/brc b/brc index 1d6e833..55efac1 100644 --- a/brc +++ b/brc @@ -26,9 +26,7 @@ unalias -a shopt -s extglob # include .files when globbing, but ignore files name . and .. # setting this also sets dotglob. -# Note, this doesnt work in bash 4.4 anymore, for paths with -# more than 1 directory, like a/b/.foo, since * is fixed to not match / -export GLOBIGNORE=*/.:*/.. +export GLOBIGNORE="*/.:*/.." # broken with bash_completion package. Saw a bug for this once. dont anymore. # still broken in wheezy @@ -1637,12 +1635,17 @@ sgo() { # service go fi } +sgu() { + systemctl list-unit-files | rg "$@" +} -shellck() { +sk() { # 2086 = unquoted $var # 2046 = unquoted $(cmd) + # 2068: Double quote array expansions to avoid re-splitting elements. # i had -x as an arg, but debian testing(stretch) doesn\'t support it - shellcheck -e 2086,2046,2068,2006,2119 "$@" + shellcheck -x -e 2086,2046,2068 "$@" + # had this before. not sure what it is 2119 } skaraoke() { diff --git a/btrbk-run b/btrbk-run index 7dad03a..48550db 100644 --- a/btrbk-run +++ b/btrbk-run @@ -17,7 +17,7 @@ # todo: if we cancel in the middle of a btrfs send, then run again immediately, the received subvolume doesn't get a Received UUID: field, and we won't mount it. Need to figure out a solution that will fix this. -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" source /usr/local/lib/err diff --git a/btrfsmaint b/btrfsmaint index 22cd4c6..c410b7b 100755 --- a/btrfsmaint +++ b/btrfsmaint @@ -84,7 +84,7 @@ for x in $($fnd --output "SOURCE" --nofsroot | sort -u); do # the wiki recommends 30 days or so, but # it makes the comp lag like shit for a day, # so I'm going with 90 days. - if (( $date > `date +%s` - 60*60*24*30 )); then + if (( date > $(date +%s) - 60*60*24*30 )); then echo "cron: skiping scrub of $mnt" continue fi diff --git a/certbot-renew-hook b/certbot-renew-hook index 70aa418..9725594 100755 --- a/certbot-renew-hook +++ b/certbot-renew-hook @@ -26,7 +26,7 @@ for ((i=0; i<${#domain_user[@]}; i+=2)); do user=${domain_user[i+1]} d=/etc/letsencrypt/live/$domain - if [[ $RENEWED_LINEAGE == $d ]]; then + if [[ $RENEWED_LINEAGE == "$d" ]]; then install -m 640 -g $user $d/{privkey.pem,fullchain.pem} $(eval echo ~$user) exit 0 fi diff --git a/check-subvol-stale b/check-subvol-stale index 8d9ac78..07926ef 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -14,7 +14,7 @@ # limitations under the License. -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR @@ -57,7 +57,7 @@ while true; do esac done -if [[ ! $@ ]]; then +if [[ ! $1 ]]; then echo "$0: error: expected mountpoint argument" fi @@ -104,7 +104,7 @@ for d; do d "svp=$svp # subvolume path" snaps=($root_dir/btrbk/$subvol_dir.20*) # Assumes we are in the 21st century. - if [[ ! ${snaps[@]} ]]; then + if [[ ! ${snaps[*]} ]]; then # no snapshots yet echo "$0: warning: no snapshots found at $root_dir/btrbk/$subvol_dir.20*. this is expected for a brand new volume" continue diff --git a/conflink b/conflink index 5f38a59..bb5d480 100755 --- a/conflink +++ b/conflink @@ -26,12 +26,14 @@ subdir-link-r() { targets=( "$2"/!(.git|..|.) ) else for f in "$1"/!(.git|..|.); do - [[ -d $f ]] && targets+=("$f") ||: + if [[ -d $f ]]; then targets+=("$f"); fi done fi - local below="$( readlink -f "$root/..")" + local below + below="$( readlink -f "$root/..")" for path in "${targets[@]}"; do - local fullpath="$(readlink -f "$path")" + local fullpath + fullpath="$(readlink -f "$path")" #e $fullpath $below # debug if [[ -f $path || $(dirname $(readlink -f "$fullpath")) == "$below" ]]; then m lnf -T "$path" "$HOME/${path#$root/}" @@ -44,7 +46,7 @@ subdir-link-r() { common-file-setup() { - local dir fs x bdir f dst + local dir fs x f for dir in "$@"; do fs=$dir/filesystem if [[ -e $fs && $user =~ ^iank?$ ]]; then @@ -77,7 +79,7 @@ case $user in /p/c/filesystem/etc/openvpn/easy-rsa/keys/*.key /p/c/machine_specific/kw/filesystem/etc/openvpn/client/*.key ) - if [[ -e $files ]]; then + if [[ -e ${files[0]} ]]; then chmod 600 ${files[@]} fi # p needs to go first so .ssh link is created, then config link inside it @@ -113,7 +115,7 @@ case $user in sudo bash -c 'shopt -s nullglob; cd /etc/openvpn; for f in client/* server/*; do ln -sf $f .; done' - m sudo -H -u user2 "$BASH_SOURCE" + m sudo -H -u user2 "${BASH_SOURCE[0]}" ;; user2) m common-file-setup ${c_dirs[@]} diff --git a/demohost-mount b/demohost-mount index 8dc0620..706a516 100755 --- a/demohost-mount +++ b/demohost-mount @@ -3,7 +3,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" diff --git a/desktop-20-autostart.sh b/desktop-20-autostart.sh index 842dab4..03be1c5 100755 --- a/desktop-20-autostart.sh +++ b/desktop-20-autostart.sh @@ -24,7 +24,7 @@ fi xout="$(xrandr)" xe() { echo "$xout"; } -x=$(xe | grep -E '^(DisplayPort-[0123]|DVI-0|DP-[1234]|DVI-I-1) connected' | wc -l) +x=$(xe | grep -Ec '^(DisplayPort-[0123]|DVI-0|DP-[1234]|DVI-I-1) connected') if (( x > 2 )); then left=$(xe | sed -rn 's/^(DVI[^ ]+) connected .*/\1/p') dps=( $(xe | sed -rn 's/^(DP-[01234]|DisplayPort-[01234]) connected .*/\1/p') ) diff --git a/small-backup b/disabled/small-backup similarity index 100% rename from small-backup rename to disabled/small-backup diff --git a/distro-begin b/distro-begin index ec39e9d..0601ff4 100755 --- a/distro-begin +++ b/distro-begin @@ -65,7 +65,8 @@ fi ##### variables/env setup -script_dir="$(readlink -f "$BASH_SOURCE")"; script_dir=${script_dir%/*} +script_dir="$(readlink -f "${BASH_SOURCE[@]}")"; script_dir=${script_dir%/*} +# shellcheck source=./pkgs source $script_dir/pkgs set +x source /a/bin/distro-functions/src/identify-distros @@ -138,7 +139,7 @@ EOF sudo systemctl start keyscriptoff.service # from /usr/share/doc/dropbear-initramfs/README.initramfs.gz - while read m _; do /sbin/modinfo -F filename "$m"; done &2' ERR for dir in /i /mnt/iroot /k /kr /w; do diff --git a/distro-end b/distro-end index 84566b8..14cc2f5 100755 --- a/distro-end +++ b/distro-end @@ -15,8 +15,9 @@ ### setup source /a/bin/errhandle/err -src="$(readlink -f -- "$BASH_SOURCE")"; src=${src%/*} # directory of this file +src="$(readlink -f -- "${BASH_SOURCE[0]}")"; src=${src%/*} # directory of this file +# shellcheck source=./pkgs source $src/pkgs set -x @@ -35,6 +36,7 @@ spa() { # simple package add simple_packages+=($@) } distro=$(distro-name) +codename=$(debian-codename) codename_compat=$(debian-codename-compat) pending_reboot=false sed="sed --follow-symlinks" @@ -184,15 +186,38 @@ sgo certbotmail.timer pi ${p1[@]} ##### begin automatic upgrades #### -# this makes it so we upgrade everything -s debconf-set-selections <<'EOF' -unattended-upgrades unattended-upgrades/origins_pattern string "codename=${distro_codename}"; + +s dd of=/etc/apt/apt.conf.d/10periodic <<'EOF' +# this file was mostly just comments. +APT::Periodic::Update-Package-Lists "1"; +APT::Periodic::Download-Upgradeable-Packages "1"; +APT::Periodic::AutocleanInterval "7"; +APT::Periodic::Unattended-Upgrade "1"; +EOF + +s dd of=/etc/apt/apt.conf.d/50unattended-upgrades <>.env.production done found=false - while read -r domain port pass; do + while read -r domain _ pass; do if [[ $domain == mail.iankelling.org ]]; then found=true # remove the username part @@ -759,6 +784,21 @@ EOF # newer version needed for false positive in checkrestart p install -y --allow-unauthenticated debian-goodies + s dd of=/etc/apt/preferences.d/shellcheck <&2; exit 1; fi + +if [[ $EUID != 0 ]]; then s=sudo; fi + +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +hn=$(hostname -f) +source /a/bin/bash_unpublished/source-state +if [[ $HOSTNAME != "$MAIL_HOST" && $hn != li.b8.nz && ! $DISPLAY ]]; then + exit 0 +fi + +$s checkrestart | sed '/^Found 0 processes using old versions of upgraded files$/d' diff --git a/filesystem/usr/local/bin/zelous-unattended-reboot b/filesystem/usr/local/bin/myupgrade similarity index 56% rename from filesystem/usr/local/bin/zelous-unattended-reboot rename to filesystem/usr/local/bin/myupgrade index a4672f3..3df5f0e 100755 --- a/filesystem/usr/local/bin/zelous-unattended-reboot +++ b/filesystem/usr/local/bin/myupgrade @@ -1,4 +1,18 @@ #!/bin/bash +# Copyright (C) 2019 Ian Kelling +# SPDX-License-Identifier: AGPL-3.0-or-later + +if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi + +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +hn=$(hostname -f) +source /a/bin/bash_unpublished/source-state +if [[ $HOSTNAME == "$MAIL_HOST" || $hn == li.b8.nz ]]; then + exit 0 +fi + if [[ $(/usr/sbin/checkrestart | wc -l) != 1 ]]; then for x in {30..1}; do echo "pid $PID. unattended upgrade, rebooting in $((x*10)) seconds" | wall -n diff --git a/i3-sway/gen b/i3-sway/gen index bf24f81..22a4e47 100755 --- a/i3-sway/gen +++ b/i3-sway/gen @@ -3,7 +3,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -x="$(readlink -f -- "$BASH_SOURCE")"; cd ${x%/*} # directory of this file +x="$(readlink -f -- "${BASH_SOURCE[0]}")"; cd ${x%/*} # directory of this file cat common.conf sway.conf > /a/bin/distro-setup/subdir_files/.config/sway/config cat common.conf i3.conf > /a/bin/distro-setup/subdir_files/.config/i3/config diff --git a/install-my-scripts b/install-my-scripts index fc61239..0e36a4f 100755 --- a/install-my-scripts +++ b/install-my-scripts @@ -23,9 +23,9 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" -x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} +x="$(readlink -f -- "${BASH_SOURCE[0]}")"; cd ${x%/*} # directory of this file # scripts that would interfere with unmounting /a, put them elsewhere diff --git a/keyscript-off b/keyscript-off index bb63cb2..b26ed9d 100755 --- a/keyscript-off +++ b/keyscript-off @@ -16,7 +16,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR -[[ $EUID == 0 ]] || exec sudo "${BASH_SOURCE}" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" if [[ $- != *i* ]]; then exec &>/var/log/keyscript-off.log echo "$0: starting. $(date)" diff --git a/keyscript-on b/keyscript-on index 7950ebe..e62c7ed 100755 --- a/keyscript-on +++ b/keyscript-on @@ -16,7 +16,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR -[[ $EUID == 0 ]] || exec sudo "${BASH_SOURCE}" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" if [[ $- != *i* ]]; then exec &>>/var/log/keyscript-on.log echo "$0: starting. $(date)" diff --git a/machine_specific/kd/filesystem/etc/cron.d/kd b/machine_specific/kd/filesystem/etc/cron.d/kd deleted file mode 100755 index fccd071..0000000 --- a/machine_specific/kd/filesystem/etc/cron.d/kd +++ /dev/null @@ -1,12 +0,0 @@ -# disabled for various reasons -# */5 * * * * /a/bin/offlineimap_cronjob -# */1 * * * * unison ~/.mpv ssh://htpc/.mpv -# small-backpup: -# runs every 10 minutes, every day 4 am, every sunday at 3 am -# stored for 3 days, 2 months, and unlimited respectively -SHELL=/bin/bash -0 4 * * * ian x=$(/usr/local/bin/logq /a/exe/small-backup --retry daily 2M); [[ $? != 0 ]] && echo "$x" -0 3 * * sun ian echo weekly backup results:; /a/exe/small-backup --retry weekly -*/10 * * * * ian /a/exe/small-backup 10minutes 3D 2>&1 | /usr/local/bin/log-once small-backup-10min -# put things we don't want to send mail about below this: -# MAILTO="" diff --git a/mail-route b/mail-route index 1dea430..52f4651 100755 --- a/mail-route +++ b/mail-route @@ -13,7 +13,7 @@ set -x # See the License for the specific language governing permissions and # limitations under the License. -[[ $EUID == 0 ]] || exec sudo "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" source /a/bin/errhandle/err diff --git a/mail-setup b/mail-setup index b97f3b9..93d09c7 100755 --- a/mail-setup +++ b/mail-setup @@ -21,7 +21,7 @@ set -x set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" if [[ ! $SUDO_USER ]]; then echo "$0: error: requires running as nonroot or sudo" exit 1 @@ -345,7 +345,7 @@ cat >$f <<'EOF' set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" f=/a/bin/bash_unpublished/source-state if [[ -e $f ]]; then @@ -398,11 +398,6 @@ systemctl start mailcert systemctl restart mailcert.timer systemctl enable mailcert.timer -# This symlink is only here to so I can use the -# fsf mailman ansible role and trick its cert script -# into doing nothing. -/a/exe/lnf -T /etc/exim4/exim.crt /etc/letsencrypt/live/$(hostname -f)/fullchain.pem - ##### end mailcert setup ##### # comon stuff diff --git a/mymimes b/mymimes index 2130c37..3177908 100755 --- a/mymimes +++ b/mymimes @@ -3,7 +3,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" shopt -s extglob nullglob diff --git a/path_add-function b/path_add-function index 540306c..f2f4299 100644 --- a/path_add-function +++ b/path_add-function @@ -22,7 +22,7 @@ path_add() { --help: print this --end: adds to end of path, which will give it lowest priority --ifexists: add to path only if directory exists" - local found x y z ifexists end loop newpath + local found x y ifexists end loop newpath ifexists=false end=false loop=true diff --git a/pkgs b/pkgs index eae95c3..d8acab1 100644 --- a/pkgs +++ b/pkgs @@ -167,6 +167,7 @@ p4=( rng-tools sakura schroot + shellcheck sig2dot sipcalc sqlite3-doc diff --git a/primary-setup b/primary-setup index 30c4222..d6c0ed9 100755 --- a/primary-setup +++ b/primary-setup @@ -7,7 +7,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -if [[ ! $SUDO_USER || $EUID == 0 ]]; then +if [[ $EUID == 0 && ! $SUDO_USER ]]; then echo "$0: error: requires running as nonroot or sudo" exit 1 fi @@ -18,7 +18,7 @@ if [[ $1 ]]; then source /a/bin/bash_unpublished/source-state fi -if [[ $HOSTNAME == $MAIL_HOST ]]; then +if [[ $HOSTNAME == "$MAIL_HOST" ]]; then # arbtt disabled for now #DISPLAY=:0 arbtt-capture --sample-rate=10 & sudo systemctl start rss2email.timer diff --git a/radicale-setup b/radicale-setup index 3cfaa82..cb43a47 100755 --- a/radicale-setup +++ b/radicale-setup @@ -1,6 +1,6 @@ #!/bin/bash -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" if [[ -e /b/errhandle/err ]]; then source /b/errhandle/err @@ -49,8 +49,8 @@ systemctl daemon-reload # not sure this is needed pi-nostart radicale # use persistent uid/gid -IFS=:; read _ _ uid _ < <(getent passwd radicale ); unset IFS -IFS=:; read _ _ gid _ < <(getent group radicale ); unset IFS +IFS=:; read -r _ _ uid _ < <(getent passwd radicale ); unset IFS +IFS=:; read -r _ _ gid _ < <(getent group radicale ); unset IFS if [[ $uid != 609 ]]; then systemctl stop radicale ||: usermod -u 609 radicale diff --git a/rootsshsync b/rootsshsync index 90928c6..c550149 100755 --- a/rootsshsync +++ b/rootsshsync @@ -16,7 +16,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" dest=/root/.ssh diff --git a/schrootupdate b/schrootupdate index 280095d..832b015 100755 --- a/schrootupdate +++ b/schrootupdate @@ -3,7 +3,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" for n in stretch jessie; do if [[ -e /etc/schroot/chroot.d/$n.conf ]]; then diff --git a/switch-mail-host b/switch-mail-host index 10fcd9f..f26b945 100644 --- a/switch-mail-host +++ b/switch-mail-host @@ -59,8 +59,8 @@ old_host=$1 new_host=$2 source /a/bin/bash_unpublished/source-state -if [[ $old_host != $MAIL_HOST ]]; then - read -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N " +if [[ $old_host != "$MAIL_HOST" ]]; then + read -r -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N " if [[ $REPLY != [yY] ]]; then exit 1 fi diff --git a/system-status b/system-status index c92bc9a..49f734a 100755 --- a/system-status +++ b/system-status @@ -18,16 +18,16 @@ write-status() { chars=() glob=(/nocow/btrfs-stale/*) - if [[ -e $glob ]] ; then + if [[ -e ${glob[0]} ]]; then chars+=("STALE!") fi glob=(/m/md/bounces/new/*) - if [[ -e $glob ]]; then + if [[ -e ${glob[0]} ]]; then chars+=("BOUNCE!") lo -1 bounce "message in /m/md/bounces/new" fi glob=(/m/md/alerts/new/* /m/md/alerts/cur/*) - if [[ -e $glob ]]; then + if [[ -e ${glob[0]} ]]; then chars+=("ALERT!") fi if [[ -e /nocow/user/mailtest-failure ]]; then @@ -39,7 +39,7 @@ write-status() { fi source /a/bin/bash_unpublished/source-state - if [[ $MAIL_HOST == $HOSTNAME ]]; then + if [[ $MAIL_HOST == "$HOSTNAME" ]]; then if [[ $(systemctl is-active btrbk.timer) != active ]]; then chars+=("BTRBK.TIMER!") lo -60 btrbk.timer "btrbk.timer not enabled" @@ -65,13 +65,13 @@ write-status() { cat /a/bin/bash_unpublished/source-state >$status_file - if [[ $chars ]]; then + if [[ ${chars[*]} ]]; then echo "ps_char=\"${chars[*]} \$ps_char\"" >>$status_file fi } write-status -if [[ $@ ]]; then +if [[ $1 ]]; then cat $status_file exit 0 fi diff --git a/trusted-network b/trusted-network index ea1d9f4..d227137 100755 --- a/trusted-network +++ b/trusted-network @@ -3,7 +3,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" # Usage: run when switching from an untrusted network like public wifi # to a trusted one. diff --git a/untrusted-network b/untrusted-network index c9a43db..3d8ac97 100755 --- a/untrusted-network +++ b/untrusted-network @@ -3,7 +3,7 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR -[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" # Usage: use when switching from a trusted network to an untrusted one, # like public wifi. -- 2.30.2