From 7828c7fd662aca1327c45854614237ca9a942a00 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sun, 15 Jan 2017 07:31:33 -0800 Subject: [PATCH] various fixes, add emacs wrappers --- btrbk-run | 22 +++++++----- distro-begin | 36 ++++++++++++------- distro-end | 97 +++++++++++++++++++++++++++++++++++++++++++++------- g | 22 ++++++++++++ g2 | 4 +++ mail-setup | 14 +++++--- rootsshsync | 15 ++++---- 7 files changed, 166 insertions(+), 44 deletions(-) create mode 100755 g create mode 100644 g2 diff --git a/btrbk-run b/btrbk-run index 485c7f5..961208e 100755 --- a/btrbk-run +++ b/btrbk-run @@ -32,15 +32,16 @@ conf_only=false dry_run=false # mostly for testing resume_arg= -temp=$(getopt -l help hcnrt: "$@") || usage 1 +temp=$(getopt -l help hcnprt: "$@") || usage 1 eval set -- "$temp" while true; do case $1 in -c) conf_only=true; shift ;; -n) dry_run=true; dry_run_arg=-n; shift ;; + -p) progress_arg="--progress"; shift ;; # btrbk arg: Resume only. Skips snapshot creation. -r) resume_arg=-r; shift ;; - -t) IFS=, targets=($2); shift 2 ;; + -t) IFS=, targets=($2); unset IFS; shift 2 ;; -h|--help) usage ;; --) shift; break ;; *) echo "$0: Internal error!" ; exit 1 ;; @@ -71,17 +72,13 @@ tg-conf() { target send-receive ssh://$tg$vol/btrbk EOF } -m() { printf "%s\n" "$*"; "$@"; } +m() { printf "%s: %s\n" "${0##*/}" "$*"; "$@"; } if ! which btrbk &>/dev/null; then echo "$0: error: no btrbk binary found" fi -if [[ $- == *i* ]]; then - progress_arg=--progress -fi - cat >/etc/btrbk.conf <<'EOF' ssh_identity /root/.ssh/id_rsa # Just a guess that local7 is a good facility to pick. @@ -135,8 +132,17 @@ if [[ ! $targets ]]; then targets=($HOME_DOMAIN) fi ;; + treetowl) + targets=(frodo) + if timeout -s 9 10 ssh x2 :; then + targets+=(x2) + fi + ;; + *) + targets=(frodo) + ;; esac - targets=(frodo) + echo "targets: ${targets[*]}" fi diff --git a/distro-begin b/distro-begin index a765491..bbd94f2 100755 --- a/distro-begin +++ b/distro-begin @@ -567,7 +567,7 @@ EOF fi fi -s mkdir -p /q/i/{w,k} +s mkdir -p /q /i/{w,k} for dir in /{i,w,k}; do if mountpoint $dir; then continue; fi # already mounted s mkdir -p $dir @@ -583,16 +583,21 @@ s mkdir -p /mnt/iroot # then waits endlessly for them on bootup, after the /dev/mapper disks # have already been created and exist. todo: create a simple repro # for this in a vm and report it upstream. +pi nfs-common s dd of=/root/imount <<'EOF' #!/bin/bash [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR for dir in /i /mnt/iroot /w /k /kr; do - if ! mountpoint $dir &>/dev/null && \ - awk '{print $2}' /etc/fstab | grep -xFq $dir; then - mount $dir - fi + if ! mountpoint $dir &>/dev/null && \ + awk '{print $2}' /etc/fstab | grep -xF $dir &>/dev/null; then + if awk '{print $3}' /etc/fstab | grep -xF nfs &>/dev/null; then + mount $dir || echo "warning: failed to mount nfs on $dir" + else + mount $dir + fi + fi done EOF s chmod +x /root/imount @@ -714,28 +719,33 @@ EOF if isdeb; then - # I've had problems with postfix on debian: + # I\'ve had problems with postfix on debian: # on stretch, a startup ordering issue caused all mail to fail. # postfix changed defaults to only use ipv6 dns, causing all my mail to fail. # exim4 is default on debian, so I assume it would # be packaged better to avoid these types of things. - # I haven't gotten around to getting a non-debian exim + # I haven\'t gotten around to getting a non-debian exim # setup. mail-setup exim4 - else - mail-setup postfix +else + mail-setup postfix fi - if isubuntu; then - # disable crash report annoying crap - s dd of=/etc/default/apport <<<'enabled=0' - fi +if isubuntu; then + # disable crash report annoying crap + s dd of=/etc/default/apport <<<'enabled=0' +fi # fai sets this an old way that doesn't work for stretch. # no harm in setting it universally here. # using debconf-set-selection, the area gets reset to ETC # on my linode test machine after doing a dpkg-reconfigure, or a reinstall, # so we are using expect :( +# I got a random error when running this, so I added a sleep +# rather than trying to write a whole detect and wait loop. +# E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) +# E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it? +sleep 1 s apt-get -y install --no-install-recommends expect s expect < '/k/partial-torrents', 'incomplete-dir-enabled' => true, 'download-dir' => '/i/k/torrents', -"speed-limit-up" => 700, +"speed-limit-up" => 800, "speed-limit-up-enabled" => true, "peer-port" => 61486, +"cache-size-mb" => 128, "ratio-limit" => 1.4000, "ratio-limit-enabled" => false, "pidfile": "/var/lib/transmission-daemon/transmission-daemon.pid", @@ -678,16 +692,29 @@ case $distro in # has no unstable dependencies spa bitcoin-qt/unstable fi - ;; - s cp /a/opt/bitcoin/contrib/init/bitcoind.service /usr/lib/systemd/system - ser daemon-reload - sgo bitcoind - - s mkdir -p $dir - s touch $f - s chmod -R o-rwx $dir - s chown -R bitcoin:bitcoin $dir - s dd of=$f < ~/.forward e $forward | s tee /root/.forward +# exim log complains about 664 permissions. +s chmod 644 ~/.forward /root/.forward # offlineimap uses this too, it is much easier to use one location than to @@ -82,7 +84,7 @@ case $distro in *) : esac -read -r domain pass < <(s cat /etc/mailpass) +read -r domain pass < <(s cat /etc/mailpass) # format: domain user:pass if postfix; then # dunno why, but debian installed postfix with builddep emacs # but I will just explicitly install it here since @@ -131,7 +133,7 @@ EOF f=/etc/postfix/sasl_passwd s touch $f s chmod 600 $f - echo "[$domain]:587 ${pass/@/#}" | s dd of=/etc/postfix/sasl_passwd >/dev/null + printf "[%s]:587 %s" "$domain" "${pass/@/#}" | s dd of=/etc/postfix/sasl_passwd 2>/dev/null s postmap hash:/etc/postfix/sasl_passwd s service postfix reload else @@ -159,7 +161,9 @@ EOF f=/etc/exim4/passwd.client s touch $f s chmod 640 $f # before writing sensitive info - echo "$domain:${pass/:/::}" | s dd of=$f >/dev/null + s chown root:Debian-exim $f + # reference: exim4_passwd_client(5) + printf "%s:%s" "$domain" "$pass" | s dd of=$f 2>/dev/null # https://blog.dhampir.no/content/make-exim4-on-debian-respect-forward-and-etcaliases-when-using-a-smarthost # i only need .forwards, so just doing that one. cd /etc/exim4/conf.d/router @@ -168,8 +172,8 @@ EOF tmp=$(mktemp) of=175_$b # sed to make the router name unique - sed -r s/^\\S+:/$b:/ 600_exim4-config_$a >$tmp - if diff -q >/dev/null $tmp $of; then + sed -r s/^\\S+:/$b:/ 600_exim4-config_$a | s dd of=$tmp 2>/dev/null + if ! diff -q >/dev/null $tmp $of; then s dd if=$tmp of=$of >/dev/null ser restart exim4 fi diff --git a/rootsshsync b/rootsshsync index aef668a..592a5aa 100755 --- a/rootsshsync +++ b/rootsshsync @@ -1,4 +1,4 @@ -#!/bin/bash -l +#!/bin/bash # Copyright (C) 2016 Ian Kelling # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -if s test -e /q/root/.ssh; then - s lnf /q/root/.ssh /root +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +if sudo test -e /q/root/.ssh; then + sudo /a/exe/lnf /q/root/.ssh /root else - mkdir /root/.ssh + sudo mkdir /root/.ssh fi -s cp -rL $(eval echo ~${SUDO_USER:-$USER})/.ssh/* /root/.ssh -s chown -R root:root /root/.ssh +sudo cp -rL $(eval echo ~${SUDO_USER:-$USER})/.ssh/* /root/.ssh +sudo chown -R root:root /root/.ssh -- 2.30.2