From: Ian Kelling Date: Mon, 21 Aug 2017 05:09:04 +0000 (-0700) Subject: various important fixes and improvements X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=commitdiff_plain;h=e7708e1261357b00d17f4baffb7051e97f7e8623 various important fixes and improvements --- diff --git a/check-subvol-stale b/check-subvol-stale index b977f76..c6497b5 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -73,7 +73,7 @@ for d; do fi fi - # check if $d is a snapshot of any of the btrbk backups + # check if $d is a snapshot of any of the btrbk backups other than the latest if [[ ! $stale ]]; then for f in ${snaps[@]}; do if [[ $f == $last_snap ]]; then continue; fi @@ -89,7 +89,7 @@ for d; do if [[ ! $stale ]]; then last_snap_gen=$(btrfs sub show $last_snap| awk '$1 == "Generation:" {print $2}') d_gen=$(btrfs sub show $d| awk '$1 == "Generation:" {print $2}') - if (( last_snap_gen < d_gen )); then + if (( d_gen < last_snap_gen )); then stale=false else echo "$d stale: it's generation, $d_gen, is earlier than the last snapshot's, $last_snap_gen" diff --git a/distro-end b/distro-end index 6625799..c13ef34 100755 --- a/distro-end +++ b/distro-end @@ -72,6 +72,7 @@ case $HOSTNAME in beets-doc binutils-doc bind9-doc + bind9-utils bwm-ng chromium cpio-doc @@ -80,6 +81,7 @@ case $HOSTNAME in debconf-doc dirmngr dnsutils + dnsmasq dtrx duplicity eclipse diff --git a/input-setup b/input-setup index 9cff413..6ec672c 100755 --- a/input-setup +++ b/input-setup @@ -15,7 +15,7 @@ set -x # limitations under the License. # set to oppsite if the order is flipped. -k2flip=falsesf- +k2flip=false if $k2flip; then k2inorder=false else diff --git a/mail-route b/mail-route index d130ca9..0368365 100755 --- a/mail-route +++ b/mail-route @@ -34,11 +34,17 @@ case $1 in start) iptables_op=-A ip_op=add + tun_dev=$(ip a show to 10.8.0.4/24 | sed -rn '1s/^\S+\s+([^:]+).*/\1/p') + if [[ $tun_dev != tun* ]]; then + echo "$0: error: failed to find tun device" + exit 1 + fi e() { "$@"; } ;; stop) iptables_op=-D ip_op=del + tun_dev=$(iptables -t nat -S | sed -rn "s/^-A POSTROUTING -o (tun[[:digit:]]+) -m mark --mark 0x1 -j SNAT --to-source 10.8.0.4$/\1/p"|head -n1) || printf "failed to find tun device.\n" e() { "$@" || printf "maybe ok failure: %s\n" "$*"; } ;; show) @@ -66,13 +72,13 @@ for port in 25 143; do # smtp and imap. e iptables -t mangle $iptables_op \ OUTPUT -m tcp -p tcp -m multiport --ports $port -j MARK --set-mark 0x1 e iptables -t mangle $iptables_op \ - OUTPUT -m tcp -p tcp -m multiport --ports $port -j MARK --set-mark 0x0 \ - -d 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 -# note, we could have used a custom chain and returned instead of setting the mark again. + OUTPUT -m tcp -p tcp -m multiport --ports $port -j MARK --set-mark 0x0 \ + -d 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 + # note, we could have used a custom chain and returned instead of setting the mark again. # in case anyone was ever curious, the inverse of private ips is: #0.0.0.0/5,8.0.0.0/7,11.0.0.0/8,12.0.0.0/6,16.0.0.0/4,32.0.0.0/3,64.0.0.0/2,128.0.0.0/3,160.0.0.0/5,168.0.0.0/6,172.0.0.0/12,172.32.0.0/11,172.64.0.0/10,172.128.0.0/9,173.0.0.0/8,174.0.0.0/7,176.0.0.0/4,192.0.0.0/9,192.128.0.0/11,192.160.0.0/13,192.169.0.0/16,192.170.0.0/15,192.172.0.0/14,192.176.0.0/12,192.192.0.0/10,193.0.0.0/8,194.0.0.0/7,196.0.0.0/6,200.0.0.0/5,208.0.0.0/4,224.0.0.0/3 done -e iptables -t nat $iptables_op POSTROUTING -o tun0 -m mark --mark 0x1 -j SNAT --to-source 10.8.0.4 +e iptables -t nat $iptables_op POSTROUTING -o $tun_dev -m mark --mark 0x1 -j SNAT --to-source 10.8.0.4 e ip rule $ip_op fwmark 1 table 1 # note, this rule does not persist when the tun interface is deleted e ip route $ip_op default via 10.8.0.1 table 1 diff --git a/switch-mail-host b/switch-mail-host index 61e8966..40cb817 100755 --- a/switch-mail-host +++ b/switch-mail-host @@ -37,20 +37,27 @@ fi if [[ $new_host == "$HOSTNAME" ]]; then localhost_new=true - ssh_prefix=ssh + new_shell="ssh $new_host" else localhost_new=false - ssh_prefix= + new_shell= fi + +old_shell= +if [[ $old_host == "$HOSTNAME" ]]; then + old_shell="ssh $old_host" +fi + if [[ ! $new_host || ! $old_host ]]; then echo "$0: bad args. see script" exit 1 fi at_home=false -if timeout -s 9 10 ssh root@wrt.lan :; then +if [[ $HOSTNAME == treetowl ]] || [[ $HOSTNAME == frodo ]] || timeout -s 9 5 ssh wrt.lan :; then at_home=true fi +echo "$0: at_home = $at_home" source /a/bin/bash_unpublished/source-semi-priv #### begin convert private hostnames to public hostnames #### @@ -67,18 +74,46 @@ fi # because our port forward is not robust enough, we can't use proxy command, -# todo: just open an ssh port to the world on wrt +# todo: just open an ssh port to the world on wrt.lan if ! $at_home; then - ssh_cmd="ssh $HOME_DOMAIN ssh wrt" + wrt_shell="ssh $HOME_DOMAIN ssh wrt.lan" else - ssh_cmd="ssh wrt" + wrt_shell="ssh wrt.lan" +fi + +btrbk_test="systemctl is-active btrbk.service" +while ! $new_shell $btrbk_test || $old_shell $btrbk_test; do + echo "$0: btrbk is running on new or old host. sleeping for 8 seconds" + sleep 6 + echo "$0: testing for btrbk activity in 2 seconds" + sleep 2 +done + +########### end initial processing, begin actually modifying things ########## + +restore_new_btrbk=false +if $new_shell systemctl is-active btrbk.timer; then + $new_shell sudo systemctl stop btrbk.timer + restore_new_btrbk=true fi +restore_old_btrbk=false +if $old_shell systemctl is-active btrbk.timer; then + $old_shell sudo systemctl stop btrbk.timer + restore_old_btrbk=true +fi + +$new_shell bash -s <<'EOF' +set -eE +if mountpoint /m; then sudo umount /m; fi +if mountpoint /o; then sudo umount /o; fi +EOF + # if new_host is not on home network, make mail.iankelling.org not resolve # on the home network. if [[ $new_host == $HOSTNAME ]] && ! $at_home; then - echo | $ssh_cmd cedit mail_host /etc/hosts + echo | $wrt_shell cedit mail_host /etc/hosts || [[ $? == 1 ]] # 1 means file changed. else - $ssh_cmd bash -s <