ccat () { # config cat. see a config without extra lines.
- grep '^\s*[^;[:space:]#]' "$@"
+ grep '^\s*[^;[:space:]#]' "$@" || [[ $? == 1 ]]
}
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 ]];
}
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
}
_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=$?
done < "$file"
}
+failfunc() { asdf a b c; }
+failfunc2() { failfunc d e f; }
# one that comes with distros is too old for newer devices
fastboot() {
#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
}
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
rsync_mountpoint=/q
+ret=0
# default options
conf_only=false
dry_run=false # mostly for testing
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
#!/bin/bash
source /a/bin/errhandle/err
-errcatch-cleanup() {
+err-cleanup() {
echo 1 >~/.local/conflink
}
# 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' \
# 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
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)"
######## 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,
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
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
echo 0 >~/.local/distro-begin
echo "$0: $(date): ending now"
+echo "exiting with status 0"
exit 0
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
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
}
### 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
# 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
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
case $codename in
flidas)
-
- ;;
+ :
+ ;;
esac
# 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
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
########### 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
# displays l and I as the same char, grrrrr.
sudo fc-cache
+pi desktop-file-utils
m /a/bin/distro-setup/mymimes
*) : ;; # 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 ;;
# 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
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.
## * 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
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=$?
# * 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
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
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
goaccess
gnat-5
gnome-screenshot
- gnupg-doc
grepmail
guvcview
hunspell
--- /dev/null
+/a/bin/distro-functions/src/package-manager-abstractions
\ No newline at end of file
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
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 ########
(( $# == 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
;;
esac
-
source /a/bin/bash_unpublished/source-state
if [[ $old_host != "$MAIL_HOST" ]]; then
mexit 1
fi
-e $new_shell hostname
-new_hostname=$($new_shell hostname)
########### end initial processing, begin actually modifying things ##########