From e33ce1523480d37fe973c46f7c366e9cc730edd9 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Mon, 30 Sep 2024 19:24:13 -0400 Subject: [PATCH] misc improvements --- brc | 5 +- conflink | 143 +++++++++++++++++----------------- filesystem/usr/local/bin/prof | 3 +- system-status | 2 +- 4 files changed, 79 insertions(+), 74 deletions(-) diff --git a/brc b/brc index 8ee018f..6a6565a 100644 --- a/brc +++ b/brc @@ -2565,7 +2565,10 @@ bn() { # shellcheck disable=SC2120 r() { if [[ $HISTFILE ]]; then - history -a # save history + # save history + if ! history -a; then + r: warning: failed command: history -a + fi fi trap ERR # this avoids a segfault exit ${1:0} diff --git a/conflink b/conflink index 0f02b04..3714d9c 100755 --- a/conflink +++ b/conflink @@ -20,12 +20,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +this_file="$(readlink -f -- "${BASH_SOURCE[0]}")" +readonly this_file this_dir="${this_file%/*}" +[[ $EUID == 0 ]] || exec sudo -E "$this_file" "$@" source /a/bin/bash-bear-trap/bash-bear err-cleanup() { - echo 1 >~/.local/conflink + echo 1 >/var/local/conflink } +shopt -s nullglob +shopt -s extglob +shopt -s dotglob + usage() { cat <&2; exit 1; } - -fast=false -verbose=false -temp=$(getopt -l help hvf "$@") || usage 1 -eval set -- "$temp" -while true; do - case $1 in - -v) verbose=true ;; - -f) fast=true ;; - -h|--help) usage ;; - --) shift; break ;; - *) echo "$0: unexpected args: $*" >&2 ; usage 1 ;; - esac - shift -done -readonly fast verbose - -##### end command line parsing ######## +lnf() { sudo -u $user /a/exe/lnf "$@"; } -tmpf=$(mktemp) -if $fast; then - lnf() { ln -sf "$@"; } -fi - -if $verbose; then - m() { - echo "$*" - "$@" - } -fi - -shopt -s nullglob -shopt -s extglob -shopt -s dotglob - # If we make a link back to the root, we stop going deeper into subdir_files. # This makes it so we can do subdir directories. eg # /p/c/subdir_files/.config/gajim -> ../../gagim @@ -115,7 +79,7 @@ subdir-link-r() { local fullpath fullpath="$(readlink -f "$path")" if [[ -f $path || $(dirname "$fullpath") == "$below" ]]; then - lnf -T "$path" "$HOME/${path#"$root/"}" + lnf -T "$path" "/home/$user/${path#"$root/"}" elif [[ -d "$path" ]]; then subdir-link-r "$root" "$path" fi @@ -136,9 +100,8 @@ common-file-setup() { fi link_glob=( $dir/!(binds|subdir_files|filesystem|machine_specific|..|.|.#*) ) (( ${#link_glob[@]} >= 1 )) || continue - lnf ${link_glob[@]} ~ + lnf ${link_glob[@]} /home/$user done - } old-files-cleanup() { @@ -148,13 +111,13 @@ old-files-cleanup() { if [[ -e $f ]]; then v systemctl stop $t.timer v systemctl disable $t.timer - s rm -fv $f + rm -fv $f reload_systemd=true fi done # old 2022-04 if [[ -e /etc/cron.daily/check-lets-encrypt-ssl-settings ]]; then - s rm -f /etc/cron.daily/check-lets-encrypt-ssl-settings + rm -f /etc/cron.daily/check-lets-encrypt-ssl-settings fi # conversion from whole folder subdir to individual files. if [[ -L /home/iank/.config/copyq ]]; then @@ -172,14 +135,52 @@ find-maybe() { fi done if (( ${#paths[@]} >= 1 )); then - s find "${paths[@]}" "$@" + find "${paths[@]}" "$@" fi } #### end function definitions, begin main script #### +##### begin command line parsing ######## + +# ensure we can handle args with spaces or empty. +ret=0; getopt -T || ret=$? +[[ $ret == 4 ]] || { echo "Install util-linux for enhanced getopt" >&2; exit 1; } + +fast=false +verbose=false +temp=$(getopt -l help hvf "$@") || usage 1 +eval set -- "$temp" +while true; do + case $1 in + -v) verbose=true ;; + -f) fast=true ;; + -h|--help) usage ;; + --) shift; break ;; + *) echo "$0: unexpected args: $*" >&2 ; usage 1 ;; + esac + shift +done +readonly fast verbose + +##### end command line parsing ######## + +tmpf=$(mktemp) +if $fast; then + lnf() { sudo -u $user ln -sf "$@"; } +fi + +if $verbose; then + m() { + echo "$*" + "$@" + } +fi + +# todo: if we start using user2, make this get set +# by SUDO_USER or command line arg +user=iank -user=$(id -un) all_dirs=({/a/bin/ds,/p/c}{,/machine_specific/$HOSTNAME}) # note, we assume a group of hosts does not have the # same name as a single host, which is no problem on our scale. @@ -234,7 +235,7 @@ case $user in fi done - cmd=( s rsync -rclgoDiSAX --chown=root:root + cmd=( rsync -rclgoDiSAX --chown=root:root --exclude=/etc/dovecot/users --exclude='/etc/exim4/passwd*' --exclude='/etc/exim4/*.pem' @@ -249,7 +250,7 @@ case $user in case $HOSTNAME in kd) if systemctl is-active prometheus &>/dev/null; then - v s systemctl reload prometheus + v systemctl reload prometheus fi ;; esac @@ -274,32 +275,32 @@ case $user in done <$tmpf if $reload_systemd; then - v s systemctl daemon-reload + v systemctl daemon-reload fi for service in ${!restart_services[@]}; do if systemctl is-active $service >/dev/null; then - v s systemctl restart $service + v systemctl restart $service fi done #### begin special extra stuff #### - install -d -m700 ~/gpg-agent-socket + install -d -oiank -giank -m700 /home/iank/gpg-agent-socket if [[ -e /p/c/user-specific/prometheus ]]; then if getent passwd prometheus &>/dev/null; then - v s rsync -clpgoDiSAX --chmod=g+r --chown=root:prometheus /p/c/user-specific/prometheus/prometheus-pass /etc - v s rsync -clpgoDiSAX --chmod=g+r --chown=root:prometheus /p/c/user-specific/prometheus/prometheus/ssl/* /etc/prometheus/ssl + v rsync -clpgoDiSAX --chmod=g+r --chown=root:prometheus /p/c/user-specific/prometheus/prometheus-pass /etc + v rsync -clpgoDiSAX --chmod=g+r --chown=root:prometheus /p/c/user-specific/prometheus/prometheus/ssl/* /etc/prometheus/ssl fi fi if [[ -e /p/c/user-specific/www-data ]]; then if getent passwd www-data &>/dev/null; then - v s rsync -clpgoDiSAX --chmod=g+r --chown=root:www-data /p/c/user-specific/www-data/* /etc + v rsync -clpgoDiSAX --chmod=g+r --chown=root:www-data /p/c/user-specific/www-data/* /etc fi fi if [[ -e /p/c/user-specific/znc ]]; then if getent group znc &>/dev/null; then - v s rsync -rclpgoDiSAX --chown=znc:znc /p/c/user-specific/znc/ /var/lib/znc + v rsync -rclpgoDiSAX --chown=znc:znc /p/c/user-specific/znc/ /var/lib/znc fi fi @@ -310,14 +311,14 @@ case $user in # "var/lib/bind/dsset-*" if [[ -e /p/c/user-specific/bind ]]; then if getent group bind &>/dev/null; then - v s rsync -clpgoDiSAX --chmod=g+r --chown=root:bind /p/c/user-specific/bind/etc/bind/* /etc/bind - v s rsync -clpgoDiSAX --chmod=g+r --chown=root:bind /p/c/user-specific/bind/var/lib/bind/* /var/lib/bind + v rsync -clpgoDiSAX --chmod=g+r --chown=root:bind /p/c/user-specific/bind/etc/bind/* /etc/bind + v rsync -clpgoDiSAX --chmod=g+r --chown=root:bind /p/c/user-specific/bind/var/lib/bind/* /var/lib/bind fi fi # this folder strangely requires ownership as icecast2 (and icecast2 group is icecast without the 2). if [[ -d /etc/icecast2 && -e /p/c/user-specific/icecast ]]; then - v s rsync -clgoDiSAX --chmod=g+r --chown=root:icecast /p/c/user-specific/icecast2/icecast.xml /etc/icecast2 + v rsync -clgoDiSAX --chmod=g+r --chown=root:icecast /p/c/user-specific/icecast2/icecast.xml /etc/icecast2 fi # disabled @@ -327,17 +328,19 @@ case $user in # fi ##### end special extra stuff ##### - if ! $fast; then - s -H -u user2 "${BASH_SOURCE[0]}" - fi + ## disabled, not using user2 for anything atm. + ## to enable this, we would need to create + ## a command line flag to set the target user. + # if ! $fast; then + # sudo -H -u user2 "${BASH_SOURCE[0]}" + # fi - mkdir -p ~/.local - echo 0 >~/.local/conflink + echo 0 >/var/local/conflink # impatiently fixup system-status chars. f=/a/bin/distro-setup/system-status if [[ -x $f ]]; then - $f _ + sudo -u iank $f _ fi ;; diff --git a/filesystem/usr/local/bin/prof b/filesystem/usr/local/bin/prof index 9ca3047..2a1c7ab 100755 --- a/filesystem/usr/local/bin/prof +++ b/filesystem/usr/local/bin/prof @@ -23,8 +23,7 @@ set -e; . /usr/local/lib/bash-bear; set +e -# get $d_host, note that is not consistently used everywhere. -source /a/bin/bash_unpublished/source-state +source /p/c/domain-info dossh=true if (( $# >= 1 )); then remote=$1 diff --git a/system-status b/system-status index d525a8b..d116534 100755 --- a/system-status +++ b/system-status @@ -353,7 +353,7 @@ write-status() { chars+=(DE) else source /a/bin/ds/script-files - f=~/.local/conflink + f=/var/local/conflink # shellcheck disable=SC2043 for _ in 1; do if [[ -e $f ]]; then -- 2.30.2