From 7f759d320592e791a62cd0a966350e8c53ee0976 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Tue, 12 Nov 2019 12:55:15 -0500 Subject: [PATCH] various fixes, mostly for etiona --- brc | 8 ++-- brc2 | 10 +++-- btrbk-run | 4 +- conflink | 4 +- desktop-20-autostart.sh | 38 +++++++++-------- distro-begin | 41 ++++++------------- distro-end | 38 +++++++++++------ distro-pkgs | 6 --- .../system/fsf-vpn-dns-cleanup.service | 3 +- mail-route | 2 +- mail-setup | 22 +++++++--- pkgs | 1 - sl/.iank/package-manager-abstractions | 1 + switch-mail-host | 21 ++++++---- 14 files changed, 105 insertions(+), 94 deletions(-) create mode 120000 sl/.iank/package-manager-abstractions diff --git a/brc b/brc index b5d4596..51a04dc 100644 --- a/brc +++ b/brc @@ -317,7 +317,7 @@ cam() { ccat () { # config cat. see a config without extra lines. - grep '^\s*[^;[:space:]#]' "$@" + grep '^\s*[^;[:space:]#]' "$@" || [[ $? == 1 ]] } @@ -768,11 +768,11 @@ lower() { # make first letter of filenames lowercase. k() { # history search - grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | tail -n 80; + grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | tail -n 80 || [[ $? == 1 ]]; } ks() { # history search - grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | uniq; + grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | uniq || [[ $? == 1 ]]; } @@ -812,7 +812,7 @@ pkx() { # package extract c $(mktemp -d) pkg=$1 # shellcheck disable=SC2012 - cached=$(ls -t /var/cache/apt/archives/$pkg* | tail -n1 2>/dev/null) + cached=$(ls -t /var/cache/apt/archives/$pkg* | tail -n1 2>/dev/null) ||: if [[ $cached ]]; then cp $cached . else diff --git a/brc2 b/brc2 index 891e095..56f4db6 100644 --- a/brc2 +++ b/brc2 @@ -141,18 +141,20 @@ bigclock() { } _jrun() { # journal run. run args, log to journal, tail and grep the journal. + # Redirect all commands which might have stderr to stdout because of + # wrapping. local pid pattern jr_pid sedscript cmd_name ended ret=0 case $1 in -p) - pattern="$2\|" + pattern="$2|" shift 2 ;; esac cmd_name=${1##*/} systemd-cat -t "$cmd_name" "$@" 2>&1 & pid=$! - sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[$pid]: ([^ ]+ +)?exiting with status [0-9]+\$/q" + sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[$pid]: $cmd_name: exiting with status [0-9]+\$/q" journalctl -S "4 seconds ago" -f |& sed -nr "$sedscript" 2>&1 & jr_pid=$! wait $pid 2>&1 || ret=$? @@ -355,6 +357,8 @@ envload() { # load environment from a previous: export > file done < "$file" } +failfunc() { asdf a b c; } +failfunc2() { failfunc d e f; } # one that comes with distros is too old for newer devices fastboot() { @@ -809,7 +813,7 @@ resolvcat() { #hr; echo dnsmasq is $(systemctl is-active dnsmasq) f=/var/run/dnsmasq/resolv.conf hr; echo $f:; ccat $f - hr; m grr '^ *servers-file *=' /etc/dnsmasq.conf /etc/dnsmasq.d + hr; m grr '^ *(servers-file|server) *=|^ *no-resolv *$' /etc/dnsmasq.conf /etc/dnsmasq.d f=/etc/dnsmasq-servers.conf hr; echo $f:; ccat $f } diff --git a/btrbk-run b/btrbk-run index 60f065d..3a2d2a4 100644 --- a/btrbk-run +++ b/btrbk-run @@ -46,7 +46,7 @@ pre="${0##*/}: " m() { if $verbose; then printf "$pre%s\n" "$*"; fi; "$@"; } e() { printf "$pre%s\n" "$*"; } die() { printf "$pre%s\n" "$*" >&2; echo "exiting with status 1" >&2; exit 1; } -mexit() { echo "exiting with status $1"; exit $1; } +mexit() { echo "$pre: exiting with status $1"; exit $1; } # latest $MAIL_HOST if [[ -e /b/bash_unpublished/source-state ]]; then @@ -59,6 +59,7 @@ mountpoints=() rsync_mountpoint=/q +ret=0 # default options conf_only=false dry_run=false # mostly for testing @@ -445,7 +446,6 @@ else m /a/exe/mount-latest-remote ${targets[@]} fi -e btrbk-run COMPLETED with exit status $ret mexit $ret # todo: move variable data we don't care about backing up diff --git a/conflink b/conflink index 61291f2..8deae09 100755 --- a/conflink +++ b/conflink @@ -1,7 +1,7 @@ #!/bin/bash source /a/bin/errhandle/err -errcatch-cleanup() { +err-cleanup() { echo 1 >~/.local/conflink } @@ -98,7 +98,7 @@ common-file-setup() { # A = preserve acls # X = preserve extended attributes # i = itemize - done < <(s rsync -n -aiSAX --chown=root:root --chmod=g-s \ + done < <(s rsync -aiSAX --chown=root:root --chmod=g-s \ --exclude=/etc/dovecot/users \ --exclude='/etc/exim4/passwd*' \ --exclude='/etc/exim4/*.pem' \ diff --git a/desktop-20-autostart.sh b/desktop-20-autostart.sh index ed83642..69f455f 100755 --- a/desktop-20-autostart.sh +++ b/desktop-20-autostart.sh @@ -14,40 +14,42 @@ # limitations under the License. # first 2 alternatives showed under ubuntu 14.04, second 2 under arch at 11/2015 -if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi if [[ $1 ]]; then - right_monitor_rotation=left + right_monitor_rotation=left else - right_monitor_rotation=normal + right_monitor_rotation=normal fi -xout="$(xrandr)" +if ! xout="$(xrandr)"; then + # under wayland + exit 0 +fi xe() { echo "$xout"; } x=$(xe | grep -Ec '^(DisplayPort-[0123]|DVI-0|DP-[1234]|DVI-I-1) connected') if (( x > 2 )); then - left=$(xe | sed -rn 's/^(DVI[^ ]+) connected .*/\1/p') - dps=( $(xe | sed -rn 's/^(DP-[01234]|DisplayPort-[01234]) connected .*/\1/p') ) + left=$(xe | sed -rn 's/^(DVI[^ ]+) connected .*/\1/p') + dps=( $(xe | sed -rn 's/^(DP-[01234]|DisplayPort-[01234]) connected .*/\1/p') ) - middle=${dps[1]} - right=${dps[0]} - # on older distros, i needed to swap middle and right. + middle=${dps[1]} + right=${dps[0]} + # on older distros, i needed to swap middle and right. - xrandr --output $left --mode 2560x1600 --pos 0x0 --rotate left \ - --output $middle --mode 2560x1600 --pos 1600x0 --rotate left \ - --output $right --mode 2560x1600 --pos 3200x0 --rotate $right_monitor_rotation + xrandr --output $left --mode 2560x1600 --pos 0x0 --rotate left \ + --output $middle --mode 2560x1600 --pos 1600x0 --rotate left \ + --output $right --mode 2560x1600 --pos 3200x0 --rotate $right_monitor_rotation elif (( x == 2 )); then - # 3rd monitor not working atm, so doing this. - left=$(xe | sed -rn 's/^(DVI[^ ]+) connected .*/\1/p') - middle=$(xe | sed -rn 's/^(DP-[01234]|DisplayPort-[01234]) connected .*/\1/p') - xrandr --output $left --mode 2560x1600 --pos 0x0 --rotate left \ - --output $middle --mode 2560x1600 --pos 1600x0 --rotate left + # 3rd monitor not working atm, so doing this. + left=$(xe | sed -rn 's/^(DVI[^ ]+) connected .*/\1/p') + middle=$(xe | sed -rn 's/^(DP-[01234]|DisplayPort-[01234]) connected .*/\1/p') + xrandr --output $left --mode 2560x1600 --pos 0x0 --rotate left \ + --output $middle --mode 2560x1600 --pos 1600x0 --rotate left fi /a/bin/distro-setup/input-setup m if isarch; then - pulseaudio --start + pulseaudio --start fi #indicator-kdeconnect diff --git a/distro-begin b/distro-begin index 22fff60..72d4d44 100755 --- a/distro-begin +++ b/distro-begin @@ -55,14 +55,13 @@ if ! $interactive; then fi source /a/bin/errhandle/err -errcatch-cleanup() { +err-cleanup() { echo 1 >~/.local/distro-begin } source /a/bin/distro-functions/src/package-manager-abstractions ### setup logging -exec &> >(sudo tee -a /var/log/distro-begin) echo "$0: $(date): starting now)" @@ -326,9 +325,9 @@ pi ${p1[@]} ######## fix evbug bug ###### -case $distro in - trisquel|ubuntu) - # noticed in flidas. +case $(debian-codename-compat) in + xenial) + # noticed in flidas. dunno if it affects any others #https://bugs.launchpad.net/ubuntu/+source/module-init-tools/+bug/240553 #https://wiki.debian.org/KernelModuleBlacklisting #common advice when searching is to use /etc/modprobe.d/blacklist.conf, @@ -353,7 +352,7 @@ if has_p; then lnf -T /p/News ~/News fi sudo /a/exe/lnf /q/root/.editor-backups /q/root/.undo-tree-history \ - /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root + /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root /a/bin/ds/install-my-scripts # needed for rootsshsync cronjob sudo /a/exe/lnf /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root @@ -544,31 +543,16 @@ if has_x; then esac ##### setup X autostart - if isarch; then - # https://wiki.archlinux.org/index.php/Xinitrc - for homedir in /home/*; do - cp /etc/X11/xinit/xinitrc $homedir/.xinitrc - # shellcheck disable=SC2016 - $sed -ri '/^ *twm\b/,$d' $homedir/.xinitrc - tee -a $homedir/.xinitrc <<'EOF' -/a/bin/desktop-20-autostart.sh -xsetroot -cursor_name left_ptr -exec xmonad -EOF - done - else - # todo, figure this out for arch if we ever try out gnome. - # install for multiple display managers in case we use one - dir=/etc/gdm3 - sudo mkdir -p $dir/PostLogin - sudo cp /a/bin/distro-setup/desktop-20-autostart.sh $dir/PostLogin/Default - sudo mkdir -p /etc/lightdm/lightdm.conf.d - sudo dd of=/etc/lightdm/lightdm.conf.d/12-iank.conf <<'EOF' + # todo, figure this out for arch if we ever try out gnome. + # install for multiple display managers in case we use one + dir=/etc/gdm3 + sudo mkdir -p $dir/PostLogin + sudo cp /a/bin/distro-setup/desktop-20-autostart.sh $dir/PostLogin/Default + sudo mkdir -p /etc/lightdm/lightdm.conf.d + sudo dd of=/etc/lightdm/lightdm.conf.d/12-iank.conf <<'EOF' [SeatDefaults] session-setup-script=/a/bin/distro-setup/desktop-20-autostart.sh EOF - fi - fi ### install and configure wayland @@ -611,4 +595,5 @@ fi echo 0 >~/.local/distro-begin echo "$0: $(date): ending now" +echo "exiting with status 0" exit 0 diff --git a/distro-end b/distro-end index d63d315..18edaa5 100755 --- a/distro-end +++ b/distro-end @@ -12,15 +12,14 @@ if [[ $EUID == 0 ]]; then exit 1 fi -errcatch-cleanup() { +err-cleanup() { echo 1 >~/.local/distro-end } # shellcheck source=./pkgs source $src/pkgs -exec &> >(sudo tee -a /var/log/distro-end) -echo "$0: $(date): starting now)" +echo "$0: $(date) starting now)" # see example of usage to understand. end_msg() { local y @@ -32,9 +31,11 @@ end() { echo 0 >~/.local/distro-end if $pending_reboot; then echo "$0: pending reboot and then finished. doing it now." + echo "exiting with status 0" sudo reboot now else echo "$0: $(date): ending now)" + echo "exiting with status 0" fi exit 0 } @@ -104,10 +105,10 @@ esac ### begin certbot install ### -if [[ $distro == debian ]]; then +if [[ $distro == debian || $codename_compat == bionic ]]; then # note, need python-certbot-nginx for nginx, but it depends on nginx, # and I'm not installing nginx by default right now. - pi certbot python-certbot-apache + pi certbot python3-certbot-apache elif [[ $codename_compat == xenial ]]; then # not packaged in xenial or flidas pi software-properties-common @@ -603,10 +604,23 @@ case $codename_compat in # mate doesnt have wayland support yet pi task-gnome-desktop ;; + bionic) + pi gnome-core + ;; esac +if [[ $codename_compat == flidas ]]; then + # doesnt exist in newer + pi gnupg-doc +fi +if [[ $codename == flidas ]]; then + pi abrowser +else + pi firefox + sudo ln -sf /usr/bin/firefox /usr/local/bin/abrowser +fi # TODO: some of the X programs can be removed from pall when using wayland @@ -617,9 +631,6 @@ esac pi ${pall[@]} $(apt-cache search ruby[.0-9]+-doc| awk '{print $1}') $(apt-cache depends gcc|grep -i suggests:| awk '{print $2}') $($src/distro-pkgs) -sgo fsf-vpn-dns-cleanup - - # website is dead june 14 2019. back in october, but meh sudo rm -fv /etc/apt/sources.list.d/iridium-browser.list # case $distro in @@ -864,8 +875,8 @@ fi case $codename in flidas) - - ;; + : + ;; esac @@ -1264,8 +1275,6 @@ sudo gpasswd -a $USER lpadmin # based on ubuntu wiki # in arch, I had to pick out the 6L driver. -# allow user to run vms, from debian handbook -for x in iank user2; 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 @@ -1284,7 +1293,8 @@ m /a/bin/buildscripts/rust m /a/bin/buildscripts/misc pi-nostart virtinst virt-manager - +# allow user to run vms, from debian handbook +for x in iank user2; do s usermod -a -G libvirt,kvm $x; done pi --no-install-recommends kdeconnect @@ -1358,6 +1368,7 @@ DEVICESCAN -a -o on -S on -n standby,q $sched \ ########### misc stuff +pi-nostart network-manager # make networkmanager use resolvconf instead of its own dnsmasq which # conflicts with the normal dnsmasq package. f=/etc/NetworkManager/NetworkManager.conf @@ -1373,6 +1384,7 @@ fi # displays l and I as the same char, grrrrr. sudo fc-cache +pi desktop-file-utils m /a/bin/distro-setup/mymimes diff --git a/distro-pkgs b/distro-pkgs index b69af1a..ab6fa64 100755 --- a/distro-pkgs +++ b/distro-pkgs @@ -154,12 +154,6 @@ case $distro in *) : ;; # comes default or with other packages esac -case $distro in - arch) e firefox pulseaudio ;; - trisquel) e abrowser ;; - *) : ;; # comes default or with other packages, or uknown -esac - case $distro in arch) e ttf-dejavu ;; diff --git a/filesystem/etc/systemd/system/fsf-vpn-dns-cleanup.service b/filesystem/etc/systemd/system/fsf-vpn-dns-cleanup.service index 3e50599..2f6d9bb 100644 --- a/filesystem/etc/systemd/system/fsf-vpn-dns-cleanup.service +++ b/filesystem/etc/systemd/system/fsf-vpn-dns-cleanup.service @@ -1,9 +1,8 @@ # If we reboot, or the vpn dies in an unusual way, it leaves dnsmasq config hanging around. -# This cleans that up. [Unit] Description=fsf-vpn-dns-cleanup After=multi-user.target -Conflicts=openvpn-client@fsf80.service openvpn-client@fsf802.service openvpn-client@fsf803.service openvpn-client@fsf443.service openvpn-client@fsf4432.service openvpn-client@fsf4433.service +Conflicts=openvpn-client@fsf80.service openvpn-client@fsf802.service openvpn-client@fsf803.service openvpn-client@fsf443.service openvpn-client@fsf4432.service openvpn-client@fsf4433.service openvpn@fsf80.service openvpn@fsf802.service openvpn@fsf803.service openvpn@fsf443.service openvpn@fsf4432.service openvpn@fsf4433.service [Service] Type=oneshot diff --git a/mail-route b/mail-route index 2dc237d..a1c1b47 100755 --- a/mail-route +++ b/mail-route @@ -60,7 +60,7 @@ up() { fi fi e() { echo "$0: $*"; "$@"; } - errcatch-cleanup() { stop; } + err-cleanup() { stop; } modify # we leave it as is even when stopping, because we would like it to be default, but the only way # to change the default is for every device, and I want to avoid that, even though I wouldn't mind, others users of this script might. diff --git a/mail-setup b/mail-setup index 3dd3e97..6f96982 100755 --- a/mail-setup +++ b/mail-setup @@ -171,7 +171,9 @@ smarthost="$mxhost::$mxport" ## * Install packages # light version of exim does not have sasl auth support. -pi exim4-daemon-heavy spamassassin spf-tools-perl openvpn dnsmasq +pi exim4-daemon-heavy spamassassin spf-tools-perl dnsmasq openvpn +# our nostart pi fails to avoid enabling +sudo systemctl disable openvpn # trisquel 8 = openvpn, debian stretch = openvpn-client vpn_ser=openvpn-client @@ -308,6 +310,8 @@ if [[ -e $f ]]; then fi if [[ $HOSTNAME == "$MAIL_HOST" ]]; then local_mx=mail.iankelling.org + mkdir -p /etc/letsencrypt/live/$local_mx + chmod 700 /etc/letsencrypt/live rsync_common="rsync -ogtL --chown=root:Debian-exim --chmod=640 root@li.iankelling.org:/etc/letsencrypt/live/$local_mx/" ${rsync_common}fullchain.pem /etc/exim4/exim.crt ret=$? @@ -358,6 +362,10 @@ m systemctl enable mailcert.timer # * common exim4 config source /a/bin/bash_unpublished/source-state +if [[ ! $MAIL_HOST ]]; then + err "\$MAIL_HOST not set" +fi + m sudo gpasswd -a iank adm #needed for reading logs @@ -378,6 +386,13 @@ for d in /Maildir /root/Maildir; do m ln -sf -T /m/md/bounces $d done +# Note, even the server needs permissions of this file right +# if it exists, so do this up here. +f=/p/c/filesystem/etc/exim4/passwd.client +if [[ ! -e $f ]]; then + f=/p/c/machine_specific/$HOSTNAME/filesystem/etc/exim4/passwd.client +fi +m sudo rsync -ahhi --chown=root:Debian-exim --chmod=0640 $f /etc/exim4/ # by default, only 10 days of logs are kept. increase that. m sed -ri 's/^(\s*rotate\s).*/\11000/' /etc/logrotate.d/exim4-base @@ -834,11 +849,6 @@ EOF hostname -f >/etc/mailname - f=/p/c/filesystem/etc/exim4/passwd.client - if [[ ! -e $f ]]; then - f=/p/c/machine_specific/$HOSTNAME/filesystem/etc/exim4/passwd.client - fi - m sudo rsync -ahhi --chown=root:Debian-exim --chmod=0640 $f /etc/exim4/ ;;& ## we use this host to monitor MAIL_HOST diff --git a/pkgs b/pkgs index 59e35ea..55126fd 100644 --- a/pkgs +++ b/pkgs @@ -106,7 +106,6 @@ p3=( goaccess gnat-5 gnome-screenshot - gnupg-doc grepmail guvcview hunspell diff --git a/sl/.iank/package-manager-abstractions b/sl/.iank/package-manager-abstractions new file mode 120000 index 0000000..5e2f60f --- /dev/null +++ b/sl/.iank/package-manager-abstractions @@ -0,0 +1 @@ +/a/bin/distro-functions/src/package-manager-abstractions \ No newline at end of file diff --git a/switch-mail-host b/switch-mail-host index 14a11f8..eafe104 100644 --- a/switch-mail-host +++ b/switch-mail-host @@ -24,7 +24,7 @@ EOF restore_new_btrbk=false restore_old_btrbk=false -errcatch-cleanup() { +err-cleanup() { if $restore_new_btrbk; then e WARNING: due to failure, btrbk.timer may need manual restoration: e $new_shell sudo systemctl start btrbk.timer @@ -38,8 +38,8 @@ errcatch-cleanup() { pre="${0##*/}:" m() { printf "$pre %s\n" "$*"; "$@"; } e() { printf "$pre %s\n" "$*"; } -err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; } -mexit() { echo "exiting with status $1"; exit $1; } +err() { echo "$pre: ERROR: $*" >&2; } +mexit() { echo "$pre: exiting with status $1"; exit $1; } ##### begin command line parsing ######## @@ -58,20 +58,28 @@ done (( $# == 2 )) || usage 1 +if [[ ! $HOSTNAME ]]; then + err '$HOSTNAME is unset' + mexit 1 +fi case $1 in push) + old_host=$HOSTNAME new_host=$2 bbk_args="-s $old_host" new_shell="ssh $new_host" - old_host=$HOSTNAME + new_hostname=$($new_shell hostname) ;; pull) old_host=$2 + new_host=$HOSTNAME + new_hostname=$HOSTNAME bbk_args="-t $new_host" bbk_args="-s $old_host" - new_host=$HOSTNAME old_shell="ssh $old_host" + # test ssh connection + $old_shell : ;; *) err invalid first argument @@ -79,7 +87,6 @@ case $1 in ;; esac - source /a/bin/bash_unpublished/source-state if [[ $old_host != "$MAIL_HOST" ]]; then @@ -92,8 +99,6 @@ if [[ ! $new_host || ! $old_host ]]; then mexit 1 fi -e $new_shell hostname -new_hostname=$($new_shell hostname) ########### end initial processing, begin actually modifying things ########## -- 2.30.2