various fixes and updates
[distro-setup] / distro-begin
index 89acacf1a2451688a66ac07f8e1b5d26e528bab7..5dc03598ea16e3920e68db7de3b2e3655614afbf 100755 (executable)
@@ -18,7 +18,7 @@ sudo bash -c 'source /a/c/repos/bash/.bashrc && source /a/bin/ssh-emacs-setup'
 # set the scrollback to unlimited in case something goes wrong
 
 if [[ $EUID == 0 ]]; then
-    echo error: do not run as root
+    echo "error: do not run as root"
     exit
 fi
 
@@ -34,17 +34,15 @@ fi
 set -E
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
 
-headless=false
-debian_stable=false
+# headless=false # unused atm
 recompile=true
 # for copying to a new data fs
-bootstrapfs=false
+bootstrapfs=false # old flag, needs new look before using.
 while [[ $1 == -* ]]; do
     case $1 in
         # avoid some of the longer compilation steps,
         # when we need to rerun because we had an error
         -n) recompile=false; shift ;;
-        -b) boostrap_new_comp=true; shift ;;
     esac
 done
 
@@ -54,10 +52,11 @@ else
     host=$HOSTNAME
 fi
 
-for f in iank-dev htpc treetowl x2 frodo; do
+for f in iank-dev htpc treetowl x2 frodo tp; do
     eval "$f() { [[ $host == $f ]]; }"
 done
-encrypted() { iank-dev || x2 || frodo ; }
+has_p() { iank-dev || x2 || frodo; }
+encrypted() { has_p || tp; }
 
 shopt -s extglob
 export GLOBIGNORE=*/.:*/..
@@ -166,9 +165,22 @@ sudo sed -ri '/noatime/s/relatime,?|defaults,?//g' /etc/fstab
 
 # this script has been designed to be idempotent
 # todo, it would be nice to cut down on some of the output
+
+
+
+# output is below so shellcheck can verify sources
 for x in /a/bin/bash-programs-by-ian/repos/{errhandle,tee-unique,lnf}/*-function; do
-    source $x;
+    echo "# shellcheck source=$x";
+    # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/bash-trace-function
+    # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errallow-function
+    # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errcatch-function
+    # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errexit-function
+    # shellcheck source=/a/bin/bash-programs-by-ian/repos/tee-unique/teeu-function
+    # shellcheck source=/a/bin/bash-programs-by-ian/repos/lnf/lnf-function
+    source $x
 done
+
+
 set +e
 $interactive || errcatch
 source /a/bin/distro-functions/src/identify-distros
@@ -176,7 +188,6 @@ echo path:$PATH
 
 
 
-
 if isfedora; then
     # comment out line disallowing calling sudo in scripts
     sudo sed -i 's/^Defaults *requiretty/#\0 # ian commented/' /etc/sudoers
@@ -231,32 +242,29 @@ if isdebian; then
     s sed -i 's/^\(deb.* main\).*/\1 contrib non-free/' /etc/apt/sources.list
 
     # non-existent var, as Im not planning to use stable right now
-    if $debian_stable; then
+    if isdebian-stable; then
         code=$(debian-codename)
-        tu /etc/apt/sources.list <<EOF
+        s dd of=/etc/apt/sources.list.d/mozilla-iceweasel <<EOF
 deb http://mozilla.debian.net/ $code-backports iceweasel-release
 deb-src http://mozilla.debian.net/ $code-backports iceweasel-release
 EOF
 
         # we change the mirror from the default, so we cant use tu
-        if ! grep -qP "^deb [^ ]+ $code-backports main contrib non-free" /etc/apt/sources.list; then
-            s tee -a /etc/apt/sources.list <<EOF
+        s dd of=/etc/apt/sources.list.d/main-backports <<EOF
 deb http://ftp.us.debian.org/debian/ $code-backports main contrib non-free
 deb-src http://ftp.us.debian.org/debian/ $code-backports main contrib non-free
 EOF
