shellcheck, better automated upgrades
[distro-setup] / distro-end
index 15ae5c2acd17085444d8892c4550e963b0bb990b..14cc2f52ddca1ff5d0ea158f9d7d55e7734ba47f 100755 (executable)
@@ -15,7 +15,9 @@
 
 ### setup
 source /a/bin/errhandle/err
-src="${BASH_SOURCE%/*}"
+src="$(readlink -f -- "${BASH_SOURCE[0]}")"; src=${src%/*} # directory of this file
+
+# shellcheck source=./pkgs
 source $src/pkgs
 
 set -x
@@ -34,6 +36,7 @@ spa() { # simple package add
   simple_packages+=($@)
 }
 distro=$(distro-name)
+codename=$(debian-codename)
 codename_compat=$(debian-codename-compat)
 pending_reboot=false
 sed="sed --follow-symlinks"
@@ -48,12 +51,12 @@ if isdeb; then
 fi
 
 # avoid ptompts!
-debconf-set-selections <<EOF
+debconf-set-selections <<EOF
 popularity-contest popularity-contest/participate boolean true
 EOF
 
 ########### begin section including li ################
-pi ${p3[@]} $($src/distro-pkgs)
+pi ${p3[@]}
 
 #### desktop stuff
 case $codename_compat in
@@ -183,15 +186,38 @@ sgo certbotmail.timer
 pi ${p1[@]}
 
 ##### begin automatic upgrades ####
-# this makes it so we upgrade everything
-s debconf-set-selections <<'EOF'
-unattended-upgrades unattended-upgrades/origins_pattern string "codename=${distro_codename}";
+
+s dd of=/etc/apt/apt.conf.d/10periodic <<'EOF'
+# this file was mostly just comments.
+APT::Periodic::Update-Package-Lists "1";
+APT::Periodic::Download-Upgradeable-Packages "1";
+APT::Periodic::AutocleanInterval "7";
+APT::Periodic::Unattended-Upgrade "1";
+EOF
+
+s dd of=/etc/apt/apt.conf.d/50unattended-upgrades  <<EOF
+# fyi: default file has comments about available options,
+# you may want to read that.
+Unattended-Upgrade::Mail "root";
+Unattended-Upgrade::MailOnlyOnError "true";
+Unattended-Upgrade::Remove-Unused-Dependencies "true";
+Unattended-Upgrade::Origins-Pattern {
+       # default is just security updates.
+       "origin=*";
+};
 EOF
-s dpkg-reconfigure -u -fnoninteractive unattended-upgrades
 
-# Setup daily reboots, so all unattended upgrades go into affect
-# unattended upgrades happen at 6 am + rand(60 min).
-echo '20 7 * * * root /usr/local/bin/zelous-unattended-reboot' | s dd of=/etc/cron.d/unattended-upgrade-reboot
+# Setup reboots when running outdated stuff, unattended upgrades happen
+# at 6 am + rand(60 min).
+/usr/local/bin/log-once checkrestart
+
+# old names, too verbose
+s rm -f /etc/cron.d/unattended-upgrade-reboot /usr/local/bin/zelous-unattended-reboot
+
+s dd of=/etc/cron.d/myupgrade <<'EOF'
+20 7 * * * root /usr/local/bin/myupgrade | /usr/local/bin/log-once -1 myupgrade
+0 * * * * root /usr/local/bin/mycheckrestart | /usr/local/bin/log-once -1 mycheckrestart
+EOF
 ##### end automatic upgrades ####
 
 # office is not exposed to internet yet
@@ -433,7 +459,7 @@ EOF
     # s reboot now
     # when running docker-compose run, kernel stack traces are printed to the journal.
     # things seem to succeed, google says nothing, so ignoring them.
-    curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` | s dd of=/usr/local/bin/docker-compose
+    curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-$(uname -s)-$(uname -m) | s dd of=/usr/local/bin/docker-compose
     s chmod +x /usr/local/bin/docker-compose
 
 
@@ -475,7 +501,7 @@ EOF
       printf "%s=%s\n" $key "$(docker-compose run --rm web rake secret|dos2unix|tail -n1)" >>.env.production
     done
     found=false
-    while read -r domain port pass; do
+    while read -r domain _ pass; do
       if [[ $domain == mail.iankelling.org ]]; then
         found=true
         # remove the username part
@@ -608,13 +634,182 @@ esac
 
 ########### end section including li/lj ###############
 
+
+case $(debian-codename) in
+  # needed for debootstrap scripts for fai since fai requires debian
+  flidas)
+    curl http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg | s apt-key add -
+    s dd of=/etc/apt/preferences.d/flidas-xenial <<EOF
+Package: *
+Pin: release a=xenial
+Pin-Priority: -100
+
+Package: *
+Pin: release a=xenial-updates
+Pin-Priority: -100
+
+Package: *
+Pin: release a=xenial-security
+Pin-Priority: -100
+EOF
+    s dd of=/etc/apt/sources.list.d/xenial.list 2>/dev/null <<EOF
+deb http://us.archive.ubuntu.com/ubuntu/ xenial main
+deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main
+deb http://us.archive.ubuntu.com/ubuntu/ xenial-security main
+EOF
+
+    s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
+    s dd of=/etc/apt/preferences.d/flidas-bionic <<EOF
+Package: *
+Pin: release a=bionic
+Pin-Priority: -100
+
+Package: *
+Pin: release a=bionic-updates
+Pin-Priority: -100
+
+Package: *
+Pin: release a=bionic-security
+Pin-Priority: -100
+EOF
+
+    # better to run btrfs-progs which matches our kernel version
+    # (note, renamed from btrfs-tools)
+    s dd of=/etc/apt/preferences.d/btrfs-progs <<EOF
+Package: btrfs-progs libzstd1
+Pin: release a=bionic
+Pin-Priority: 1005
+
+Package: btrfs-progs libzstd1
+Pin: release a=bionic-updates
+Pin-Priority: 1005
+
+Package: btrfs-progs libzstd1
+Pin: release a=bionic-security
+Pin-Priority: 1005
+EOF
+
+
+    t=$(mktemp)
+    cat >$t <<EOF
+deb http://us.archive.ubuntu.com/ubuntu/ bionic main
+deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main
+deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main
+EOF
+    f=/etc/apt/sources.list.d/bionic.list
+    if ! diff -q $t $f; then
+      s cp $t $f
+      s chmod 644 $f
+      p update
+    fi
+
+    # no special reason, but its better for btrfs-progs to
+    # be closer to our kernel version
+    pi btrfs-progs
+
+    t=$(mktemp -d)
+    cd $t
+    aptitude download debootstrap/xenial
+    ex ./*
+    s cp ./usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
+
+    s dd of=/etc/apt/preferences.d/flidas-etiona <<EOF
+Package: *
+Pin: release a=etiona
+Pin-Priority: -100
+
+Package: *
+Pin: release a=etiona-updates
+Pin-Priority: -100
+
+Package: *
+Pin: release a=etiona-security
+Pin-Priority: -100
+
+Package: *
+Pin: release a=etiona-backports
+Pin-Priority: -100
+EOF
+
+    t=$(mktemp)
+    cat >$t <<EOF
+deb http://mirror.fsf.org/trisquel/ etiona main
+deb http://mirror.fsf.org/trisquel/ etiona-updates main
+deb http://archive.trisquel.info/trisquel/ etiona-security main
+deb http://mirror.fsf.org/trisquel/ etiona-backports main
+EOF
+    f=/etc/apt/sources.list.d/etiona.list
+    if ! diff -q $t $f; then
+      s cp $t $f
+      s chmod 644 $f
+      p update
+    fi
+
+    s dd of=/etc/apt/preferences.d/debian-goodies <<EOF
+Package: debian-goodies
+Pin: release n=buster
+Pin-Priority: 1005
+EOF
+
+
+    s dd of=/etc/apt/preferences.d/flidas-buster <<EOF
+Package: *
+Pin: release n=buster
+Pin-Priority: -100
+EOF
+
+    # stupid buster uses some key algorithm not supported by flidas gpg that apt uses.
+    s dd of=/etc/apt/apt.conf.d/01iank <<'EOF'
+Acquire::AllowInsecureRepositories "true";
+EOF
+
+    t=$(mktemp)
+    cat >$t <<EOF
+deb http://http.us.debian.org/debian buster main
+deb-src http://http.us.debian.org/debian buster main
+
+deb http://security.debian.org/ buster/updates main
+deb-src http://security.debian.org/ buster/updates main
+
+deb http://http.us.debian.org/debian buster-updates main
+deb-src http://http.us.debian.org/debian buster-updates main
+EOF
+    f=/etc/apt/sources.list.d/buster.list
+    if ! diff -q $t $f; then
+      s cp $t $f
+      s chmod 644 $f
+      p update
+    fi
+
+    # newer version needed for false positive in checkrestart
+    p install -y --allow-unauthenticated debian-goodies
+
+    s dd of=/etc/apt/preferences.d/shellcheck <<EOF
+Package: shellcheck
+Pin: release a=etiona
+Pin-Priority: 1005
+
+Package: shellcheck
+Pin: release a=etiona-updates
+Pin-Priority: 1005
+
+Package: shellcheck
+Pin: release a=etiona-security
+Pin-Priority: 1005
+EOF
+
+
+    ;;
+esac
+
+
 # TODO: some of the X programs can be removed from pall when using wayland
 
 # depends gcc is a way to install suggests. this is apparently the only
 # way to install suggests even if the main package is already
 # installed. reinstall doesn't work, uninstalling can cause removing
 # dependent packages.
-pi ${pall[@]} $(apt-cache search ruby[.0-9]+-doc| awk '{print $1}') $(apt-cache depends gcc|grep -i suggests:| awk '{print $2}')
+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)
 
 if ! type pip; then
   x=$(mktemp)
@@ -826,7 +1021,7 @@ if [[ $HOSTNAME == frodo ]]; then
         # https://apt.syncthing.net/
         curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
         s="deb http://apt.syncthing.net/ syncthing release"
-        if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != $s ]]; then
+        if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != "$s" ]]; then
           echo "$s" | s dd of=/etc/apt/sources.list.d/syncthing.list
           p update
         fi
@@ -887,6 +1082,13 @@ fi
 
 ####### begin misc packages ###########
 
+case $codename in
+  flidas)
+
+    ;;
+esac
+
+
 # sakura config is owned by ian
 reset-sakura
 reset-konsole
@@ -917,13 +1119,13 @@ wget -O $t http://mirror.fsf.org/fsfsys-trisquel/fsfsys-trisquel/pool/main/s/spd
 s dpkg -i $t
 rm $t
 # this guesses at the appropriate directory, adjust if needed
-x=(/usr/lib/x86_64-linux-gnu/perl/5.*)
-sudo ln -sf ../../../perl/5.18.2/SPD/ $x
+perldir=(/usr/lib/x86_64-linux-gnu/perl/5.*)
+sudo ln -sf ../../../perl/5.18.2/SPD/ ${perldir[0]}
 # newer distro had gpg2 as default, older one, flidas, need to make it that way
-x=$(which gpg2)
+gpgpath=$(which gpg2)
 if [[ $x ]]; then
   s mkdir -p /usr/local/spdhackfix
-  s lnf -T $x /usr/local/spdhackfix/gpg
+  s lnf -T $gpgpath /usr/local/spdhackfix/gpg
 fi
 ### end spd install
 
@@ -976,119 +1178,6 @@ case $distro in
   # others unknown
 esac
 
-case $(debian-codename) in
-  # needed for debootstrap scripts for fai since fai requires debian
-  flidas)
-    curl http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg | s apt-key add -
-    s dd of=/etc/apt/preferences.d/flidas-xenial <<EOF
-Package: *
-Pin: release a=xenial
-Pin-Priority: -100
-
-Package: *
-Pin: release a=xenial-updates
-Pin-Priority: -100
-
-Package: *
-Pin: release a=xenial-security
-Pin-Priority: -100
-EOF
-    s dd of=/etc/apt/sources.list.d/xenial.list 2>/dev/null <<EOF
-deb http://us.archive.ubuntu.com/ubuntu/ xenial main
-deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main
-deb http://us.archive.ubuntu.com/ubuntu/ xenial-security main
-EOF
-
-    s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
-    s dd of=/etc/apt/preferences.d/flidas-bionic <<EOF
-Package: *
-Pin: release a=bionic
-Pin-Priority: -100
-
-Package: *
-Pin: release a=bionic-updates
-Pin-Priority: -100
-
-Package: *
-Pin: release a=bionic-security
-Pin-Priority: -100
-EOF
-
-    # better to run btrfs-progs which matches our kernel version
-    # (note, renamed from btrfs-tools)
-    s dd of=/etc/apt/preferences.d/btrfs-progs <<EOF
-Package: btrfs-progs libzstd1
-Pin: release a=bionic
-Pin-Priority: 1005
-
-Package: btrfs-progs libzstd1
-Pin: release a=bionic-updates
-Pin-Priority: 1005
-
-Package: btrfs-progs libzstd1
-Pin: release a=bionic-security
-Pin-Priority: 1005
-EOF
-
-
-    t=$(mktemp)
-    cat >$t <<EOF
-deb http://us.archive.ubuntu.com/ubuntu/ bionic main
-deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main
-deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main
-EOF
-    f=/etc/apt/sources.list.d/bionic.list
-    if ! diff -q $t $f; then
-      s cp $t $f
-      s chmod 644 $f
-      p update
-    fi
-
-    # no special reason, but its better for btrfs-progs to
-    # be closer to our kernel version
-    pi btrfs-progs
-
-    t=$(mktemp -d)
-    cd $t
-    aptitude download debootstrap/xenial
-    ex ./*
-    s cp ./usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
-
-    s dd of=/etc/apt/preferences.d/flidas-etiona <<EOF
-Package: *
-Pin: release a=etiona
-Pin-Priority: -100
-
-Package: *
-Pin: release a=etiona-updates
-Pin-Priority: -100
-
-Package: *
-Pin: release a=etiona-security
-Pin-Priority: -100
-
-Package: *
-Pin: release a=etiona-backports
-Pin-Priority: -100
-EOF
-
-    t=$(mktemp)
-    cat >$t <<EOF
-deb http://mirror.fsf.org/trisquel/ etiona main
-deb http://mirror.fsf.org/trisquel/ etiona-updates main
-deb http://archive.trisquel.info/trisquel/ etiona-security main
-deb http://mirror.fsf.org/trisquel/ etiona-backports main
-EOF
-    f=/etc/apt/sources.list.d/etiona.list
-    if ! diff -q $t $f; then
-      s cp $t $f
-      s chmod 644 $f
-      p update
-    fi
-
-    ;;
-esac
-
 # /run and /dev/shm are listed as required for pulseaudio. All 4 in the group
 # listed in the default config as suggested.
 # /run/usr/1000 i noticed was missing for pulseaudio
@@ -1604,7 +1693,7 @@ dbus-launch gsettings set org.gnome.desktop.media-handling automount-open false
 # on grub upgrade, we get prompts unless we do this
 devs=()
 for dev in $(s btrfs fil show /boot | sed -nr 's#.*path\s+(\S+)$#\1#p'); do
-  devs+=($(devbyid $dev),)
+  devs+=("$(devbyid $dev),")
 done
 devs[-1]=${devs[-1]%,} # jonied by commas
 s debconf-set-selections <<EOF
@@ -1675,6 +1764,28 @@ esac
 
 /a/bin/buildscripts/pithosfly
 
+
+# based on guix manual instructions, also added code to profile
+pi nscd
+if ! type -p guix >/dev/null; then
+  cd $(mktemp -d)
+  wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
+  # added some stuff to envonment.sh for profile based on
+  # manual instructions
+  # wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
+  # echo is to get past prompt
+  yes | sudo -E HOME=$HOME bash guix-install.sh || [[ $? == 141 ]]
+  guix install glibc-utf8-locales
+  guix package --install guile
+fi
+
+# install rust.
+curl https://sh.rustup.rs -sSf | bash -s -- -y
+# todo: update this. updates in rust are stupidly complicate
+if ! which rg &>/dev/null; then
+  cargo install ripgrep
+fi
+
 #### tor
 case $distro in
   # based on
@@ -1746,16 +1857,12 @@ make sure to reload the firewall to load the persistent configuration
 
 EOF
     pi nfs-utils
-    sgo nfs-server
     ;;
   debian|trisquel|ubuntu)
-    pi nfs-server
+    pi-nostart nfs-server
     ;;
   arch)
     pi nfs-utils || pending_reboot=true
-    sgo rpcbind
-    # this failed until I rebooted
-    sgo nfs-server
     ;;
 esac