X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=conflink;h=61291f2b42b643dfc2f68008032e892de501da64;hb=165008e5b82c81ebff1061c8f8294c3bc6e9dced;hp=aecd0377119a99daf04b7d0e497e65c46f729de0;hpb=36f92d5af79d7934e953515f58af1c86d6838599;p=distro-setup diff --git a/conflink b/conflink index aecd037..61291f2 100755 --- a/conflink +++ b/conflink @@ -1,7 +1,7 @@ #!/bin/bash source /a/bin/errhandle/err -_errcatch_cleanup() { +errcatch-cleanup() { echo 1 >~/.local/conflink } @@ -24,14 +24,21 @@ m() { s() { sudo "$@"; } lnf() { /a/exe/lnf "$@"; } + +fast=false if [[ $1 == -f ]]; then # f for fast - lnf() { ln -sf "$@"; } + fast=true + shift elif [[ $1 ]]; then echo "error: unrecognized arguments" >&2 exit 0 fi +if $fast; then + lnf() { ln -sf "$@"; } +fi + shopt -s nullglob shopt -s extglob shopt -s dotglob @@ -67,19 +74,35 @@ subdir-link-r() { common-file-setup() { - local dir fs x f systemd_reload - systemd_reload=false + local dir fs x f reload_systemd + local -a reload_services + local -a restart_services + reload_systemd=false for dir in "$@"; do fs=$dir/filesystem if [[ -e $fs && $user =~ ^iank?$ ]]; then - # this could be done with rsync, something like this, - # but I haven't looked at the symlinks. - # s rsync -n -ahviSAXPH --specials --devices --chown=root:root --chmod=g-s $fs / - # note, symlinks get resolved, not copied. - if s tar --mode=g-s --owner=0 --group=0 -cz -C $fs . | s tar -dz -C / | grep /etc/systemd &>/dev/null; then - systemd_reload=true - fi - s tar --mode=g-s --owner=0 --group=0 -cz -C $fs . | s tar -xz -C / + while read -r line; do + file="${line:12}" + case $file in + etc/systemd/system/*) + reload_systemd=true + ;; + etc/dnsmasq.d/*) + restart_services+=(dnsmasq) + ;; + esac + # Previously did this with tar, but it doesn't + # update directory permissions. + # + # S = do spare files efficiently + # A = preserve acls + # X = preserve extended attributes + # i = itemize + done < <(s rsync -n -aiSAX --chown=root:root --chmod=g-s \ + --exclude=/etc/dovecot/users \ + --exclude='/etc/exim4/passwd*' \ + --exclude='/etc/exim4/*.pem' \ + $fs/ /) fi if [[ -e $dir/subdir_files ]]; then @@ -89,9 +112,15 @@ common-file-setup() { (( ${#x[@]} >= 1 )) || continue m lnf ${x[@]} ~ done - if $systemd_reload; then + if $reload_systemd; then m s systemctl daemon-reload fi + for service in ${restart_services[@]}; do + if systemctl is-active $service >/dev/null; then + m s systemctl reload $service + fi + done + } user=$(id -un) @@ -154,6 +183,7 @@ case $user in if [[ -x $f ]]; then $f _ fi + mkdir -p ~/.local echo 0 >~/.local/conflink ;; @@ -164,4 +194,3 @@ case $user in echo "$0: error: unexpected user"; exit 1 ;; esac -