-        fi
 
         p update
         # take care of mozilla signing errors in previous command
         pi pkg-mozilla-archive-keyring
     else
-        sudo sed -ri 's!^( *[^ #]+ +[^ ]+ +)[[:alpha:]]+(.*)!\1testing\2!' \
-             /etc/apt/sources.list
-        pup
+        :
+        # this would change stable to testing, but I set that up already.
+        # It\'s just a no-op if its already testing.
+        # sudo sed -ri 's!^( *[^ #]+ +[^ ]+ +)[[:alpha:]]+(.*)!\1testing\2!' /etc/apt/sources.list
+        p update
     fi
-    # doesnt exist on ubuntu. ubuntu has a mirror type url to use instead.
-    pi netselect-apt
-    debian_pick_mirror
 fi
 
 if isarch; then
@@ -291,13 +299,16 @@ EOF
     sudo dd of=/etc/pacman.conf if=$x; rm $x
     sudo systemctl enable pacserve.service
     sudo systemctl start pacserve.service
+
+    # strange error if just installing trash-cli: "pyalpm requires python",
+    # so I see that it requires python2, and installing that manually fixes it.
+    # I didn't see this on earlier installation, main thing which changed was
+    # pacserve, so not sure if it's related.
+    pi python2
 fi
+
 pup
-# strange error if just installing trash-cli: "pyalpm requires python",
-# so I see that it requires python2, and installing that manually fixes it.
-# I didn't see this on earlier installation, main thing which changed was
-# pacserve, so not sure if it's related.
-pi python2 trash-cli
+pi trash-cli
 
 
 ###### link files ###########
@@ -317,29 +328,24 @@ s lnf /a/sdx{,d} /
 
 # todo: this is desktop specific. on work comp, mkdir /p/.editor-backups
 # todo: reconcile ~/.ssh/config work/home
-if encrypted; then
+if has_p; then
     lnf -T /p/offlineimap ~/Maildir
     lnf -T /p/News ~/News
     s lnf -T /q/p /p
     # don't use /* because I don't want to require it to be mounted
     s lnf /q/root/.editor-backups /q/root/.undo-tree-history \
-      /q/root/.ssh /q/root/sasl_passwd /q/root/sasl_passwd.db /a/opt \
+      /q/root/.ssh /a/opt \
       /a/c/.emacs.d ~/.unison /root
 
 fi
 
-for x in /a/c/repos/*/!(.git); do
-    [[ $x == */. || $x == */.. ]] && continue # workaround for ubuntu 14.04 bug
-    lnf "$x" ~
-done
-
 s lnf /a/c/.inputrc /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
 
 if [[ $HOSTNAME == htpc ]]; then
     lnf -T /i/Videos ~/Downloads
 fi
 
-if encrypted; then
+if has_p; then
     # for dovecot
     lnf -T /i/mboxes ~/mail
 fi
@@ -348,9 +354,14 @@ fi
 # basic needed packages
 case $(distro-name) in
     debian)
-        pi $( $debian_stable && e -t $code-backports ) iceweasel \
-           linux-image-amd64 firmware-linux-nonfree \
-           firmware-linux-free linux-headers-amd64
+        pi $( isdebian-stable && e -t $code-backports ) iceweasel
+        # for hosts which require nonfree drivers
+        case $HOSTNAME in
+            tp|x2) : ;;
+            *) pi linux-image-amd64 firmware-linux-nonfree \
+                  firmware-linux-free linux-headers-amd64
+               ;;
+        esac
         ;;&
     ubuntu|debian)
         pi xmacro gtk-redshift xinput
@@ -384,15 +395,19 @@ esac
 
 pi xbindkeys xkbset cryptsetup unison
 
+pi lvm2
 # enables trim for volume delete, other rare commands.
 sudo sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
+
 if encrypted; then
     if isdeb; then
         sudo cp /usr/share/doc/util-linux/examples/fstrim.{service,timer} /etc/systemd/system
     fi
     # does weekly trim
     sudo systemctl enable fstrim.timer
