lots of fixes
[distro-setup] / distro-end
index d51cbef4eb10ef72fc2c623c5a234c94ebb1d46a..655ae7f4c19d68bf6f4aa1cb6c9ea25997f03b3b 100755 (executable)
@@ -14,7 +14,7 @@
 # limitations under the License.
 
 ### setup
-errcatch
+source /a/bin/errhandle/err
 src="${BASH_SOURCE%/*}"
 source $src/pkgs
 
@@ -110,11 +110,13 @@ if isdeb; then
   # https://store.docker.com/editions/community/docker-ce-server-debian?tab=description
   pi  software-properties-common apt-transport-https
   curl -fsSL https://download.docker.com/linux/$(distro-name-compat)/gpg | sudo apt-key add -
-  sudo add-apt-repository \
-       "deb [arch=amd64] https://download.docker.com/linux/$(distro-name-compat) \
-         $(debian-codename-compat) \
-         stable"
-  p update
+  url=https://download.docker.com/linux/$(distro-name-compat)
+  l="deb [arch=amd64] $url $(debian-codename-compat) stable"
+
+  if ! grep -xFq "$l" /etc/apt/sources.list{,.d/*.list}; then
+    sudo add-apt-repository $l
+    p update
+  fi
   # docker eats up a fair amount of cpu when doing nothing, so don't enable it unless
   # we really need it.
   pi-nostart docker-ce
@@ -144,8 +146,11 @@ case $distro in
   trisquel|ubuntu)
     # not packaged in xenial or flidas
     pi software-properties-common
-    s add-apt-repository -y ppa:certbot/certbot ||:
-    p update
+    l="deb http://ppa.launchpad.net/certbot/certbot/ubuntu xenial main"
+    if ! grep -xFq "$l" /etc/apt/sources.list{,.d/*.list}; then
+      s add-apt-repository -y ppa:certbot/certbot ||:
+      p update
+    fi
     pi python-certbot-apache
     ;;
   # todo: other distros unknown
@@ -163,15 +168,15 @@ sgo certbotmail.timer
 ### end certbot install ###
 
 
-# dogcam setup
-case $HOSTNAME in
-  lj|li)
-    /a/bin/webcam/install-server
-    ;;
-  kw)
-    /a/bin/webcam/install-client
-    ;;
-esac
+# dogcam setup. not using atm
+case $HOSTNAME in
+  lj|li)
+    /a/bin/webcam/install-server
+    ;;
+  kw)
+    /a/bin/webcam/install-client
+    ;;
+esac
 
 pi ${p1[@]}
 
@@ -578,25 +583,13 @@ esac
 # dependent packages.
 pi ${pall[@]} $(apt-cache search ruby[.0-9]+-doc| awk '{print $1}') $(apt-cache depends gcc|grep -i suggests:| awk '{print $2}')
 
-sgo fsf-vpn-dns-cleanup
-
-case $distro in
-  trisquel|ubuntu)
-    l="deb http://ppa.launchpad.net/ansible/ansible/ubuntu xenial main"
-    f=/etc/apt/sources.list.d/ansible-ubuntu-ansible-xenial.list
-    if ! grep -qF "$l" $f; then
-      s add-apt-repository -y ppa:ansible/ansible
-      p update
-    fi
-    s pip install --upgrade pip
-    # newer 2.7 versions have a bug that incorrectly detects trisquel version. fixed once 2.8 arrives
-    # in 2019
-    pip install --user ansible=2.7.4
-    #pi ansible
-    ;;
-esac
-
+if ! type pip; then
+  x=$(mktemp)
+  wget -O$x https://bootstrap.pypa.io/get-pip.py
+  python3 $x --user
+fi
 
+sgo fsf-vpn-dns-cleanup
 
 
 case $distro in
@@ -604,11 +597,17 @@ case $distro in
     pi chromium ;;
   trisquel|ubuntu)
     wget -qO - https://downloads.iridiumbrowser.de/ubuntu/iridium-release-sign-01.pub|sudo apt-key add -
-    cat <<EOF | sudo tee /etc/apt/sources.list.d/iridium-browser.list
+    t=$(mktemp)
+    cat >$t <<EOF
 deb [arch=amd64] https://downloads.iridiumbrowser.de/deb/ stable main
 #deb-src https://downloads.iridiumbrowser.de/deb/ stable main
 EOF
-    p update
+    f=/etc/apt/sources.list.d/iridium-browser.list
+    if ! diff -q $t $f; then
+      cp $t $f
+      chmod 644 $f
+      p update
+    fi
     pi iridium-browser
     ;;
 esac
@@ -953,26 +952,31 @@ Package: btrfs-progs libzstd1
 Pin: release a=bionic
 Pin-Priority: 1005
 
-Package: *
+Package: btrfs-progs libzstd1
 Pin: release a=bionic-updates
 Pin-Priority: 1005
 
-Package: *
+Package: btrfs-progs libzstd1
 Pin: release a=bionic-security
 Pin-Priority: 1005
 EOF
 
 
-    # this will be needed if we want to pin something, generally useful for investigating
-    s dd of=/etc/apt/sources.list.d/bionic.list 2>/dev/null <<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
+      cp $t $f
+      chmod 644 $f
+      p update
+    fi
 
-
-    p update
-
+    # no special reason, but its better for btrfs-progs to
+    # be closer to our kernel version
     pi btrfs-progs
 
     t=$(mktemp -d)
@@ -1012,6 +1016,10 @@ mkschroot() {
   esac
   n=$1
   shift
+  if schroot -l | grep -xFq chroot:$n; then
+    echo "$0: $n schroot already installed, skipping"
+    return 0
+  fi
   apps=($@)
   d=/nocow/schroot/$n
   s dd of=/etc/schroot/chroot.d/$n.conf <<EOF
@@ -1076,6 +1084,42 @@ case $distro in
   # others unknown
 esac
 
+
+# adapted from /var/lib/dpkg/info/transmission-daemon.postinst
+# 450 seems likely to be unused. we need to specify one or else
+# it won't be stable across installs.
+if ! getent passwd debian-transmission > /dev/null; then
+  case $distro in
+    arch)
+      s groupadd -g 450 debian-transmission
+      s useradd \
+        --system \
+        --create-home \
+        --gid 450 \
+        --uid 450 \
+        --home-dir /var/lib/transmission-daemon \
+        --shell /bin/false \
+        debian-transmission
+      ;;
+    *)
+      s adduser --quiet \
+        --gid 450 \
+        --uid 450 \
+        --system \
+        --group \
+        --no-create-home \
+        --disabled-password \
+        --home /var/lib/transmission-daemon \
+        debian-transmission
+      ;;
+  esac
+fi
+# We want group writable stuff from transmission.
+# However, after setting this, I learn that transmission sets it's
+# own umask based on it's settings file. Well, no harm leaving this
+# so it's set right from the beginning.
+s chfn debian-transmission -o umask=0002
+
 case $distro in
   debian|trisquel|ubuntu)
     # note i had to do this, which is persistent:
@@ -1093,6 +1137,9 @@ EOF
 
     # some reason it doesn\'t seem to start automatically anyways
     pi-nostart transmission-daemon
+    # be extra sure its not started
+    ser disable transmission-daemon
+    ser stop transmission-daemon
 
     # the folder was moved here after an install around 02/2017.
     # it contains runtime data,
@@ -1140,40 +1187,11 @@ File.write(p, JSON.pretty_generate(JSON.parse(File.read(p)).merge({
 })) + "\n")
 EOF
 
-    # make sure its not enabled, not sure if this is needed
-    ser disable transmission-daemon
     ;;
   # todo: others unknown
 esac
-# adapted from /var/lib/dpkg/info/transmission-daemon.postinst
-if ! getent passwd debian-transmission > /dev/null; then
-  case $distro in
-    arch)
-      s useradd \
-        --system \
-        --create-home \
-        --home-dir /var/lib/transmission-daemon \
-        --shell /bin/false \
-        debian-transmission
-      ;;
-    *)
-      s adduser --quiet \
-        --system \
-        --group \
-        --no-create-home \
-        --disabled-password \
-        --home /var/lib/transmission-daemon \
-        debian-transmission
-      ;;
-  esac
-fi
 
 
-# We want group writable stuff from transmission.
-# However, after setting this, I learn that transmission sets it's
-# own umask based on it's settings file. Well, no harm leaving this
-# so it's set right from the beginning.
-s chfn debian-transmission -o umask=0002
 
 # trisquel 8 = openvpn, debian stretch = openvpn-client
 vpn_ser=openvpn-client
@@ -1316,8 +1334,17 @@ for x in iank traci; do s usermod -a -G libvirt,kvm $x; done
 
 case $distro in
   debian|trisquel|ubuntu)
+    if ! type -p go &>/dev/null; then
+      cd $(mktemp -d)
+      # just the latest stable at the time of writing
+      # TODO, maybe put this all into a build script,
+      # and do some automatic updates
+      wget https://dl.google.com/go/go1.12.4.linux-amd64.tar.gz
+      s tar -C /usr/local -xzf go1.12.4.linux-amd64.tar.gz
+      rm -f *
+    fi
+    go get -u mvdan.cc/fdroidcl
     # a bit of googling, and added settings to bashrc
-    go get -u github.com/mvdan/fdroidcl/cmd/fdroidcl
     ;;
 esac
 
@@ -1347,7 +1374,7 @@ case $distro in
     ./configure --with-exuberant-ctags=/usr/bin/ctags
     make
     s make install
-    pip install pygments
+    pip install pygments
     ;;
   *)
     pi global