2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
6 source /a
/bin
/errhandle
/err
7 src
="$(readlink -f -- "${BASH_SOURCE[0]}")"; src
=${src%/*} # directory of this file
9 if [[ $EUID == 0 ]]; then
10 echo "$0: error: run as regular user" >&2
15 echo 1 >~
/.local
/distro-end
18 # shellcheck source=./pkgs
21 exec &> >(sudo
tee -a /var
/log
/distro-end
)
22 echo "$0: $(date): starting now)"
23 # see example of usage to understand.
26 IFS
= read -r -d '' y ||
:
31 echo 0 >~
/.local
/distro-end
32 if $pending_reboot; then
33 echo "$0: pending reboot and then finished. doing it now."
36 echo "$0: $(date): ending now)"
43 SUDOD
="$PWD" sudo
-i "$@";
46 s
dd of
="$1" 2>/dev
/null
48 m
() { printf "$pre %s\n" "$*"; "$@"; }
49 e
() { printf "$pre %s\n" "$*"; }
50 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; }
52 codename
=$
(debian-codename
)
53 codename_compat
=$
(debian-codename-compat
)
55 sed="sed --follow-symlinks"
67 s debconf-set-selections
<<EOF
68 popularity-contest popularity-contest/participate boolean true
71 ########### begin section including linode ################
77 # no equivalent in other distros:
78 if isdeb
&& pcheck apt-file
; then
79 # this condition is just a speed optimization
88 # allows me to pipe with ssh -t, and gets rid of spam
89 # http://forums.debian.net/viewtopic.php?f=5&t=85822
90 # i'd rather disable the service than comment the init file
91 # this says disabling the service, it will still get restarted
92 # but this script doesn't do anything on restart, so it should be fine
93 s truncate
-s0 /var
/run
/motd.dynamic
96 # this isn't a complete solution. It still shows me when updates are available,
97 # but it's no big deal.
98 s
rm -fv /etc
/update-motd.d
/10-help-text /etc
/update-motd.d
/00-header
105 ### begin certbot install ###
106 if [[ $distro == debian
]]; then
107 # note, need python-certbot-nginx for nginx, but it depends on nginx,
108 # and I'm not installing nginx by default right now.
109 pi certbot python-certbot-apache
110 elif [[ $codename_compat == xenial
]]; then
111 # not packaged in xenial or flidas
112 pi software-properties-common
113 l
="deb http://ppa.launchpad.net/certbot/certbot/ubuntu xenial main"
114 if ! grep -xFq "$l" /etc
/apt
/sources.list
{,.d
/*.list
}; then
115 s add-apt-repository
-y ppa
:certbot
/certbot ||
:
118 pi python-certbot-apache
120 err
"distro unknown for certbot"
122 # make a version of the certbot timer that emails me.
123 x
=/systemd
/system
/certbot
124 $sed -r -f - /lib
$x.timer
<<'EOF' |sd /etc${x}mail.timer
125 s,^Description.*,\0 mail version,
127 $sed -r -f - /lib
$x.service
<<'EOF' |sd /etc${x}mail.service
128 s,(ExecStart=)(/usr/bin/certbot),\1/a/bin/log-quiet/sysd-mail-once certbotmail \2 --renew-hook /a/bin/distro-setup/certbot-renew-hook,
131 m sgo certbotmail.timer
132 ### end certbot install ###
135 # dogcam setup. not using atm
138 # /a/bin/webcam/install-server
141 # /a/bin/webcam/install-client
146 ## not actually using prometheus just yet
147 # # office is not exposed to internet yet
148 # if [[ $HOSTNAME != kw ]]; then
149 # ## prometheus node exporter setup
150 # web-conf -f 9100 -p 9101 apache2 $(hostname -f) <<'EOF'
151 # #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
152 # # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
156 # AuthName "Authentication Required"
157 # # setup one time, with root:www-data, 640
158 # AuthUserFile "/etc/prometheus-htpasswd"
165 ######### begin flidas pinned packages ######
166 case $
(debian-codename
) in
167 # needed for debootstrap scripts for fai since fai requires debian
169 curl http
://archive.ubuntu.com
/ubuntu
/project
/ubuntu-archive-keyring.gpg | s apt-key add
-
170 sd
/etc
/apt
/preferences.d
/flidas-xenial
<<EOF
172 Pin: release a=xenial
176 Pin: release a=xenial-updates
180 Pin: release a=xenial-security
183 sd
/etc
/apt
/sources.list.d
/xenial.list
2>/dev
/null
<<EOF
184 deb http://us.archive.ubuntu.com/ubuntu/ xenial main
185 deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main
186 deb http://us.archive.ubuntu.com/ubuntu/ xenial-security main
189 if ! apt-key list |
grep /C0B21F32
&>/dev
/null
; then
190 s apt-key adv
--keyserver keyserver.ubuntu.com
--recv-keys 3B4FE6ACC0B21F32
191 sd
/etc
/apt
/preferences.d
/flidas-bionic
<<EOF
193 Pin: release a=bionic
197 Pin: release a=bionic-updates
201 Pin: release a=bionic-security
206 # better to run btrfs-progs which matches our kernel version
207 # (note, renamed from btrfs-tools)
208 sd
/etc
/apt
/preferences.d
/btrfs-progs
<<EOF
209 Package: btrfs-progs libzstd1
210 Pin: release a=bionic
213 Package: btrfs-progs libzstd1
214 Pin: release a=bionic-updates
217 Package: btrfs-progs libzstd1
218 Pin: release a=bionic-security
225 deb http://us.archive.ubuntu.com/ubuntu/ bionic main
226 deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main
227 deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main
229 f
=/etc
/apt
/sources.list.d
/bionic.list
230 if ! diff -q $t $f; then
236 # no special reason, but its better for btrfs-progs to
237 # be closer to our kernel version
240 if [[ ! -e /usr
/share
/debootstrap
/scripts
/xenial
]]; then
243 m aptitude download debootstrap
/xenial
245 s
cp .
/usr
/share
/debootstrap
/scripts
/* /usr
/share
/debootstrap
/scripts
248 sd
/etc
/apt
/preferences.d
/flidas-etiona
<<EOF
250 Pin: release a=etiona
254 Pin: release a=etiona-updates
258 Pin: release a=etiona-security
262 Pin: release a=etiona-backports
268 deb http://mirror.fsf.org/trisquel/ etiona main
269 deb http://mirror.fsf.org/trisquel/ etiona-updates main
270 deb http://archive.trisquel.info/trisquel/ etiona-security main
271 deb http://mirror.fsf.org/trisquel/ etiona-backports main
273 f
=/etc
/apt
/sources.list.d
/etiona.list
274 if ! diff -q $t $f; then
280 sd
/etc
/apt
/preferences.d
/debian-goodies
<<EOF
281 Package: debian-goodies
282 Pin: release n=etiona
287 sd
/etc
/apt
/preferences.d
/flidas-buster
<<EOF
289 Pin: release n=buster
293 Pin: release n=buster-updates
297 # dont use buster because it causes dist-upgrade to think its downgrading
298 # packages while really just reinstalling the same version.
299 f
=/etc
/apt
/apt.conf.d
/01iank
301 # # stupid buster uses some key algorithm not supported by flidas gpg that apt uses.
302 # sd /etc/apt/apt.conf.d/01iank <<'EOF'
303 # Acquire::AllowInsecureRepositories "true";
306 f
=/etc
/apt
/sources.list.d
/buster.list
310 # deb http://http.us.debian.org/debian buster main
311 # deb-src http://http.us.debian.org/debian buster main
313 # deb http://security.debian.org/ buster/updates main
314 # deb-src http://security.debian.org/ buster/updates main
316 # deb http://http.us.debian.org/debian buster-updates main
317 # deb-src http://http.us.debian.org/debian buster-updates main
319 # if ! diff -q $t $f; then
325 # newer version needed for false positive in checkrestart.
326 # I did buster at first, but other problem above with having
327 # buster repos. not sure if the false positive exists in etiona.
330 sd
/etc
/apt
/preferences.d
/shellcheck
<<EOF
332 Pin: release a=etiona
336 Pin: release a=etiona-updates
340 Pin: release a=etiona-security
344 sd
/etc
/apt
/preferences.d
/bash
<<EOF
346 Pin: release a=etiona
350 Pin: release a=etiona-updates
354 Pin: release a=etiona-security
362 pi debian-goodies shellcheck
366 ######### end flidas pinned packages ######
368 ##### begin automatic upgrades (after checkrestart has been installed) ####
369 sd
/etc
/apt
/apt.conf.d
/10periodic
<<'EOF'
370 # this file was mostly just comments.
371 APT::Periodic::Update-Package-Lists "1";
372 APT::Periodic::Download-Upgradeable-Packages "1";
373 APT::Periodic::AutocleanInterval "7";
374 APT::Periodic::Unattended-Upgrade "1";
377 sd
/etc
/apt
/apt.conf.d
/50unattended
-upgrades <<EOF
378 # fyi: default file has comments about available options,
379 # you may want to read that, do pkx unattended-upgrades
380 Unattended-Upgrade::Mail "root";
381 Unattended-Upgrade::MailOnlyOnError "true";
382 Unattended-Upgrade::Remove-Unused-Dependencies "true";
383 Unattended-Upgrade::Origins-Pattern {
384 # default is just security updates. this list found from reading
385 # match_whitelist_string() in $(which unattended-upgrades)
386 "o=*,l=*,a=*,c=*,site=*,n=*";
390 # old names, too verbose
391 s
rm -f /etc
/cron.d
/unattended-upgrade-reboot
/usr
/local
/bin
/zelous-unattended-reboot
393 sd
/etc
/cron.d
/myupgrade
<<'EOF'
394 # Setup reboots when running outdated stuff, unattended upgrades happen
395 # at 6 am + rand(60 min).
399 # default is /usr/bin:/bin
400 PATH=/usr/bin:/bin:/usr/local/bin
401 20 7 * * * iank myupgrade |& log-once -1 myupgrade
402 0 * * * * root mycheckrestart |& log-once -1 mycheckrestart
404 ##### end automatic upgrades ####
408 ###### begin website setup
412 f
=/var
/lib
/bind
/db.b8.nz
413 if [[ ! -e $f ]]; then
416 s
install -m 644 -o bind -g bind /p
/c
/machine_specific
/linode
/bind-initial
/db.b8.nz
$f
421 # setup let's encrypt cert
422 m web-conf apache2 l2.b8.nz
423 s
rm -fv /etc
/apache
2/sites-enabled
/l2.b8.nz
{,-redir}.conf
425 s lnf
-T /etc
/letsencrypt
/live
/l2.b8.nz
/fullchain.pem
/etc
/exim
4/exim.crt
426 if [[ ! -L /etc
/exim
4/exim.key
]]; then
427 s lnf
-T /etc
/letsencrypt
/live
/l2.b8.nz
/privkey.pem
/etc
/exim
4/exim.key
436 m
/a
/h
/setup.sh iankelling.org
439 # allow symlinks on other hosts so i can host files in arbitrary paths
445 # start mumble only when im going to use it, since i dont use it much
446 pi-nostart mumble-server
447 s
$sed -ri "s/^ *(serverpassword=).*/\1$(< /a/bin/bash_unpublished/mumble_pass)/" /etc
/mumble-server.ini
449 # do certificate to avoid warning about unsigned cert,
450 # which is overkill for my use, but hey, I'm cool, I know
452 m web-conf apache2 mumble.iankelling.org
453 s
rm -fv /etc
/apache
2/sites-enabled
/mumble.iankelling.org
455 export RENEWED_LINEAGE=/etc/letsencrypt/live/mumble.iankelling.org
456 /a/bin/distro-setup/certbot-renew-hook
460 # requested from linode via a support ticket.
461 # https://www.linode.com/docs/networking/an-overview-of-ipv6-on-linode/
462 # ipv6 stuff pieced together
463 # via slightly wrong information from
464 # https://github.com/angristan/openvpn-install/blob/master/openvpn-install.sh
465 # https://community.openvpn.net/openvpn/wiki/IPv6
468 m vpn-server-setup
-rd 2600:3c00
:e000
:280::1/64 2600:3c00
::f03c
:91ff
:feb4
:0bf3
469 s
tee /etc
/openvpn
/client-config
/mail <<'EOF'
470 ifconfig-push 10.8.0.4 255.255.255.0
471 ifconfig-ipv6-push 2600:3c00:e000:280::2/64
474 if [[ -e /lib
/systemd
/system
/openvpn-server@.service
]]; then
475 vpn_service
=openvpn-server@server
477 vpn_service
=openvpn@server
480 sudo
dd of
=/etc
/systemd
/system
/vpnmail.service
<<EOF
482 Description=Turns on iptables mail nat
487 ExecStart=/a/bin/distro-setup/vpn-mail-forward start
488 ExecStop=/a/bin/distro-setup/vpn-mail-forward stop
491 WantedBy=$vpn_service.service
494 m sgo vpnmail.service
495 # needed for li's local mail delivery.
496 tu
/etc
/hosts
<<<"10.8.0.4 mail.iankelling.org"
498 # setup let's encrypt cert
499 m web-conf apache2 mail.iankelling.org
500 s rm -fv /etc/apache2/sites-enabled/mail.iankelling.org{,-redir}.conf
503 domain=cal.iankelling.org
504 web-conf -f 10.8.0.4:5232 - apache2 $domain <<'EOF'
505 #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
506 # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
508 Options +FollowSymLinks +Multiviews +Indexes
511 AuthName "Authentication Required"
512 # setup one time, with root:www-data, 640
513 AuthUserFile "/etc/caldav-htpasswd"
517 # nginx version of above would be:
518 # auth_basic "Not currently available";
519 # auth_basic_user_file /etc/nginx/caldav/htpasswd;
523 ###### begin znc setup #####
526 # https://wiki.znc.in/FAQ seems to imply that znc doesn\'t need restart after cert change.
527 # to get into the web interface,
528 # then use non-main browser or else it doebsn't allow it based on ocsp stapling from my main site.
529 # https://iankelling.org:12533/
531 export RENEWED_LINEAGE=/etc/letsencrypt/live/iankelling.org
532 /a/bin/distro-setup/certbot-renew-hook
535 # znc config generated by doing
537 # selected port is also used in erc config
538 # comma separated channel list worked.
539 # while figuring things out, running znc -D for debug in foreground.
540 # to exit and save config:
541 # /msg *status shutdown
542 # configed auth on freenode by following
543 # https://wiki.znc.in/Sasl:
544 # /msg *sasl RequireAuth yes
545 # /msg *sasl Mechanism PLAIN
546 # /msg *sasl Set ident_name password
547 # created the system service after, and had to do
548 # mv /home/iank/.znc/* /var/lib/znc
549 # sed -i 's,/home/iank/.znc/,/var/lib/znc,' /var/lib/znc/config/znc.conf
550 # and made a copy of the config files into /p/c
551 # /msg *status LoadMod --type=global log -sanitize
552 # todo: in config file AllowWeb = true should be false. better security if that is off unless we need it.
553 # /msg *status LoadMod --type=network perform
554 # /msg *perform add PRIVMSG ChanServ :invite #fsf-office
555 # /msg *perform add JOIN #fsf-office
558 # also ran /znc LoadMod clearbufferonmsg
559 # it would be nice if erc supported erc query buffers by doing
560 # /msg *status clearbuffer <name of the query/receiver
562 # an example seems to be here: https://github.com/zenspider/elisp/blob/master/rwd-irc.el
563 # if that was the case i could remove the module clearbufferonmsg
564 # also would be nice if erc supported
565 # https://wiki.znc.in/self-message
566 # https://wiki.znc.in/Query_buffers \
568 s useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc || [[ $? == 9 ]] # 9 if it exists already
569 s chmod 700 /var/lib/znc
570 s chown -R znc:znc /var/lib/znc
571 # Avoid restarting if possible, reconnecting to irc is annoying.
572 # The unit file was made active with conflink.
573 if [[ $(ser is-active znc) != active ]]; then
576 ###### stop znc setup #####
581 ###### end website setup
583 ########### end section including li/lj ###############
586 case $codename_compat in
588 # mate-indicator-applet and beyond are msc things I noticed diffing a
589 # standard install with mine.
590 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras mate-indicator-applet anacron
596 # mate doesnt have wayland support yet
597 pi task-gnome-desktop
604 # TODO: some of the X programs can be removed from pall when using wayland
606 # depends gcc is a way to install suggests. this is apparently the only
607 # way to install suggests even if the main package is already
608 # installed. reinstall doesn't work, uninstalling can cause removing
609 # dependent packages.
610 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)
613 m sgo fsf-vpn-dns-cleanup
616 # website is dead june 14 2019. back in october, but meh
617 s rm -fv /etc/apt/sources.list.d/iridium-browser.list
622 # wget -qO - https://downloads.iridiumbrowser.de/ubuntu/iridium-release-sign-01.pub|sudo apt-key add -
625 # deb [arch=amd64] https://downloads.iridiumbrowser.de/deb/ stable main
626 # #deb-src https://downloads.iridiumbrowser.de/deb/ stable main
628 # f=/etc/apt/sources.list.d/iridium-browser.list
629 # if ! diff -q $t $f; then
639 ### begin home vpn server setup
642 # # this section done initially to make persistent keys.
643 # # Also note, I temporarily set /etc/hosts so my host was
644 # # b8.nz when running this, since the vpn client config
645 # # generator assumes we need to go to that server to get
647 # vpn-server-setup -rds
648 # s cp -r --parents /etc/openvpn/easy-rsa/keys /p/c/filesystem
649 # s chown -R 1000:1000 /p/c/filesystem/etc/openvpn/easy-rsa/keys
650 # # kw = kgpe work machine.
651 # for host in x2 x3 kw; do
652 # vpn-mk-client-cert -b $host -n home b8.nz 1196
653 # dir=/p/c/machine_specific/$host/filesystem/etc/openvpn/client
655 # s bash -c "cp /etc/openvpn/client/home* $dir"
656 # # note: /etc/update-resolv-conf-home also exists for all systems with /p
659 # key already exists, so this won't generate one, just the configs.
660 m vpn-server-setup -rds
661 s tee -a /etc/openvpn/server/server.conf <<'EOF'
662 push "dhcp-option DNS 10.0.0.1"
663 push "route 10.0.0.0 255.255.0.0"
664 client-connect /a/bin/distro-setup/vpn-client-connect
666 s sed -i --follow-symlinks 's/10.8./10.9./g;s/^\s*port\s.*/port 1196/' /etc/openvpn/server/server.conf
668 if [[ $HOSTNAME == tp ]]; then
669 if [[ -e /lib/systemd/system/openvpn-server@.service ]]; then
670 vpn_service=openvpn-server@server
672 vpn_service=openvpn@server
676 ### end vpn server setup
680 # note, see bashrc for more documentation.
682 sd /etc/systemd/system/rss2email.service <<'EOF'
684 Description=rss2email
685 After=multi-user.target
690 # about 24 hours of failures
691 # it copies over its files without respecting symlinks, so
692 # we pass options to use different location.
693 ExecStart=/a/bin/log-quiet/sysd-mail-once -288 rss2email r2e -d /p/c/rss2email.json -c /p/c/rss2email.cfg run
695 sd /etc/systemd/system/rss2email.timer <<'EOF'
697 Description=rss2email
700 # for initial run. required.
702 # for subsequent runs.
703 OnUnitInactiveSec=300
706 WantedBy=timers.target
708 s systemctl daemon-reload
711 ######### begin pump.io periodic backup #############
712 if [[ $HOSTNAME == frodo ]]; then
713 sd /etc/systemd/system/pumpbackup.service <<'EOF'
715 Description=pump li backup
716 After=multi-user.target
721 ExecStart=/a/bin/log-quiet/sysd-mail-once pump-backup /a/bin/distro-setup/pump-backup
723 sd /etc/systemd/system/pumpbackup.timer <<'EOF'
725 Description=pump li backup hourly
731 WantedBy=timers.target
734 m sgo pumpbackup.timer
736 ######### end pump.io periodic backup #############
739 ######### begin irc periodic backup #############
740 if [[ $HOSTNAME == frodo ]]; then
741 sd /etc/systemd/system/ircbackup.service <<'EOF'
743 Description=irc li backup
744 After=multi-user.target
749 ExecStart=/a/bin/log-quiet/sysd-mail-once irc-backup rsync -rlptDhSAX root@iankelling.org:/var/lib/znc/moddata/log/iank/freenode/ /k/irclogs
751 sd /etc/systemd/system/ircbackup.timer <<'EOF'
753 Description=irc li backup hourly
759 WantedBy=timers.target
761 s systemctl daemon-reload
766 ######### end irc periodic backup #############
770 debian|trisquel|ubuntu)
771 # suggests resolvconf package. installing it here is redundant, but make sure anyways.
772 # todo: check other distros to make sure it\'s installed
773 pi-nostart openvpn resolvconf
774 # pi-nostart does not disable
780 m /a/bin/distro-setup/radicale-setup
783 ############# begin syncthing setup ###########
784 if [[ $HOSTNAME == frodo ]]; then
785 # It\'s simpler to just worry about running it in one place for now.
786 # I assume it would work to clone it\'s config to another non-phone
787 # and just run it in one place instead of the normal having a
788 # separate config. I lean toward using the same config, since btrfs
789 # syncs between comps.
790 # testing has relatively up to date packages
791 if ! isdebian-testing; then
792 # based on error when doing apt-get update:
793 # E: The method driver /usr/lib/apt/methods/https could not be found.
794 pi apt-transport-https
795 # google led me here:
796 # https://apt.syncthing.net/
797 curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
798 s="deb http://apt.syncthing.net/ syncthing release"
799 if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != "$s" ]]; then
800 echo "$s" | sd /etc/apt/sources.list.d/syncthing.list
805 m lnf -T /w/syncthing /home/iank/.config/syncthing
806 ser daemon-reload # syncthing likely not properly packaged
807 m sgo syncthing@iank # runs as iank
809 # these things persist in ~/.config/syncthing, which I save in
810 # /w/syncthing (not in /p, because syncthing should continue to
811 # run on home server even when using laptop as primary device)
812 # open http://localhost:8384/
813 # change listen address from default to tcp://:22001,
814 # this is because we do port forward so it doesn\'t have to use
815 # some external server, but the syncthing is broken for port forward,
816 # you get a message, something "like connected to myself, this should not happen"
817 # when connecting to other local devices, so I bump the port up by 1,
819 # https://forum.syncthing.net/t/connected-to-myself-should-not-happen/1763/19.
820 # Without this, it was being stuck syncing at 0%.
821 # Set gui username and password.
823 # install syncthing via f-droid,
824 # folder setting, turn off send only.
825 # on phone, add device, click bar code icon
826 # on dekstop, top right, actions, device id
827 # after adding, notification will appear on desktop to confirm
829 # syncing folder. from phone to desktop: select desktop in the
830 # folder on phone\'s sync options, notification will appear in
831 # desktop\'s web ui within a minute. For the reverse, the
832 # notification will appear in android\'s notifications, you have to
833 # swipe down and tap it to add the folder. It won\'t appear in the
834 # syncthing ui, which would be intuitive, but don\'t wait for it
835 # there. The notification may not work, instead open the web gui
836 # from in the app, there should be a notification within there.
838 # On phone, set settings to run syncthing all the time, and
839 # show no notification.
841 # Folder versioning would make sense if I didn\'t already use btrfs
842 # for backups. I would choose staggered, or trash can for more space.
844 # if needed to install on a remote comp:
845 # ssh -L 8384:localhost:8384 -N frodo
846 # open http://localhost:8384/
848 # Note, the other thing i did was port forward port 22000,
849 # per https://docs.syncthing.net/users/firewall.html
852 ############# end syncthing setup ###########
856 ####### begin misc packages ###########
865 # sakura config is owned by ian
868 m sudo -u user2 -i reset-konsole
869 # user2 xscreensaver we don't want to reset
873 # this would install from cabal for newer / consistent version across os, but it screws up xmonad, so disabled for now.
874 # this is also in primary-setup
875 # pi libxss-dev # dependency based on build failure
877 # cabal install --upgrade-dependencies --force-reinstalls arbtt
878 # also, i assume syncing this between machines somehow messed thin
879 #lnf -T /m/arbtt-capture.log ~/.arbtt/capture.log
883 if [[ ! -e ~/.linphonerc && -e /p/.linphonerc-initial ]]; then
884 m cp /p/.linphonerc-initial ~/.linphonerc
888 ### begin spd install
889 pi libswitch-perl libdigest-md5-file-perl libgnupg-interface-perl
891 m wget -O $t http://mirror.fsf.org/fsfsys-trisquel/fsfsys-trisquel/pool/main/s/spd-perl/spd-perl_0.2-1_amd64.deb
894 # this guesses at the appropriate directory, adjust if needed
895 perldir=(/usr/lib/x86_64-linux-gnu/perl/5.*)
896 m sudo ln -sf ../../../perl/5.18.2/SPD/ ${perldir[0]}
897 # newer distro had gpg2 as default, older one, flidas, need to make it that way
898 gpgpath=$(which gpg2)
900 s mkdir -p /usr/local/spdhackfix
901 s lnf -T $gpgpath /usr/local/spdhackfix/gpg
906 # nagstamon setting which were set through the ui
908 # all unknown sources
909 # all warning services
910 # acknowledged hosts & services
911 # hosts & services down for maintenence
912 # services on down hosts
913 # services on hosts in maintenece
914 # services on unreachable osts
915 # hosts in soft state
916 # services in soft state
917 # in display tab: fullscreen
919 # these translate to these settings I think
920 # filter_acknowledged_hosts_services = True
921 # filter_all_unknown_services = True
922 # filter_all_warning_services = True
923 # filter_hosts_in_soft_state = True
924 # filter_hosts_services_maintenance = True
925 # filter_services_in_soft_state = True
926 # filter_services_on_down_hosts = True
927 # filter_services_on_hosts_in_maintenance = True
928 # filter_services_on_unreachable_hosts = True
929 # notify_if_up = False
930 # statusbar_floating = False
932 # but i'm just going to rely on the webpage plus sms for now.
935 # it asks if it should make users in it's group capture packets without root,
936 # which is arguably more secure than running wireshark as root. default is no,
937 # which is what i prefer, since I plan to use tcpdump to input to wireshark.
938 s DEBIAN_FRONTEND=noninteractive pi wireshark-gtk
940 # /run and /dev/shm are listed as required for pulseaudio. All 4 in the group
941 # listed in the default config as suggested.
942 # /run/usr/1000 i noticed was missing for pulseaudio
943 # /run/user/0 just seemed like a not bad idea, given the above
944 tu /etc/schroot/desktop/fstab <<'EOF'
945 /run /run none rw,bind 0 0
946 /run/lock /run/lock none rw,bind 0 0
947 /dev/shm /dev/shm none rw,bind 0 0
948 /run/shm /run/shm none rw,bind 0 0
949 /run/user/1000 /run/user/1000 none rw,bind 0 0
950 /run/user/1001 /run/user/1001 none rw,bind 0 0
951 /run/user/0 /run/user/0 none rw,bind 0 0
959 repo=http://archive.ubuntu.com/ubuntu/
962 repo=http://deb.debian.org/debian/
967 if schroot -l | grep -xFq chroot:$n; then
968 echo "$0: $n schroot already installed, skipping"
973 sd /etc/schroot/chroot.d/$n.conf <<EOF
979 preserve-environment=true
982 if [[ -e $d/bin ]]; then
983 s chroot $d apt-get update
984 s chroot $d apt-get -y dist-upgrade --purge --auto-remove
985 cd; s schroot -c $n -- apt-get install --allow-unauthenticated -y ${apps[@]}
989 s debootstrap $n $d $repo
990 cd; s schroot -c $n -- apt-get install --allow-unauthenticated -y ${apps[@]}
992 s cp -P {,$d}/etc/localtime
994 sd /etc/systemd/system/schrootupdate.service <<'EOF'
996 Description=schrootupdate
997 After=multi-user.target
1001 ExecStart=/a/bin/log-quiet/sysd-mail-once schrootupdate /a/bin/distro-setup/schrootupdate
1003 sd /etc/systemd/system/schrootupdate.timer <<'EOF'
1005 Description=schrootupdate
1008 OnCalendar=*-*-* 04:20:00
1011 WantedBy=timers.target
1014 m sgo schrootupdate.timer
1021 m mkschroot debian stretch firefox-esr pulseaudio chromium
1028 s mkdir -p /nocow/user
1029 s chown $USER:$USER /nocow/user
1033 ####### begin transmission
1044 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
1045 # 450 seems likely to be unused. we need to specify one or else
1046 # it won't be stable across installs.
1047 if ! getent passwd debian-transmission > /dev/null; then
1048 s groupadd -g 450 debian-transmission
1054 --disabled-password \
1055 --home /var/lib/transmission-daemon \
1058 # We want group writable stuff from transmission.
1059 # However, after setting this, I learn that transmission sets it's
1060 # own umask based on it's settings file. Well, no harm leaving this
1061 # so it's set right from the beginning.
1062 s chfn debian-transmission -o umask=0002
1064 # note i had to do this, which is persistent:
1066 # s chgrp debian-transmission torrents partial-torrents
1068 # syslog says things like
1069 # 'Failed to set receive buffer: requested 4194304, got 425984'
1070 # google suggets giving it even more than that
1071 tu /etc/sysctl.conf<<'EOF'
1072 net.core.rmem_max = 67108864
1073 net.core.wmem_max = 16777216
1077 # some reason it doesn\'t seem to start automatically anyways
1078 pi-nostart transmission-daemon
1079 # be extra sure its not started
1080 ser disable transmission-daemon
1081 ser stop transmission-daemon
1083 # the folder was moved here after an install around 02/2017.
1084 # it contains runtime data,
1085 # plus a simple symlink to the config file which it\'s
1086 # not worth separating out.
1087 # between comps, the uid can change
1088 f=$tdir/transmission-daemon
1090 s lnf -T $f /var/lib/transmission-daemon/.config/transmission-daemon
1091 s lnf -T /etc/transmission-daemon/settings.json $f/settings.json
1092 s chown -R debian-transmission:debian-transmission $f
1093 for f in $tdir/partial-torrents $tdir/torrents; do
1094 if [[ -e $f ]]; then
1095 s chown -R debian-transmission:user2 $f
1098 s chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon
1100 # config file documented here, and it\'s the same config
1101 # for daemon vs client, so it\'s documented in the gui.
1102 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
1104 # I originaly setup rpc-whitelist, but after using
1105 # routing to a network namespace, it doesn\'t see the
1106 # real source address, so it\'s disabled.
1108 # Changed the cache-size to 256 mb, reduces disk use.
1109 # It is a read & write cache.
1112 p = '/etc/transmission-daemon/settings.json'
1113 File.write(p, JSON.pretty_generate(JSON.parse(File.read(p)).merge({
1114 'rpc-whitelist-enabled' => false,
1115 'rpc-authentication-required' => false,
1116 'incomplete-dir' => '$tdir/partial-torrents',
1117 'incomplete-dir-enabled' => true,
1118 'download-dir' => '$tdir/torrents',
1119 "speed-limit-up" => 800,
1120 "speed-limit-up-enabled" => true,
1121 "peer-port" => 61486,
1122 "cache-size-mb" => 256,
1123 "ratio-limit" => 5.0,
1124 "ratio-limit-enabled" => true,
1127 ####### end transmission
1131 # trisquel 8 = openvpn, debian stretch = openvpn-client
1132 vpn_ser=openvpn-client
1133 if [[ ! -e /lib/systemd/system/openvpn-client@.service ]]; then
1137 sd /etc/systemd/system/transmission-daemon-nn.service <<EOF
1139 Description=Transmission BitTorrent Daemon netns
1140 After=network.target
1141 Requires=${vpn_ser}-nn@client.service
1142 After=${vpn_ser}-nn@client.service
1143 JoinsNamespaceOf=${vpn_ser}-nn@client.service
1146 #User=debian-transmission
1147 # notify type doesn't work with sudo
1149 ExecStart=/usr/bin/nsenter --mount=/root/mount_namespaces/client sudo -u debian-transmission /usr/bin/transmission-daemon -f --log-error
1150 ExecReload=/bin/kill -s HUP \$MAINPID
1155 WantedBy=multi-user.target
1159 if [[ $HOSTNAME == frodo ]]; then
1160 m sgo transmission-daemon-nn
1164 ######### begin transmission client setup ######
1166 if [[ -e /p/transmission-rpc-pass ]]; then
1167 # arch had a default config,
1168 # debian had nothing until you start it.
1169 # With a little trial an error, here is a minimal config
1170 # taken from the generated one, plus changes that the
1171 # settings ui does, without a bunch of ui crap settings.
1173 # only settings I set were
1178 # the password is randomly generated on first run, i copied it out
1179 # so it could be used by other hosts.
1182 p = '/etc/transmission-daemon/settings.json'
1183 s = JSON.parse(File.read(p))
1184 s["rpc-password"] = File.read("/p/transmission-rpc-pass").chomp
1185 # default is 0022 (18 in decimal)
1187 File.write p, JSON.pretty_generate(s)
1190 rpc_pass=$(</p/transmission-rpc-pass)
1191 for f in /home/*; do
1193 uid=$(id -u $u 2>/dev/null) || continue
1194 if [[ ! $uid -ge 1000 ]]; then
1197 d=$f/.config/transmission-remote-gtk
1199 s -u $u dd of=$d/config.json <<EOF
1203 "profile-name" : "Default",
1204 "hostname" : "transmission.b8.nz",
1206 "rpc-url-path" : "/transmission/rpc",
1208 "password" : "$rpc_pass",
1209 "auto-connect" : true,
1213 "update-active-only" : false,
1214 "activeonly-fullsync-enabled" : false,
1215 "activeonly-fullsync-every" : 2,
1216 "update-interval" : 3,
1217 "min-update-interval" : 3,
1218 "session-update-interval" : 60,
1219 "exec-commands" : [],
1223 "profile-name" : "local",
1224 "hostname" : "10.173.0.2",
1227 "password" : "$rpc_pass",
1228 "auto-connect" : true,
1232 "update-active-only" : false,
1233 "activeonly-fullsync-enabled" : false,
1234 "activeonly-fullsync-every" : 2,
1235 "update-interval" : 3,
1236 "min-update-interval" : 3,
1237 "session-update-interval" : 60,
1238 "exec-commands" : [],
1243 "add-options-dialog" : false
1248 ######### end transmission client setup ######
1253 s gpasswd -a $USER lpadmin # based on ubuntu wiki
1254 # goto http://127.0.0.1:631
1255 # administration tab, add new printer button.
1256 # In debian, I could use hte recommended driver,
1257 # in arch, I had to pick out the 6L driver.
1260 # allow user to run vms, from debian handbook
1261 for x in iank user2; do s usermod -a -G libvirt,kvm $x; done
1262 # bridge networking as user fails. google lead here, but it doesn\'t work:
1263 # oh well, I give up.
1264 # http://wiki.qemu.org/Features-Done/HelperNetworking
1266 # f=/etc/qemu/bridge.conf
1270 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
1273 # general known for debian/ubuntu, not for fedora
1275 m /a/bin/buildscripts/go
1276 m /a/bin/buildscripts/rust
1277 m /a/bin/buildscripts/misc
1279 pi-nostart virtinst virt-manager
1283 pi --no-install-recommends kdeconnect
1284 ### kdeconnect for gnome. started in /a/bin/distro-setup/desktop-20-autostart.sh
1285 ### but gnome + xmonad not working in flidas, so i disabled it
1286 # pi libgtk-3-dev python3-requests-oauthlib valac cmake python-nautilus libappindicator3-dev
1287 # cd /a/opt/indicator-kdeconnect
1290 # cmake .. -DCMAKE_INSTALL_PREFIX=/usr
1293 # # we can start it manually with /usr/lib/x86_64-linux-gnu/libexec/kdeconnectd
1294 # # it seems, according to
1295 # # /etc/xdg/autostart/kdeconnectd.desktop
1296 # # I'm not seeing the icon, but the clipboard replication is working
1299 ### model 01 arduino support ###
1300 # https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux
1301 # also built latest arduino in /a/opt/Arduino, (just cd build; ant build; ant run )
1302 # set arduino var in bashrc,
1303 # have system config file setup too.
1304 s adduser $USER dialout
1306 # this is for the mail command too. update-alternatives is kind of misleading
1307 # since at least it's main commands pretend mail does not exist.
1308 # bsd's mail got pulled in on some dumb dependency, i dunno how.
1309 s update-alternatives --set mailx /usr/bin/mail.mailutils
1311 ######### end misc packages #########
1314 # packages I once used before and liked, but don\'t want installed now for
1316 # python-sqlite is used for offlineimap
1317 # lxappearance python-sqlite dolphin paman dconf-editor
1323 # todo, finish configuring smart.
1326 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
1327 # turn on smart. background on options:
1328 # first line, -a = test everyting on all devices.
1329 # -S on, turn on disk internal saving of vendor specific info,
1330 # from google, seems like this is usually already on and fairly standard.
1331 # -o on, turn on 4 hour period non-performance degrading testing.
1332 # short test daily 2-3am, extended tests Saturdays between 3-4am:
1333 sched="-s (S/../.././02|L/../../6/03)"
1334 s sed -i --follow-symlinks "s#^[[:space:]]*DEVICESCAN.*#\
1335 DEVICESCAN -a -o on -S on -n standby,q $sched \
1336 -m ian@iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
1338 # in the default configuration of at least ubuntu 14.04, resolvconf is
1339 # configured to order any nameservers associated with tun* or tap*
1340 # before the normal internet interfaces, which means they are always
1341 # consulted first. This is often slower and undesirable, ie. local dns
1342 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
1344 #sudo sed -i --follow-symlinks '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
1345 # however, this breaks dns lookup for hosts on the openvpn lan.
1346 # I can\'t figure out why hosts on the normal lan would not be
1347 # broken under the default ordering, except the host I was
1348 # testing with previously had an entry in /etc/hosts.
1350 ############# end unfinished
1352 ########### misc stuff
1354 # make networkmanager use resolvconf instead of its own dnsmasq which
1355 # conflicts with the normal dnsmasq package.
1356 f=/etc/NetworkManager/NetworkManager.conf
1358 s sed -ri '/ *\[main\]/,/^ *\[[^]]+\]/{/^\s*dns[[:space:]=]/d}' $f
1359 s sed -ri '/ *\[main\]/a dns=default' $f
1360 if [[ $m != $(md5sum $f) ]]; then
1361 srestart NetworkManager
1364 # make my /etc/fonts/conf.d/ get used.
1365 # I have a new sans-serif font there because the default one
1366 # displays l and I as the same char, grrrrr.
1369 m /a/bin/distro-setup/mymimes
1372 m sgo dynamicipupdate
1375 # stop autopoping windows when i plug in an android phone.
1376 # dbus-launch makes this work within an ssh connection, otherwise you get this message,
1377 # with still 0 exit code.
1378 # dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
1379 m dbus-launch gsettings set org.gnome.desktop.media-handling automount-open false
1382 # on grub upgrade, we get prompts unless we do this
1384 for dev in $(s btrfs fil show /boot | sed -nr 's#.*path\s+(\S+)$#\1#p'); do
1385 devs+=("$(devbyid $dev),")
1387 devs[-1]=${devs[-1]%,} # jonied by commas
1388 s debconf-set-selections <<EOF
1389 grub-pc grub-pc/install_devices multiselect ${devs[*]}
1393 sgo btrfsmaint.timer
1394 sgo btrfsmaintstop.timer
1396 # aren't autoupdating this, but I do check on it somewhat regularly.
1401 # note: to see when it was last run,
1406 In mate settings settings, change scrolling to two-finger,
1407 because the default edge scroll doesn\'t work. Originally found this in debian.
1410 # Remove dep that came in with desktop to fix associations.
1411 m pu transmission-gtk
1413 s gpasswd -a iank adm #needed for reading logs
1415 m /a/bin/buildscripts/pithosfly
1418 # # Based on guix manual instructions, also added code to profile.
1419 # # disabled since i'm not using it now.
1421 # if ! type -p guix >/dev/null; then
1423 # wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
1424 # # added some stuff to envonment.sh for profile based on
1425 # # manual instructions
1426 # # wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
1427 # # echo is to get past prompt
1428 # yes | sudo -E HOME=$HOME bash guix-install.sh || [[ $? == 141 ]]
1429 # guix install glibc-utf8-locales
1430 # guix package --install guile
1436 m /a/bin/buildscripts/tor-browser
1439 pi-nostart nfs-kernel-server
1441 # networkmanager has this nasty behavior on flidas: if the machine
1442 # crashes with dnsmasq running, on subsequent boot, it adds an entry to
1443 # resolvconf for 127.0.0.1 in some stupid attempt to restore
1445 # This can be manually fixed by stoping dnsmasq,
1446 # then based on whats in /run/dnsmasq/, i see we can run
1447 # s resolvconf -d NetworkManager
1448 # oh ya, and stoping NetworkManager leaves this crap behind without cleaning it up.
1449 ser disable NetworkManager
1452 if [[ $HOSTNAME == frodo ]]; then
1453 # nohide = export filesystems mounted deeper than the export point
1454 # fsid=0 makes this export the "root" export
1455 # not documented in the man page, but this means
1456 # 1. it can be mounted with a shorthand of server:/
1457 # 2. exports that are subdirectories of this one will automatically be mounted
1458 tu /etc/exports <<'EOF'
1459 /k 10.0.0.0/24(rw,fsid=0,nohide,no_root_squash,async,no_subtree_check,insecure)
1468 # if I was going to create a persistent vm, i might do it like this:
1469 # variant=something # from: virt-install --os-variant list
1470 # s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
1471 # --disk=/a/images/some_name.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
1472 # -n some_name --import --os-variant $variant --cpu host-model-only
1476 ######### begin stuff belonging at the end ##########