From: Ian Kelling Date: Tue, 13 Aug 2024 04:18:35 +0000 (-0400) Subject: minor fix plus shellcheck X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=3e713f66d08de0af80b90cf4b0ad76691bc5308a;p=distro-setup minor fix plus shellcheck --- diff --git a/brc2 b/brc2 index be6052d..dc58628 100644 --- a/brc2 +++ b/brc2 @@ -1666,11 +1666,8 @@ srun() { ret=0 unit=$1 journalctl -qn2 -f -u $unit & - systemctl start $unit sleep 2 - kill $jr_pid &>/dev/null ||: - unset jr_pid - fg &>/dev/null ||: + systemctl start $unit } sm() { # switch mail host @@ -3038,15 +3035,7 @@ mnsd() { # mount namespace + systemd namespace mns-setup $ns pid=$(servicepid $unit) - # i can't remember the exact reason i started exporting, but it does keep the - # environment vars perfectly accurate, whereas sudo -E does not quite. Although, - # we could just set those explicity, PATH is the main one. It also - # seems less secure since another process could modify the temp file. - tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX) - export -p >$tmpf - printf "%s " "${@@Q}" >>$tmpf - echo >>$tmpf - echo "rm -f $tmpf" >>$tmpf + env-tmpf "$@" m sudo nsenter -t $pid -n --mount=/root/mount_namespaces/$ns sudo -u $USER -i bash -c ". $tmpf" } @@ -4082,11 +4071,7 @@ sdncmd() { unit=$1 shift pid=$(servicepid $unit) - tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX) - export -p >$tmpf - printf "%s " "${@@Q}" >>$tmpf - echo >>$tmpf - echo "rm -f $tmpf" >>$tmpf + env-tmpf "$@" m sudo nsenter -t $pid -n -m sudo -u $USER -i bash -c ". $tmpf" } @@ -4102,6 +4087,20 @@ sdncmdroot() { # systemd namespace root command m sudo nsenter -t $pid -n -m "$@" } +## create tempfile script which runs command under same env then deletes itself. +# background: i can't remember the exact reason i started exporting, but it does keep the +# environment vars perfectly accurate, whereas sudo -E does not quite. Although, +# we could just set those explicity, PATH is the main one. It also +# seems less secure since another process could modify the temp file. +env-tmpf() { + tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX) + { + export -p + printf "%s " "${@@Q}" + echo + echo "rm -f $tmpf" + } >$tmpf +} # systemd network namespace (not mount) cmd # usage: UNIT CMD... @@ -4114,11 +4113,7 @@ sdnncmd() { unit=$1 shift pid=$(servicepid $unit) - tmpf=$(mktemp --tmpdir $unit.XXXXXXXXXX) - export -p >$tmpf - printf "%s " "${@@Q}" >>$tmpf - echo >>$tmpf - echo "rm -f $tmpf" >>$tmpf + env-tmpf "$@" m sudo nsenter -t $pid -n sudo -u $USER -i bash -c ". $tmpf" } @@ -4994,7 +4989,6 @@ localai() { } spdfx() { - local spd_file spdx -f ~/.spd/spd/spd_data_financial.gpg "$@" } diff --git a/conflink b/conflink index 0ca21f0..7e038fb 100755 --- a/conflink +++ b/conflink @@ -280,12 +280,14 @@ case $user in m s -H -u user2 "${BASH_SOURCE[0]}" fi + mkdir -p ~/.local + echo 0 >~/.local/conflink + + # impatiently fixup system-status chars. f=/a/bin/distro-setup/system-status if [[ -x $f ]]; then $f _ fi - mkdir -p ~/.local - echo 0 >~/.local/conflink ;; user2) diff --git a/system-status b/system-status index c090a4a..9a294c6 100755 --- a/system-status +++ b/system-status @@ -50,6 +50,13 @@ v() { printf "%s\n" "$*" fi } +append-status-file() { + if $verbose; then + tee -a $status_file + else + >>$status_file + fi +} p() { printf "%s\n" "$*"; } # log-once COUNT NAME [MESSAGE] lo() { @@ -177,8 +184,8 @@ write-status() { p "$snapshotmsg" | loday -1 old-snapshot fi # not bothering to get info on all volumes if we find an old one. - else - echo | loday -1 old-snapshot + else + echo | loday -1 old-snapshot fi fi @@ -447,7 +454,7 @@ write-status() { fi if [[ ${chars[*]} ]]; then - echo "ps_char=\"${chars[*]} \$ps_char\"" >>$status_file + echo "ps_char=\"${chars[*]} \$ps_char\"" | append-status-file fi fi @@ -494,7 +501,6 @@ first_chars=() write-status if [[ $1 ]]; then - cat $status_file exit 0 fi