+fi
 
+if has_p; then
     # relatime is default, but it still significantly increases writes
     # in comparison because it writes on the first read after each
     # write.
@@ -401,8 +416,8 @@ if encrypted; then
     if ! frodo; then
         dirs+=(/q)
     fi
-    s mkdir -p ${dirs[@]}
-    s chown ian:ian  ${dirs[@]}
+    s mkdir -p "${dirs[@]}"
+    s chown ian:ian  "${dirs[@]}"
     # ssh and probably some other things care about parent directory
     # ownership, and ssh doesn\'t allow any group writable parent
     # directories, so we are forced to use a directory structure similar
@@ -450,24 +465,13 @@ EOF
 
 
 
-    # emacs dependencies.
+fi
 
-    # dunno why debian installed postfix with yum-builddep emacs
-    # but I will just explicitly install it here since
-    # I use it for sending mail in emacs.
-    if isdeb; then
-        s debconf-set-selections<<EOF
-postfix postfix/main_mailer_type select Satellite system
-postfix postfix/mailname string $host
-postfix postfix/relayhost string [mail.messagingengine.com]:587
-EOF
-        pi postfix
-    else
-        pi postfix
-        s postconf -v 'relayhost = [mail.messagingengine.com]:587'
-        s systemctl enable postfix
-        s systemctl start postfix
-    fi
+
+
+# exptected directory for .editor-backups
+if ! has_p; then
+    s lnf /a/p /
 fi
 
 /a/bin/conflink
@@ -538,6 +542,42 @@ umask 002
 EOF
 
 
+
+# emacs dependency.
+# dunno why debian installed postfix with yum-builddep emacs
+# but I will just explicitly install it here since
+# I use it for sending mail in emacs.
+if private-host; then
+    relayhost="[mail.messagingengine.com]:587"
+else
+    # ses initially suggests port 25, but I had problems connecting to that.
+    relayhost="[email-smtp.us-west-2.amazonaws.com]:587"
+fi
+if isdeb; then
+    s debconf-set-selections<<EOF
+postfix postfix/main_mailer_type select Satellite system
+postfix postfix/mailname string $host
+postfix postfix/relayhost string $relayhost
+EOF
+
+    pi postfix
+else
+    pi postfix
+    # Settings from reading the output when installing on debian,
+    # then seeing which were different in a default install on arch.
+    # I assume the same works for fedora.
+    postconfin <<EOF
+mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
+mailbox_size_limit = 0
+relayhost = $relayhost
+inet_interfaces = loopback-only
+EOF
+
+    s systemctl enable postfix
+    s systemctl start postfix
+fi
+
+
 if isarch; then
     # install so it's build dependencies don't get removed.
     x=$(mktemp -d)
@@ -547,6 +587,8 @@ if isarch; then
     popd
     rm -rf $x
 else
+    # to disable emacs git build,
+    # s apt-get install emacs
     if $recompile; then
         /a/bin/buildscripts/emacs
     else
@@ -563,7 +605,7 @@ if ! isarch; then
         # fedora didn\'t have the 3.
         dir=/etc/gdm
     fi
-    mkdir -p $dir/PostLogin
+    mkdir -p $dir/PostLogin
     s command cp /a/bin/desktop-20-autostart.sh $dir/PostLogin/Default
     s mkdir /etc/lightdm/lightdm.conf.d
     s dd of=/etc/lightdm/lightdm.conf.d/12-ian.conf <<'EOF'
@@ -587,7 +629,7 @@ cabal update
 PATH="$PATH:$HOME/.cabal/bin"
 
 # trying out the distro's versions newer distros
-if $debian_stable || isubuntu; then
+if isdebian-stable || isubuntu; then
     # todo: on ubuntu 12.04, needed to install  zlib1g-dev
     cabal install cabal-install
     pu cabal-install
@@ -628,3 +670,7 @@ else
     fi
 fi
 pi dmenu
+
+if isdeb && (tp || x2); then
+    pi task-laptop
+fi