From d46190aff6f5dc65bd39524e3937dc5765895b42 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sat, 21 Oct 2017 19:37:58 -0700 Subject: [PATCH] move some stuff to frodo, rename user to iank, fixes --- btrbk-run | 24 +++++---- check-subvol-stale | 19 ++++--- conflink | 6 +-- demohost-mount | 30 ++++------- distro-begin | 28 +++++----- distro-end | 118 +++++++++++++++++++++++-------------------- dynamic-ip-update.sh | 2 +- input-setup | 2 +- keyscript-off | 2 +- keyscript-on | 2 +- mail-setup | 77 ++++++++++++++++------------ mount-latest-subvol | 27 ++++++++-- phabricator-setup | 2 +- 13 files changed, 190 insertions(+), 149 deletions(-) diff --git a/btrbk-run b/btrbk-run index 4713820..d05616a 100755 --- a/btrbk-run +++ b/btrbk-run @@ -30,7 +30,6 @@ script_dir=$(dirname $(readlink -f "$BASH_SOURCE")) # note p/m is owned 1000:1000 and chmod 700 -targets=() mountpoints=() rsync_mountpoint=/q @@ -50,6 +49,7 @@ temp=$(getopt -l help cl:m:nprt:vh "$@") || usage 1 eval set -- "$temp" while true; do case $1 in + # only creates the config file, does not run btrbk -c) conf_only=true; shift ;; -l) rate_limit=$2; shift 2 ;; -m) IFS=, mountpoints=($2); unset IFS; shift 2 ;; @@ -57,6 +57,8 @@ while true; do -p) progress_arg="--progress"; shift ;; # btrbk arg: Resume only. Skips snapshot creation. -r) resume_arg=-r; shift ;; + # empty is valid for just doing local snapshot. we have default hosts + # we will populate -t) IFS=, targets=($2); unset IFS; shift 2 ;; -v) verbose=true; verbose_arg=-v; shift ;; -h|--help) usage ;; @@ -74,7 +76,7 @@ fi echo -e "$0: options: conf_only=$conf_only\ndry_run=$dry_run\nresume_arg=$resume_arg\nrate_limit=$rate_limit\nverbose=$verbose" # set default targets -if ! (( ${#targets[@]} )); then +if [[ ! -v targets ]]; then case $HOSTNAME in x2) if [[ $HOSTNAME == "$MAIL_HOST" ]]; then @@ -89,6 +91,9 @@ if ! (( ${#targets[@]} )); then fi fi ;; + frodo) + targets=() + ;; *) echo "$0: error: no default targets for this host, use -t" exit 1 @@ -108,15 +113,14 @@ if (( ${#mountpoints[@]} )); then fi done else # set default mountpoints - prospective_mps=(/a /q) - if [[ $HOSTNAME == "$MAIL_HOST" ]]; then - prospective_mps+=(/o) - fi - for tg in ${targets[@]}; do - if [[ $tg == frodo && $HOSTNAME == treetowl ]]; then - prospective_mps+=(/i) + if [[ $HOSTNAME == frodo ]]; then + prospective_mps=(/i) + else + prospective_mps=(/a /q) + if [[ $HOSTNAME == "$MAIL_HOST" ]]; then + prospective_mps+=(/o) fi - done + fi for mp in ${prospective_mps[@]}; do # default mountpoints to sync if [[ -e /nocow/btrfs-stale/$mp ]]; then echo "$0: warning: $mp stale, not adding to default mountpoints" diff --git a/check-subvol-stale b/check-subvol-stale index afa711f..bdb4749 100644 --- a/check-subvol-stale +++ b/check-subvol-stale @@ -53,11 +53,14 @@ for d; do vol=${d##*/} dev=$(sed -rn "s,^\s*([^#]\S*)\s+$d\s.*,\1,p" /etc/fstab|head -n1) subvol_dir=$(sed -rn "s,^\s*[^#]\S*\s+$d\s.*\bsubvol=([a-zA-A/]+).*,\1,p" /etc/fstab|head -n1) - root_dir=$(sed -rn "s,^\s*$dev\s+(\S+).*\bsubvolid=0\b.*,\1,p" /etc/fstab|head -n1) + # note, we need $dev because $d might not be mounted, and we do this loop + # because the device in fstab for the rootfs can be different. + for devx in $(btrfs fi show $dev| sed -rn 's#.*path (/\S+)$#\1#p'); do + root_dir=$(sed -rn "s,^\s*$devx\s+(\S+).*\bsubvolid=0\b.*,\1,p" /etc/fstab|head -n1) + if [[ $root_dir ]]; then break; fi + done svp=$root_dir/$subvol_dir # subvolume path - - snaps=($root_dir/btrbk/$subvol_dir.20*) # Assumes we are in the 21st century. if [[ ! $snaps ]]; then # no snapshots yet @@ -84,7 +87,8 @@ for d; do last_snap=$( for s in ${snaps[@]}; do f=${s##*/} - printf "%s %s\n" $(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s) $f + unix_time=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s) + printf "%s %s\n" $unix_time $s done | sort -r | head -n 1 | awk '{print $2}' ) if [[ ! $last_snap ]]; then @@ -95,8 +99,10 @@ for d; do fi if [[ ! -e $svp ]]; then - echo "$0: warning: subvol we want to check does not exist: $svp" - stale-file=$last_snap + echo "$0: warning: subvol does not exist: $svp" + echo "$0 assuming this host was just for receiving and latest snap is freshest" + freshest_snap=$last_snap + stale=true stale-file continue fi @@ -116,6 +122,7 @@ for d; do continue fi + # fallback to using last_snap as the freshest freshest_snap=$last_snap stale=true # fresh if $svp has $last_snap as a snapshot, diff --git a/conflink b/conflink index 7a597e3..139096f 100755 --- a/conflink +++ b/conflink @@ -49,9 +49,9 @@ common-file-setup() { local dir fs x bdir f dst for dir in "$@"; do fs=$dir/filesystem - if [[ -e $fs && $USER == ian ]]; then + if [[ -e $fs && $USER =~ ^iank?$ ]]; then # note, symlinks get resolved, not copied. - m s cp -RLT --preserve=mode,timestamps $fs / + s tar --mode=g-s --owner=0 --group=0 -cz -C $fs . | s tar -xz -C / fi if [[ -e $dir/subdir_files ]]; then @@ -72,7 +72,7 @@ done c_dirs=(/a/c{,/machine_specific/$HOSTNAME}) case $USER in - ian) + ian|iank) # p needs to go first so .ssh link is created, then config link inside it m common-file-setup ${all_dirs[@]} if [[ -d /etc/bind/bind-writable ]]; then diff --git a/demohost-mount b/demohost-mount index 416ab2e..6445187 100755 --- a/demohost-mount +++ b/demohost-mount @@ -5,36 +5,28 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" -virsh destroy demohost ||: -# there's some other ways to configure it, but by default, we get perms of this user -usermod -a -G ian libvirt-qemu -usermod -a -G traci libvirt-qemu -virsh attach-device demohost <(e " ") --config ||: -virsh attach-device demohost <(e " ") --config ||: - -virsh start demohost -while ! timeout -s 9 5 ssh demohost :; do sleep 3; done +ip=$(host demohost | sed -rn 's/^\S+ has address //p;T;q')/32 +cedit demohost /etc/exports <>/etc/modules <>/etc/fstab <<'EOF' -/a /a 9p trans=virtio 0 0 -/q /q 9p trans=virtio 0 0 +faiserver:/a /a nfs defaults 0 0 +faiserver:/q /q nfs defaults 0 0 /q/p /p none bind 0 0 EOF + mkdir -p /a /q /p mount /a mount /q diff --git a/distro-begin b/distro-begin index dde7c8e..214c33f 100755 --- a/distro-begin +++ b/distro-begin @@ -30,7 +30,7 @@ sudo bash -c 'source /a/c/.bashrc && source /a/exe/ssh-emacs-setup' # set the scrollback to unlimited in case something goes wrong if [[ $EUID == 0 ]]; then - if getent passwd ian; then + if getent passwd iank || getent passwd ian ; then echo "$0: error: running as root. unprivileged user exists. use it." exit 1 else @@ -167,7 +167,7 @@ fi distro=$(distro-name) case $distro in ubuntu|debian|trisquel) - sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/GRUB_PC/11-ian" + sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/GRUB_PC/11-iank" ;; *) sudo bash -c ". /a/bin/fai/fai-wrapper && @@ -207,8 +207,8 @@ $interactive || set -x # passwordless sudo -tu /etc/sudoers <<'EOF' -ian ALL=(ALL) NOPASSWD: ALL +tu /etc/sudoers < /dev/null; then ;; esac fi -if [[ $HOSTNAME == treetowl ]]; then +if [[ $HOSTNAME == frodo ]]; then sgo transmission-daemon-nn fi @@ -1123,7 +1125,7 @@ case $distro in # others unknown esac # allow user to run vms, from debian handbook -for x in ian traci; do s usermod -a -G libvirt,kvm $x; done +for x in iank traci; do s usermod -a -G libvirt,kvm $x; done # bridge networking as user fails. google lead here, but it doesn\'t work: # oh well, I give up. # http://wiki.qemu.org/Features-Done/HelperNetworking @@ -1253,19 +1255,11 @@ if [[ $HOSTNAME == treetowl ]]; then f=$dir/bitcoin.conf s dd of=$f </dev/null </dev/null <$f </dev/null; then + apt-get -y install --purge --auto-remove openvpn + fi + if [[ -e /p/c/filesystem ]]; then /a/exe/vpn-mk-client-cert -b mail -n mail li fi - cat >/etc/systemd/system/mailroute.service <<'EOF' + cat >/etc/systemd/system/mailroute.service </etc/systemd/system/offlineimapsync.timer <<'EOF' @@ -295,13 +310,13 @@ OnCalendar=*:0/5 WantedBy=timers.target EOF - cat >/etc/systemd/system/offlineimapsync.service <<'EOF' + cat >/etc/systemd/system/offlineimapsync.service <$exim_main_dir/000_localmacros <<'EOF' + cat >$exim_main_dir/000_localmacros </dev/null ||: systemctl stop offlineimapsync.timer &>/dev/null ||: - systemctl disable openvpn-client@mail - systemctl stop openvpn-client@mail + systemctl disable $vpn_ser@mail + systemctl stop $vpn_ser@mail systemctl disable dovecot ||: systemctl stop dovecot ||: # @@ -802,21 +817,21 @@ EOF sed -r s/^\\S+:/$b:/ 600_exim4-config_userforward >175_$b systemctl restart exim4 -fi # end if exim4 + fi # end if exim4 -# /etc/alias setup is debian specific, and -# exim config sets up an /etc/alias from root to the postmaster, which i -# config to ian, as long as there exists an entry for root, or there was -# no preexisting aliases file. based on the postinst file. postfix -# won't set up a root to $postmaster alias if it's already installed. -# Since postfix is not the greatest, just set it ourselves. -if [[ $postmaster != root ]]; then - sed -i --follow-symlinks -f - /etc/aliases </dev/null; then continue @@ -141,11 +146,23 @@ for vol in q a o; do if e umount -R $dir; then unmounted+=($dir) else - umount_ret=false - ret=1 echo "$0: failed to umount $dir" - e lsof $dir - break + # lsof will fail if it finds no pids + if ! e lsof $dir; then + umount_ret=false + ret=1 + continue + fi + pids=$(lsof -t $dir) ||: + kill $pids + sleep .5 + if e umount -R $dir; then + unmounted+=($dir) + else + umount_ret=false + ret=1 + continue + fi fi fi done diff --git a/phabricator-setup b/phabricator-setup index 2265591..ebd9360 100755 --- a/phabricator-setup +++ b/phabricator-setup @@ -302,7 +302,7 @@ sudo systemctl daemon-reload # arcanist(), phabricator(), phutil() s usermod -a -G vcs www-data -s usermod -a -G vcs ian +s usermod -a -G vcs iank s usermod -a -G vcs phabricator s chown root:vcs /usr/share/phabricator/conf/local/local.json fbin config set diffusion.ssh-port $ssh_port -- 2.30.2