minor fixes and improvements
[distro-setup] / distro-end
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 # shellcheck source=/a/bin/ds/.bashrc
6 export LC_USEBASHRC=t; if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
7
8 ### setup
9 source /a/bin/errhandle/err
10 src="$(readlink -f -- "${BASH_SOURCE[0]}")"; src=${src%/*} # directory of this file
11
12 if [[ $EUID == 0 ]]; then
13 echo "$0: error: run as regular user" >&2
14 exit 1
15 fi
16
17 err-cleanup() {
18 echo 1 >~/.local/distro-end
19 }
20
21 # shellcheck source=./pkgs
22 source $src/pkgs
23
24 echo "$0: $(date) starting now)"
25 # see example of usage to understand.
26 end_msg() {
27 local y
28 IFS= read -r -d '' y ||:
29 end_msg_var+="$y"
30 }
31 end() {
32 e "$end_msg_var"
33 echo 0 >~/.local/distro-end
34 if $pending_reboot; then
35 echo "$0: pending reboot and then finished. doing it now."
36 echo "exiting with status 0"
37 sudo reboot now
38 else
39 echo "$0: $(date): ending now)"
40 echo "exiting with status 0"
41 fi
42 exit 0
43 }
44 pre="${0##*/}:"
45 sudo() {
46 printf "$pre %s\n" "$*"
47 SUDOD="$PWD" command sudo "$@";
48 }
49 m() { printf "$pre %s\n" "$*"; "$@"; }
50 e() { printf "$pre %s\n" "$*"; }
51 distro=$(distro-name)
52 codename=$(debian-codename)
53 codename_compat=$(debian-codename-compat)
54 pending_reboot=false
55 sed="sed --follow-symlinks"
56
57 # when we schroot, it will fail if we are in a directory that doesnt exist in the chroot
58 cd /
59
60 ## template:
61 # case $distro in
62 # esac
63
64 case $HOSTNAME in
65 li|bk|je) : ;;
66 *)
67 # get sudo pass cached right away
68 if ! sudo -nv 2>/dev/null; then
69 sudo -v
70 fi
71 ;;
72 esac
73
74 # old repo. remove when all machines updated
75 sudo rm -fv /etc/apt/sources.list.d/wireguard-ubuntu-wireguard-bionic.list
76 # remove old file
77 sudo rm -fv /etc/apt/preferences.d/minetest
78
79 #### initial packages
80 pup
81 if isdeb; then
82 pi aptitude
83 fi
84
85 # avoid prompts
86 sudo debconf-set-selections <<EOF
87 popularity-contest popularity-contest/participate boolean true
88 EOF
89
90 ########### begin section including vps ################
91 pi ${p2[@]}
92
93
94 conflink
95
96 sudo rm -fv
97
98 # no equivalent in other distros:
99 if isdeb && pcheck apt-file; then
100 # this condition is just a speed optimization
101 pi apt-file
102 sudo apt-file update
103 fi
104
105
106 # disable motd junk.
107 case $distro in
108 debian)
109 # allows me to pipe with ssh -t, and gets rid of spam
110 # http://forums.debian.net/viewtopic.php?f=5&t=85822
111 # i'd rather disable the service than comment the init file
112 # this says disabling the service, it will still get restarted
113 # but this script doesn't do anything on restart, so it should be fine
114 sudo truncate -s0 /var/run/motd.dynamic
115 ;;
116 trisquel|ubuntu)
117 # this isn't a complete solution. It still shows me when updates are available,
118 # but it's no big deal.
119 sudo rm -fv /etc/update-motd.d/10-help-text /etc/update-motd.d/00-header
120 ;;
121 esac
122
123
124
125
126
127
128 # dogcam setup. not using atm
129 # case $HOSTNAME in
130 # lj|li)
131 # /a/bin/webcam/install-server
132 # ;;
133 # kw)
134 # /a/bin/webcam/install-client
135 # ;;
136 # esac
137
138
139 ## not actually using prometheus just yet
140 # # office is not exposed to internet yet
141 # if [[ $HOSTNAME != kw ]]; then
142 # ## prometheus node exporter setup
143 # web-conf -f 9100 -p 9101 apache2 $(hostname -f) <<'EOF'
144 # #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
145 # # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
146 # <Location />
147 # AllowOverride None
148 # AuthType basic
149 # AuthName "Authentication Required"
150 # # setup one time, with root:www-data, 640
151 # AuthUserFile "/etc/prometheus-htpasswd"
152 # Require valid-user
153 # </Location>
154 # EOF
155 # fi
156
157
158 pi debootstrap
159 ######### begin universal pinned packages ######
160 case $(debian-codename) in
161 nabia|etiona|flidas)
162 sudo rm -fv /etc/apt/preferences.d/etiona-buster
163 sd /etc/apt/preferences.d/trisquel-debian <<EOF
164 Explanation: Debian* includes Debian + Debian Backports
165 Package: *
166 Pin: release o=Debian*
167 Pin-Priority: -100
168 EOF
169 ;;&
170 # needed for debootstrap scripts for fai since fai requires debian
171 flidas)
172 # moved to fai
173 #curl http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg | s apt-key add -
174 sd /etc/apt/preferences.d/flidas-xenial <<EOF
175 Package: *
176 Pin: release a=xenial
177 Pin-Priority: -100
178
179 Package: *
180 Pin: release a=xenial-updates
181 Pin-Priority: -100
182
183 Package: *
184 Pin: release a=xenial-security
185 Pin-Priority: -100
186
187 Package: firefox
188 Pin: release n=xenial
189 Pin-Priority: 500
190 EOF
191 sd /etc/apt/sources.list.d/xenial.list 2>/dev/null <<EOF
192 deb http://us.archive.ubuntu.com/ubuntu/ xenial main
193 deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main
194 deb http://us.archive.ubuntu.com/ubuntu/ xenial-security main
195 EOF
196
197 if ! apt-key list | grep /C0B21F32 &>/dev/null; then
198 # moved to fai
199 #sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
200 sd /etc/apt/preferences.d/flidas-bionic <<EOF
201 Package: *
202 Pin: release a=bionic
203 Pin-Priority: -100
204
205 Package: *
206 Pin: release a=bionic-updates
207 Pin-Priority: -100
208
209 Package: *
210 Pin: release a=bionic-security
211 Pin-Priority: -100
212 EOF
213 fi
214
215 # better to run btrfs-progs which matches our kernel version
216 # (note, renamed from btrfs-tools)
217 sd /etc/apt/preferences.d/btrfs-progs <<EOF
218 Package: btrfs-progs libzstd1
219 Pin: release a=bionic
220 Pin-Priority: 1005
221
222 Package: btrfs-progs libzstd1
223 Pin: release a=bionic-updates
224 Pin-Priority: 1005
225
226 Package: btrfs-progs libzstd1
227 Pin: release a=bionic-security
228 Pin-Priority: 1005
229 EOF
230
231
232 t=$(mktemp)
233 cat >$t <<EOF
234 deb http://us.archive.ubuntu.com/ubuntu/ bionic main
235 deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main
236 deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main
237 EOF
238 f=/etc/apt/sources.list.d/bionic.list
239 if ! diff -q $t $f; then
240 sudo cp $t $f
241 sudo chmod 644 $f
242 m p update
243 fi
244
245 # no special reason, but its better for btrfs-progs to
246 # be closer to our kernel version
247 pi btrfs-progs
248
249 if [[ ! -e /usr/share/debootstrap/scripts/xenial ]]; then
250 t=$(mktemp -d)
251 cd $t
252 m aptitude download debootstrap/xenial
253 m ex ./*
254 sudo cp ./usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
255 fi
256
257 sd /etc/apt/preferences.d/flidas-etiona <<EOF
258 Package: *
259 Pin: release a=etiona
260 Pin-Priority: -100
261
262 Package: *
263 Pin: release a=etiona-updates
264 Pin-Priority: -100
265
266 Package: *
267 Pin: release a=etiona-security
268 Pin-Priority: -100
269
270 Package: *
271 Pin: release a=etiona-backports
272 Pin-Priority: -100
273 EOF
274
275 t=$(mktemp)
276 cat >$t <<EOF
277 deb http://mirror.fsf.org/trisquel/ etiona main
278 deb http://mirror.fsf.org/trisquel/ etiona-updates main
279 deb http://archive.trisquel.info/trisquel/ etiona-security main
280 deb http://mirror.fsf.org/trisquel/ etiona-backports main
281 EOF
282 f=/etc/apt/sources.list.d/etiona.list
283 if ! diff -q $t $f; then
284 sudo cp $t $f
285 n s chmod 644 $f
286 m p update
287 fi
288
289 sd /etc/apt/preferences.d/debian-goodies <<EOF
290 Package: debian-goodies
291 Pin: release n=etiona
292 Pin-Priority: 1005
293 EOF
294
295
296 # dont use buster because it causes dist-upgrade to think its downgrading
297 # packages while really just reinstalling the same version.
298 f=/etc/apt/apt.conf.d/01iank
299 sudo rm -fv $f
300 # # stupid buster uses some key algorithm not supported by flidas gpg that apt uses.
301 # sd /etc/apt/apt.conf.d/01iank <<'EOF'
302 # Acquire::AllowInsecureRepositories "true";
303 # EOF
304
305 f=/etc/apt/sources.list.d/buster.list
306 sudo rm -fv $f
307
308 # newer version needed for false positive in checkrestart.
309 # I did buster at first, but other problem above with having
310 # buster repos. not sure if the false positive exists in etiona.
311 pi debian-goodies
312
313 sd /etc/apt/preferences.d/shellcheck <<EOF
314 Package: shellcheck
315 Pin: release a=etiona
316 Pin-Priority: 1005
317
318 Package: shellcheck
319 Pin: release a=etiona-updates
320 Pin-Priority: 1005
321
322 Package: shellcheck
323 Pin: release a=etiona-security
324 Pin-Priority: 1005
325 EOF
326
327 sd /etc/apt/preferences.d/bash <<EOF
328 Package: bash
329 Pin: release a=etiona
330 Pin-Priority: 1005
331
332 Package: bash
333 Pin: release a=etiona-updates
334 Pin-Priority: 1005
335
336 Package: bash
337 Pin: release a=etiona-security
338 Pin-Priority: 1005
339 EOF
340
341
342 ;;&
343 nabia|etiona)
344 # for ziva
345 #p install --no-install-recommends minetest/buster libleveldb1d/buster libncursesw6/buster libtinfo6/buster
346 doupdate=false
347 for n in buster bullseye; do
348 f=/etc/apt/sources.list.d/$n.list
349 t=$(mktemp)
350 case $n in
351 buster)
352 cat >$t <<'EOF'
353 deb http://http.us.debian.org/debian buster main
354 deb-src http://http.us.debian.org/debian buster main
355
356 deb http://security.debian.org/ buster/updates main
357 deb-src http://security.debian.org/ buster/updates main
358
359 deb http://http.us.debian.org/debian buster-updates main
360 deb-src http://http.us.debian.org/debian buster-updates main
361
362 deb http://http.debian.net/debian buster-backports main
363 deb-src http://http.debian.net/debian buster-backports main
364 EOF
365 ;;
366 bullseye)
367 cat >$t <<'EOF'
368 EOF
369 cat >$t <<EOF
370 deb http://deb.debian.org/debian bullseye main
371 deb-src http://deb.debian.org/debian bullseye main
372
373 deb http://deb.debian.org/debian-security/ bullseye-security main
374 deb-src http://deb.debian.org/debian-security/ bullseye-security main
375
376 deb http://deb.debian.org/debian bullseye-updates main
377 deb-src http://deb.debian.org/debian bullseye-updates main
378
379 deb http://http.debian.net/debian bullseye-backports main
380 deb-src http://http.debian.net/debian bullseye-backports main
381 EOF
382 ;;
383 esac
384
385 if ! diff -q $t $f; then
386 doupdate=true
387 s cp $t $f
388 s chmod 644 $f
389 fi
390 done
391 if $doupdate; then
392 curl -s https://ftp-master.debian.org/keys/archive-key-10-security.asc | sudo apt-key add -
393 curl -s https://ftp-master.debian.org/keys/archive-key-10.asc | sudo apt-key add -
394 p update
395 fi
396
397 if [[ ! -e /usr/share/debootstrap/scripts/bullseye ]]; then
398 t=$(mktemp -d)
399 cd $t
400 m aptitude download debootstrap/bullseye
401 m ex ./*
402 sudo cp ./usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
403 fi
404
405 ;;&
406 etiona)
407 sd /etc/apt/preferences.d/focal <<'EOF'
408 Package: *
409 Pin: release n=focal,o=Ubuntu
410 Pin-Priority: -100
411 EOF
412
413 sd /etc/apt/preferences.d/spamassassin <<'EOF'
414 Package: spamassassin sa-compile spamc
415 Pin: release n=focal,o=Ubuntu
416 Pin-Priority: 500
417 EOF
418 sd /etc/apt/preferences.d/spamassassin <<'EOF'
419 Package: spamassassin sa-compile spamc
420 Pin: release n=focal,o=Ubuntu
421 Pin-Priority: 500
422 EOF
423 sd /etc/apt/preferences.d/psd <<'EOF'
424 Package: profile-sync-daemon
425 Pin: release n=focal,o=Ubuntu
426 Pin-Priority: 500
427 EOF
428
429 f=/etc/apt/sources.list.d/focal.list
430 t=$(mktemp)
431 cat >$t <<'EOF'
432 deb http://us.archive.ubuntu.com/ubuntu/ focal main universe
433 deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main universe
434 deb http://us.archive.ubuntu.com/ubuntu/ focal-security main universe
435 EOF
436 if ! diff -q $t $f; then
437 sudo dd if=$t of=$f 2>/dev/null
438 p update
439 fi
440
441
442
443 sd /etc/apt/preferences.d/nabia-etiona <<'EOF'
444 Package: *
445 Pin: release n=nabia*,o=Trisquel
446 Pin-Priority: -100
447 EOF
448
449 f=/etc/apt/sources.list.d/nabia.list
450 t=$(mktemp)
451 cat >$t <<'EOF'
452 deb http://mirror.fsf.org/trisquel/ nabia main
453 deb-src http://mirror.fsf.org/trisquel/ nabia main
454
455 deb http://mirror.fsf.org/trisquel/ nabia-updates main
456 deb-src http://mirror.fsf.org/trisquel/ nabia-updates main
457
458 deb http://archive.trisquel.info/trisquel/ nabia-security main
459 deb-src http://archive.trisquel.info/trisquel/ nabia-security main
460
461 # Uncomment this lines to enable the backports optional repository
462 deb http://mirror.fsf.org/trisquel/ nabia-backports main
463 deb-src http://mirror.fsf.org/trisquel/ nabia-backports main
464 EOF
465 if ! diff -q $t $f; then
466 sudo dd if=$t of=$f 2>/dev/null
467 p update
468 fi
469
470 # duplicated in fai. Pin for bionic + ubuntu so that ppas dont get
471 # matched.
472 sd /etc/apt/preferences.d/etiona-bionic <<'EOF'
473 Package: *
474 Pin: release n=bionic,o=Ubuntu
475 Pin-Priority: -100
476 Package: firefox
477 Pin: release n=bionic,o=Ubuntu
478 Pin-Priority: 500
479 EOF
480
481 sd /etc/apt/preferences.d/etiona-sa <<'EOF'
482 Package: *
483 Pin: release n=bionic,o=Ubuntu
484 Pin-Priority: -100
485 EOF
486
487 ;;&
488 *)
489 if isdeb; then
490 pi debian-goodies shellcheck
491 fi
492 ;;
493 esac
494
495
496
497 case $codename_compat in
498 focal)
499 sd /etc/apt/preferences.d/nabia-btrfs-progs <<'EOF'
500 Package: btrfs-progs
501 Pin: release a=buster-backports
502 Pin-Priority: 500
503 EOF
504 p install btrfs-progs
505 ;;
506 esac
507
508
509 # 2020-03-03 old file
510 s rm -fv /etc/apt/preferences.d/radicale
511 ######### end universal pinned packages ######
512
513
514 case $codename in
515 etiona)
516 sd /etc/apt/preferences.d/obs <<EOF
517 Package: libfdk-aac1
518 Pin: release n=bionic
519 Pin-Priority: 500
520 EOF
521 sd /etc/apt/preferences.d/chromium <<EOF
522 Package: chromium-*
523 Pin: release n=bionic
524 Pin-Priority: 500
525 EOF
526
527 ;;
528 esac
529
530
531
532 ##### begin automatic upgrades (after checkrestart has been installed) ####
533 # if apt-config-auto-update is installed,
534 # it also has similar config, in a file 10something,
535 # but i think his overrides it since its higher number.
536 # This file was part of the automatic-updates package,
537 # and it has a configu option to not get new package lists,
538 # which seems pretty stupid to me, you cant actually upgrade
539 # anything if you dont have the new package list.
540 sd /etc/apt/apt.conf.d/20auto-upgrades <<'EOF'
541 APT::Periodic::Update-Package-Lists "1";
542 APT::Periodic::Download-Upgradeable-Packages "1";
543 APT::Periodic::AutocleanInterval "7";
544 APT::Periodic::Unattended-Upgrade "1";
545 EOF
546
547 # fyi: default file has comments about available options,
548 # you may want to read that, do pkx unattended-upgrades
549 # default is just security updates. this list found from reading
550 # match_whitelist_string() in $(which unattended-upgrades)
551 sd /etc/apt/apt.conf.d/50unattended-upgrades <<EOF
552 Unattended-Upgrade::Mail "root";
553 Unattended-Upgrade::MailOnlyOnError "true";
554 Unattended-Upgrade::Remove-Unused-Dependencies "true";
555 Unattended-Upgrade::Origins-Pattern {
556 "o=*,l=*,a=*,c=*,site=*,n=*";
557 };
558 EOF
559
560 # old files
561 sudo rm -f /etc/cron.d/unattended-upgrade-reboot /usr/local/bin/zelous-unattended-reboot /etc/cron.d/myupgrade
562
563 # myupgrade cron exists in /etc/cron.d/ian
564
565 ##### end automatic upgrades ####
566
567
568 # commented in case i want to use this sometime later
569 # sd /etc/apt/preferences.d/buster-backports <<EOF
570 # Package: *
571 # Pin: release a=buster-backports
572 # Pin-Priority: 500
573 # EOF
574
575 if [[ -e /etc/wireguard/wghole.conf ]]; then
576 sgo wg-quick@wghole
577 fi
578
579 ###### begin website setup
580 case $HOSTNAME in
581 li|bk|je)
582 pi bind9
583 f=/var/lib/bind/db.b8.nz
584 if [[ ! -e $f ]]; then
585 dnsb8
586 fi
587 ;;&
588 bk)
589 sgo wg-quick@wgmail
590
591 # i just dont feel like setting up a special purpose ssh key to do this automatically.
592 end_msg <<'EOF'
593 # run this once for bk on local machine:
594 # only used for old openvpn setup
595 /a/exe/vpn-mk-client-cert -c bk.b8.nz -b expertpath -n mail li.iankelling.org
596 EOF
597 end
598 ;;
599 je)
600 end
601 ;;
602 li)
603
604 m /a/h/setup.sh iankelling.org
605
606 # start mumble only when im going to use it, since i dont use it much
607 pi-nostart mumble-server
608 sudo $sed -ri "s/^ *(serverpassword=).*/\1$(< /a/bin/bash_unpublished/mumble_pass)/" /etc/mumble-server.ini
609
610 # do certificate to avoid warning about unsigned cert,
611 # which is overkill for my use, but hey, I'm cool, I know
612 # how to do this.
613 m web-conf apache2 mumble.iankelling.org
614 sudo rm -fv /etc/apache2/sites-enabled/mumble.iankelling.org
615
616 # general vpn for as needed use
617 vpn-server-setup -d -r -4 10.5.5 -p 443 -n hole
618
619 # todo: consider if this should exist for the
620 # other vpn server
621 teeu /etc/openvpn/server/hole.conf <<'EOF'
622 client-to-client
623 EOF
624
625 # sullivan d8
626 sd /etc/openvpn/client-config-hole/sd8 <<'EOF'
627 ifconfig-push 10.5.5.41 255.255.255.0
628 EOF
629 # hsieh d8
630 sd /etc/openvpn/client-config-hole/hd8 <<'EOF'
631 ifconfig-push 10.5.5.42 255.255.255.0
632 EOF
633
634 sd /etc/openvpn/client-config-hole/onep9 <<'EOF'
635 ifconfig-push 10.5.5.14 255.255.255.0
636 EOF
637 sd /etc/openvpn/client-config-hole/sy <<'EOF'
638 ifconfig-push 10.5.5.12 255.255.255.0
639 EOF
640 sd /etc/openvpn/client-config-hole/kw <<'EOF'
641 ifconfig-push 10.5.5.9 255.255.255.0
642 EOF
643 sd /etc/openvpn/client-config-hole/x3 <<'EOF'
644 ifconfig-push 10.5.5.8 255.255.255.0
645 EOF
646 sd /etc/openvpn/client-config-hole/x2 <<'EOF'
647 ifconfig-push 10.5.5.7 255.255.255.0
648 EOF
649 sd /etc/openvpn/client-config-hole/wclient <<'EOF'
650 ifconfig-push 10.5.5.6 255.255.255.0
651 EOF
652 sd /etc/openvpn/client-config-hole/frodo <<'EOF'
653 ifconfig-push 10.5.5.5 255.255.255.0
654 EOF
655 sd /etc/openvpn/client-config-hole/amy <<'EOF'
656 ifconfig-push 10.5.5.3 255.255.255.0
657 EOF
658 sd /etc/openvpn/client-config-hole/kd <<'EOF'
659 ifconfig-push 10.5.5.2 255.255.255.0
660 EOF
661
662 # for adding to current system:
663 #vpn-mk-client-cert -s "" -n hole 72.14.176.105
664 # adding to remove system 107,
665 #vpn-mk-client-cert -s "" -n hole -c 10.2.0.107 -b hd8 iankelling.org
666 #
667 # for wireguard hole vpn
668 # wghole
669
670 # requested from linode via a support ticket.
671 # https://www.linode.com/docs/networking/an-overview-of-ipv6-on-linode/
672 # ipv6 stuff pieced together
673 # via slightly wrong information from
674 # https://github.com/angristan/openvpn-install/blob/master/openvpn-install.sh
675 # https://community.openvpn.net/openvpn/wiki/IPv6
676 # and man openvpn.
677 #
678 # This uses a public /64, but afaik, that is not needed for my
679 # current use case, since I'm doing ipv6 nat, they could be private
680 # and nat to a public address. I'm doing ipv6 nat in order to have 2
681 # vpn clients that externally share the same ip when sending so they
682 # share ip reputation. Note, the eth0 and tunx needed to be
683 # different subnets. On the same, I saw some neighbor packet go
684 # unanswered, tcpdump showed packets getting lost. I tried splitting the
685 # /64, it didn't work but I didn't investigate closely.
686
687
688 # not starting as i intend to replace it
689 m vpn-server-setup -s -i tunmail -n mail -d -6 2600:3c00:e002:3800::/64 2600:3c00:e002:3800::1/64
690 sudo tee /etc/openvpn/client-config-mail/mailclient <<'EOF'
691 ifconfig-push 10.8.0.4 255.255.255.0
692 ifconfig-ipv6-push 2600:3c00:e002:3800::4/64
693 EOF
694 sudo tee /etc/openvpn/client-config-mail/expertpath <<'EOF'
695 ifconfig-push 10.8.0.5 255.255.255.0
696 ifconfig-ipv6-push 2600:3c00:e002:3800::5/64
697 EOF
698
699
700 sudo dd of=/etc/systemd/system/vpn-mail-forward.service <<'EOF'
701 [Unit]
702 Description=Turns on iptables mail nat
703 BindsTo=openvpn-server@mail.service
704
705 [Service]
706 Type=oneshot
707 RemainAfterExit=yes
708 ExecStart=/a/bin/distro-setup/vpn-mail-forward tunmail start
709 ExecStop=/a/bin/distro-setup/vpn-mail-forward tunmail stop
710
711 [Install]
712 RequiredBy=openvpn-server@mail.service
713 EOF
714 ser daemon-reload
715
716
717 # needed for li's local mail delivery.
718 tu /etc/hosts <<<"10.8.0.4 mx.iankelling.org"
719
720 # wgmail handles this.
721 #sgo vpn-mail-forward.service
722 # old:
723 #sgo openvpn-server@mail
724 sgo wg-quick@wgmail
725
726 # setup let's encrypt cert
727 m web-conf apache2 mail.iankelling.org
728 # TODO, i expanded the above cert manually to mx.iankelling.org, this should be captured
729 # in the automation here. We use mail.iankelling.org as our ehlo name when sending mail
730 # but our mx record is mx.iankelling.org. Initially I was just using mail.iankelling.org,
731 # but the problem is I want multiple ips to be able to identify as mail.iankelling.org,
732 # but a subset to be mx.iankelling.org. Afaik, there is no problem with having
733 # our mail cert be for mail.iankelling.org, and have people connect to mx.ian...,
734 # but it doesn't make logical sense to do this.
735 sudo rm -fv /etc/apache2/sites-enabled/mail.iankelling.org{,-redir}.conf
736 ser reload apache2
737
738 a2enmod -q proxy proxy_http
739 domain=cal.iankelling.org
740 web-conf -f 10.8.0.4:5232 - apache2 $domain <<'EOF'
741 # https://radicale.org/2.1.html
742 #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
743 # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
744 <Location /radicale/>
745 Options +FollowSymLinks +Multiviews +Indexes
746 AllowOverride None
747 AuthType basic
748 AuthName "Authentication Required"
749 # setup one time, with root:www-data, 640
750 AuthUserFile "/etc/caldav-htpasswd"
751 Require valid-user
752 RequestHeader set X-Script-Name /radicale/
753 RequestHeader set X-Remote-User expr=%{REMOTE_USER}
754 ProxyPass "http://10.8.0.4:5232/" retry=0
755 ProxyPassReverse "http://10.8.0.4:5232/"
756 </Location>
757 EOF
758 # nginx version of above would be:
759 # auth_basic "Not currently available";
760 # auth_basic_user_file /etc/nginx/caldav/htpasswd;
761
762
763
764 ###### begin znc setup #####
765 pi znc
766
767 # https://wiki.znc.in/FAQ seems to imply that znc doesn\'t need restart after cert change.
768 # to get into the web interface,
769 # then use non-main browser or else it doebsn't allow it based on ocsp stapling from my main site.
770 # https://iankelling.org:12533/
771 # login as ian, pass is in pass store, the part after :
772
773 # znc config generated by doing
774 # znc --makeconf
775 # selected port is also used in erc config
776 # comma separated channel list worked.
777 # while figuring things out, running znc -D for debug in foreground.
778 # to exit and save config:
779 # /msg *status shutdown
780 # configed auth on freenode by following
781 # https://wiki.znc.in/Sasl:
782 # /query *sasl
783 # RequireAuth yes
784 # Mechanism PLAIN
785 # Set MyNickservName pa$$w0rd
786 # created the system service after, and had to do
787 # mv /home/iank/.znc/* /var/lib/znc
788 # sed -i 's,/home/iank/.znc/,/var/lib/znc,' /var/lib/znc/config/znc.conf
789 # and made a copy of the config files into /p/c
790 # /msg *status LoadMod --type=global log -sanitize
791 # todo: in config file AllowWeb = true should be false. better security if that is off unless we need it.
792 # /msg *status LoadMod --type=network perform
793 # /query *perform add PRIVMSG ChanServ :invite #fsf-office
794 # /msg *perform add JOIN #fsf-office
795 # /msg *status LoadMod NickServ
796 #
797 # i set Buffer = 500
798 # also ran /znc LoadMod clearbufferonmsg
799 # it would be nice if erc supported erc query buffers by doing
800 # /msg *status clearbuffer <name of the query/receiver
801 # on killing the,
802 # an example seems to be here: https://github.com/zenspider/elisp/blob/master/rwd-irc.el
803 # if that was the case i could remove the module clearbufferonmsg
804 # also would be nice if erc supported
805 # https://wiki.znc.in/self-message
806 # https://wiki.znc.in/Query_buffers \
807 #
808 if ! getent passwd znc > /dev/null; then
809 sudo useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
810 fi
811 sudo chmod 700 /var/lib/znc
812 sudo chown -R znc:znc /var/lib/znc
813 # Avoid restarting if possible, reconnecting to irc is annoying.
814 # The unit file was made active with conflink.
815 # Note, avoid using ser here because we wrap sudo to prints the command first.
816 if [[ $(systemctl is-active znc) != active ]]; then
817 sgo znc
818 fi
819 ###### stop znc setup #####
820
821 end
822 ;;
823 esac
824 ###### end website setup
825
826 ########### end section including li/lj ###############
827
828
829 #### desktop stuff
830
831 ### system76 things ###
832 case $HOSTNAME in
833 sy)
834 # note, i stored the initial popos packages at /a/bin/data/popos-pkgs
835 if [[ ! -e /etc/apt/sources.list.d/system76.list ]]; then
836 # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
837 sd /etc/apt/sources.list.d/system76.list <<EOF
838 deb http://ppa.launchpad.net/system76-dev/stable/ubuntu $codename_compat main
839 deb-src http://ppa.launchpad.net/system76-dev/stable/ubuntu $codename_compat main
840 EOF
841 s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5D1F3A80254F6AFBA254FED5ACD442D1C8B7748B
842 p update
843 # https://support.system76.com/articles/install-ubuntu/
844 # but i'm hoping this is not needed
845 # sd /etc/apt/preferences.d/system76 <<'EOF'
846 # Package: *
847 # Pin: release o=LP-PPA-system76-dev-stable
848 # Pin-Priority: 1001
849 # EOF
850 pi system76-driver system76-firmware-cli
851 # if you get a notice about a firmware update, the notifier on i3
852 # is too dumb to do anything when you click it. so to see
853 # a changelog, cd to
854 # /var/cache/system76-firmware-daemon
855 # extract the xz files there, one will contain a changelog.
856 # then to install an update:
857 # s system76-firmware-cli schedule
858 fi
859 ;;
860 esac
861
862 case $distro in
863 trisquel|ubuntu)
864
865 # ppa:obsproject/obs-studio
866 if [[ ! -d /etc/apt/sources.list.d/obs.list ]]; then
867 # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
868 sd /etc/apt/sources.list.d/obs.list <<EOF
869 deb http://ppa.launchpad.net/obsproject/obs-studio/ubuntu $codename_compat main
870 deb-src http://ppa.launchpad.net/obsproject/obs-studio/ubuntu $codename_compat main
871 EOF
872 s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BC7345F522079769F5BBE987EFC71127F425E228
873 p update
874 fi
875 ;;
876 esac
877
878 case $codename_compat in
879 xenial)
880 # mate-indicator-applet and beyond are msc things I noticed diffing a
881 # standard install with mine.
882 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras mate-indicator-applet anacron
883 ;;
884 stretch)
885 pi task-mate-desktop
886 ;;
887 buster)
888 # todo: figure out mate for buster
889 # pi task-gnome-desktop
890 ;;
891 bionic|focal)
892 # i had installing mate-indicator-applet, but im not sure why so i removed
893 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras anacron
894
895 # pi gnome-core
896 # # apt-get update periodically fails with an appstream error.
897 # # this removes gnome-core, but its just a package for dependencies
898 # p -y remove appstream
899
900
901 # by default, it sleeps when not logged in to x/wayland and on ac power.
902 # stop that.
903 if id -u gdm &>/dev/null; then
904 sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
905 m systemctl --user stop gvfs-daemon
906 m systemctl --user disable gvfs-daemon
907 fi
908 ;;&
909 focal)
910 # lightdm startup fails without this. on etiona, we got unity-greeter installed automatically,
911 # it would probably work on nabia too, but google just lead me to this and it works fine.
912 pi lightdm-gtk-greeter
913 # ok, this is really weird
914 # normally this file has
915 sd /etc/X11/Xsession.d/99x11-common_start <<'EOF'
916 # this is very odd.
917 # this file normally just has: exec $STARTUP
918 # but then ~/.xsession-errors
919 # says $STARTUP is not found, which appears to be the real
920 # error, but normal bash doesnt operate that way.
921 # https://bugs.launchpad.net/ubuntu/+source/im-config/+bug/1879352
922 eval exec $STARTUP
923 EOF
924 # also, gdm wayland was default, had to do
925 # dpkg-reconfigure gdm3
926 # and choose lightdm.
927 #
928 ;;
929 esac
930
931
932 if [[ $codename_compat == flidas ]]; then
933 # doesnt exist in newer
934 pi gnupg-doc
935 fi
936
937
938 case $distro in
939 trisquel)
940 case $codename in
941 *)
942 # firefox would work here too, apt would select abrowser.
943 # and the update-alternatives thing i think is becuz firefox is
944 # generally available before abrowser and this helps fix things
945 # up when we have both.
946 pi abrowser
947 s update-alternatives --set x-www-browser /usr/bin/abrowser
948 ;;
949 esac
950 ;;
951 ubuntu)
952 pi firefox
953 ;;
954 debian)
955 pi firefox-esr
956 ;;
957 esac
958
959 # newer distros just use adb for package name it seems
960 case $codename_compat in
961 bionic|stretch)
962 pi android-tools-adbd
963 ;;
964 esac
965
966 case $codename_compat in
967 focal)
968 pi libext2fs-dev libzstd-dev
969 cd /a/opt/btrfs-progs
970 ;;
971 esac
972
973
974 case $codename_compat in
975 bionic)
976 pi python-vte
977 ;;
978 *)
979 pi reportbug-gtk
980 ;;
981 esac
982
983 # not packaged in newer distros it seems
984 case $codename_compat in
985 bionic|buster|stretch)
986 pi dtrx
987 ;;
988 esac
989
990
991 # TODO: some of the X programs can be removed from pall when using wayland
992
993 # depends gcc is a way to install suggests. this is apparently the only
994 # way to install suggests even if the main package is already
995 # installed. reinstall doesn't work, uninstalling can cause removing
996 # dependent packages.
997 pi ${pall[@]} $(apt-cache search ruby[.0-9]+-doc| awk '{print $1}') $($src/distro-pkgs)
998
999
1000 # commented, not worth the hassle i think.
1001 #seru enable psd
1002 #seru start psd
1003
1004
1005 # old filename
1006 sudo rm -fv /etc/systemd/resolved.conf.d/iank.conf
1007
1008 # website is dead june 14 2019. back in october, but meh
1009 sudo rm -fv /etc/apt/sources.list.d/iridium-browser.list
1010 # case $distro in
1011 # debian)
1012 # pi chromium ;;
1013 # trisquel|ubuntu)
1014 # wget -qO - https://downloads.iridiumbrowser.de/ubuntu/iridium-release-sign-01.pub|sudo apt-key add -
1015 # t=$(mktemp)
1016 # cat >$t <<EOF
1017 # deb [arch=amd64] https://downloads.iridiumbrowser.de/deb/ stable main
1018 # #deb-src https://downloads.iridiumbrowser.de/deb/ stable main
1019 # EOF
1020 # f=/etc/apt/sources.list.d/iridium-browser.list
1021 # if ! diff -q $t $f; then
1022 # s cp $t $f
1023 # s chmod 644 $f
1024 # p update
1025 # fi
1026 # pi iridium-browser
1027 # ;;
1028 # esac
1029
1030
1031 ### begin home vpn server setup
1032
1033
1034 # # this section done initially to make persistent keys.
1035 # # Also note, I temporarily set /etc/hosts so my host was
1036 # # b8.nz when running this, since the vpn client config
1037 # # generator assumes we need to go to that server to get
1038 # # server keys.
1039 # vpn-server-setup -rds
1040 # s cp -r --parents /etc/openvpn/easy-rsa/keys /p/c/filesystem
1041 # s chown -R 1000:1000 /p/c/filesystem/etc/openvpn/easy-rsa/keys
1042 # # kw = kgpe work machine.
1043 # for host in x2 x3 kw; do
1044 # vpn-mk-client-cert -b $host -n home b8.nz 1196
1045 # dir=/p/c/machine_specific/$host/filesystem/etc/openvpn/client
1046 # mkdir -p $dir
1047 # s bash -c "cp /etc/openvpn/client/home* $dir"
1048 # # note: /etc/update-resolv-conf-home also exists for all systems with /p
1049 # done
1050
1051 # key already exists, so this won't generate one, just the configs.
1052 # m vpn-server-setup -rds
1053 # sudo tee -a /etc/openvpn/server/server.conf <<'EOF'
1054 # push "dhcp-option DNS 10.0.0.1"
1055 # push "route 10.0.0.0 255.255.0.0"
1056 # client-connect /a/bin/distro-setup/vpn-client-connect
1057 # EOF
1058 # sudo sed -i --follow-symlinks 's/10.8./10.9./g;s/^\s*port\s.*/port 1196/' /etc/openvpn/server/server.conf
1059
1060 # if [[ $HOSTNAME == tp ]]; then
1061 # if [[ -e /lib/systemd/system/openvpn-server@.service ]]; then
1062 # vpn_service=openvpn-server@server
1063 # else
1064 # vpn_service=openvpn@server
1065 # fi
1066 # sgo $vpn_service
1067 # fi
1068 ### end vpn server setup
1069
1070 ##### rss2email
1071 if mountpoint /p &>/dev/null; then
1072 # note, see bashrc for more documentation.
1073 pi rss2email
1074 sd /etc/systemd/system/rss2email.service <<'EOF'
1075 [Unit]
1076 Description=rss2email
1077 After=multi-user.target
1078
1079 [Service]
1080 User=iank
1081 Type=oneshot
1082 # about 24 hours of failures
1083 # it copies over its files without respecting symlinks, so
1084 # we pass options to use different location.
1085 ExecStart=/usr/local/bin/sysd-mail-once -288 rss2email r2e -d /p/c/rss2email.json -c /p/c/rss2email.cfg run
1086 EOF
1087 sd /etc/systemd/system/rss2email.timer <<'EOF'
1088 [Unit]
1089 Description=rss2email
1090
1091 [Timer]
1092 # for initial run. required.
1093 OnActiveSec=30
1094 # for subsequent runs.
1095 OnUnitInactiveSec=300
1096
1097 [Install]
1098 WantedBy=timers.target
1099 EOF
1100 sudo systemctl daemon-reload
1101 fi
1102
1103
1104 ######### begin irc periodic backup #############
1105 if [[ $HOSTNAME == frodo ]]; then
1106 sd /etc/systemd/system/ircbackup.service <<'EOF'
1107 [Unit]
1108 Description=irc li backup
1109 After=multi-user.target
1110
1111 [Service]
1112 User=iank
1113 Type=oneshot
1114 ExecStart=/usr/local/bin/sysd-mail-once irc-backup rsync -rlptDhSAX root@iankelling.org:/var/lib/znc/moddata/log/iank/freenode/ /k/irclogs
1115 EOF
1116 sd /etc/systemd/system/ircbackup.timer <<'EOF'
1117 [Unit]
1118 Description=irc li backup hourly
1119
1120 [Timer]
1121 OnCalendar=hourly
1122
1123 [Install]
1124 WantedBy=timers.target
1125 EOF
1126 sudo systemctl daemon-reload
1127 sgo ircbackup.timer
1128 fi
1129
1130
1131 ######### end irc periodic backup #############
1132
1133
1134 pi-nostart openvpn
1135 # pi-nostart does not disable
1136 ser disable openvpn
1137
1138
1139 if [[ -e /p/c/gen-fsf-vpn ]]; then
1140 /p/c/gen-fsf-vpn
1141 fi
1142
1143 if [[ -e /p/c/machine_specific/$HOSTNAME/filesystem/etc/openvpn/client/hole.crt ]]; then
1144 sgo openvpn-client@hole
1145 fi
1146
1147 if [[ $HOSTNAME == frodo ]]; then
1148 vpn-mk-client-cert -b frodo -n hole iankelling.org
1149 fi
1150
1151 ############# begin syncthing setup ###########
1152 if [[ $HOSTNAME == frodo ]]; then
1153 # It\'s simpler to just worry about running it in one place for now.
1154 # I assume it would work to clone it\'s config to another non-phone
1155 # and just run it in one place instead of the normal having a
1156 # separate config. I lean toward using the same config, since btrfs
1157 # syncs between comps.
1158 # testing has relatively up to date packages
1159 if ! isdebian-testing; then
1160 # based on error when doing apt-get update:
1161 # E: The method driver /usr/lib/apt/methods/https could not be found.
1162 pi apt-transport-https
1163 # google led me here:
1164 # https://apt.syncthing.net/
1165 curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
1166 s="deb http://apt.syncthing.net/ syncthing release"
1167 if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != "$s" ]]; then
1168 echo "$s" | sd /etc/apt/sources.list.d/syncthing.list
1169 p update
1170 fi
1171 fi
1172 pi syncthing
1173 m lnf -T /w/syncthing /home/iank/.config/syncthing
1174 ser daemon-reload # syncthing likely not properly packaged
1175 sgo syncthing@iank # runs as iank
1176
1177 # these things persist in ~/.config/syncthing, which I save in
1178 # /w/syncthing (not in /p, because syncthing should continue to
1179 # run on home server even when using laptop as primary device)
1180 # open http://localhost:8384/
1181 # change listen address from default to tcp://:22001,
1182 # this is because we do port forward so it doesn\'t have to use
1183 # some external server, but the syncthing is broken for port forward,
1184 # you get a message, something "like connected to myself, this should not happen"
1185 # when connecting to other local devices, so I bump the port up by 1,
1186 # based on
1187 # https://forum.syncthing.net/t/connected-to-myself-should-not-happen/1763/19.
1188 # Without this, it was being stuck syncing at 0%.
1189 # Set gui username and password.
1190 #
1191 # install syncthing via f-droid,
1192 # folder setting, turn off send only.
1193 # on phone, add device, click bar code icon
1194 # on dekstop, top right, actions, device id
1195 # after adding, notification will appear on desktop to confirm
1196 #
1197 # syncing folder. from phone to desktop: select desktop in the
1198 # folder on phone\'s sync options, notification will appear in
1199 # desktop\'s web ui within a minute. For the reverse, the
1200 # notification will appear in android\'s notifications, you have to
1201 # swipe down and tap it to add the folder. It won\'t appear in the
1202 # syncthing ui, which would be intuitive, but don\'t wait for it
1203 # there. The notification may not work, instead open the web gui
1204 # from in the app, there should be a notification within there.
1205 #
1206 # On phone, set settings to run syncthing all the time, and
1207 # show no notification.
1208 #
1209 # Folder versioning would make sense if I didn\'t already use btrfs
1210 # for backups. I would choose staggered, or trash can for more space.
1211 #
1212 # if needed to install on a remote comp:
1213 # ssh -L 8384:localhost:8384 -N frodo
1214 # open http://localhost:8384/
1215 #
1216 # Note, the other thing i did was port forward port 22000,
1217 # per https://docs.syncthing.net/users/firewall.html
1218
1219 fi
1220 ############# end syncthing setup ###########
1221
1222
1223
1224 ####### begin misc packages ###########
1225
1226 # template
1227 case $codename in
1228 flidas)
1229 :
1230 ;;
1231 esac
1232
1233 sudo update-alternatives --set pinentry /usr/bin/pinentry-gtk-2
1234
1235
1236 # sakura config is owned by ian
1237 m reset-sakura
1238 m reset-konsole
1239 m sudo -u user2 -i reset-konsole
1240 # user2 xscreensaver we don't want to reset
1241 m reset-xscreensaver
1242
1243
1244 # this would install from cabal for newer / consistent version across os, but it screws up xmonad, so disabled for now.
1245 # this is also in primary-setup
1246 # pi libxss-dev # dependency based on build failure
1247 # cabal update
1248 # cabal install --upgrade-dependencies --force-reinstalls arbtt
1249 # also, i assume syncing this between machines somehow messed up the data.
1250 if mountpoint /p &>/dev/null; then
1251 case $codename in
1252 etiona|nabia)
1253 pi arbtt
1254 # same as seru enable arbtt, but works over ssh when systemctl --user causes error:
1255 # Failed to connect to bus: No such file or directory
1256 lnf -T /a/bin/ds/subdir_files/.config/systemd/user/arbtt.service /home/iank/.config/systemd/user/default.target.wants/arbtt.service
1257 # allow failure
1258 seru start arbtt ||:
1259 ;;
1260 esac
1261 fi
1262
1263
1264 m primary-setup
1265
1266 if [[ ! -e ~/.linphonerc && -e /p/.linphonerc-initial ]]; then
1267 m cp /p/.linphonerc-initial ~/.linphonerc
1268 fi
1269
1270 # linphone in t10 wont do dns with systemd-resolved or something
1271 s teeu /etc/hosts <<'EOF'
1272 74.94.156.215 watson.fsf.org
1273 EOF
1274
1275
1276
1277 ### begin spd install
1278 if mountpoint /p &>/dev/null; then
1279 pi libswitch-perl libdigest-md5-file-perl libgnupg-interface-perl
1280 t=$(mktemp)
1281 m wget -O $t http://mirror.fsf.org/fsfsys-trisquel/fsfsys-trisquel/pool/main/s/spd-perl/spd-perl_0.2-1_amd64.deb
1282 sudo dpkg -i $t
1283 m rm $t
1284 # this guesses at the appropriate directory, adjust if needed
1285 perldir=(/usr/lib/x86_64-linux-gnu/perl/5.*)
1286 m sudo ln -sf ../../../perl/5.18.2/SPD/ ${perldir[0]}
1287 # newer distro had gpg2 as default, older one, flidas, need to make it that way
1288 gpgpath=$(which gpg2) ||:
1289 if [[ $gpgpath ]]; then
1290 sudo mkdir -p /usr/local/spdhackfix
1291 s lnf -T $gpgpath /usr/local/spdhackfix/gpg
1292 fi
1293 fi
1294 ### end spd install
1295
1296
1297 # nagstamon setting which were set through the ui
1298 # monitor url https://klaxon.fsf.org/cgi-bin
1299 # monitor url cgi https://klaxon.fsf.org/cgi-bin
1300 # in filters tab:
1301 # all unknown services
1302 # all warning services
1303 # acknowledged hosts & services
1304 # hosts & services down for maintenence
1305 # services on down hosts
1306 # services on hosts in maintenece
1307 # services on unreachable osts
1308 # hosts in soft state
1309 # services in soft state
1310 # in display tab: fullscreen
1311
1312 # these translate to these settings I think
1313 # filter_acknowledged_hosts_services = True
1314 # filter_all_unknown_services = True
1315 # filter_all_warning_services = True
1316 # filter_hosts_in_soft_state = True
1317 # filter_hosts_services_maintenance = True
1318 # filter_services_in_soft_state = True
1319 # filter_services_on_down_hosts = True
1320 # filter_services_on_hosts_in_maintenance = True
1321 # filter_services_on_unreachable_hosts = True
1322 # notify_if_up = False
1323 # statusbar_floating = False
1324 # fullscreen = True
1325 # but i'm just going to rely on the webpage plus sms for now.
1326
1327
1328 # it asks if it should make users in it's group capture packets without root,
1329 # which is arguably more secure than running wireshark as root. default is no,
1330 # which is what i prefer, since I plan to use tcpdump to input to wireshark.
1331 s DEBIAN_FRONTEND=noninteractive pi wireshark-gtk
1332
1333 # /run and /dev/shm are listed as required for pulseaudio. All 4 in the group
1334 # listed in the default config as suggested.
1335 # /run/usr/1000 i noticed was missing for pulseaudio
1336 # /run/user/0 just seemed like a not bad idea, given the above
1337 tu /etc/schroot/desktop/fstab <<'EOF'
1338 /p /p none rw,bind 0 0
1339 /a /a none rw,bind 0 0
1340 /run /run none rw,bind 0 0
1341 /run/lock /run/lock none rw,bind 0 0
1342 /dev/shm /dev/shm none rw,bind 0 0
1343 /run/shm /run/shm none rw,bind 0 0
1344 /run/user/1000 /run/user/1000 none rw,bind 0 0
1345 /run/user/1001 /run/user/1001 none rw,bind 0 0
1346 /run/user/0 /run/user/0 none rw,bind 0 0
1347 EOF
1348
1349 sd /etc/systemd/system/schrootupdate.service <<'EOF'
1350 [Unit]
1351 Description=schrootupdate
1352 After=multi-user.target
1353
1354 [Service]
1355 Type=oneshot
1356 ExecStart=/usr/local/bin/sysd-mail-once schrootupdate /a/bin/distro-setup/schrootupdate
1357 EOF
1358 sd /etc/systemd/system/schrootupdate.timer <<'EOF'
1359 [Unit]
1360 Description=schrootupdate
1361
1362 [Timer]
1363 OnCalendar=*-*-* 04:20:00
1364
1365 [Install]
1366 WantedBy=timers.target
1367 EOF
1368 ser daemon-reload
1369 sgo schrootupdate.timer
1370
1371
1372
1373 # for my roommate
1374 case $distro in
1375 trisquel)
1376 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/bullseye.list/BULLSEYE_FREE \
1377 debian bullseye firefox-esr pulseaudio chromium anki
1378 case $(debian-codename) in
1379 etiona|nabia)
1380 # we have a lot of t8 stuff, useful to have
1381 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/flidas.list/FLIDAS \
1382 trisquel flidas
1383 tu /nocow/schroot/flidas/etc/sudoers <<EOF
1384 $USER ALL=(ALL) NOPASSWD: ALL
1385 Defaults env_keep += SUDOD
1386 Defaults always_set_home
1387 Defaults !umask
1388 EOF
1389 sd /nocow/schroot/flidas//etc/locale.gen <<'EOF'
1390 en_US.UTF-8 UTF-8
1391 EOF
1392 s schroot -c flidas locale-gen
1393 s schroot -c flidas update-locale LANG=en_US.UTF-8
1394 ;;
1395 esac
1396 ;;
1397 debian)
1398 pi chromium
1399 ;;
1400 esac
1401
1402 sudo mkdir -p /nocow/user
1403 sudo chown $USER:$USER /nocow/user
1404 pi anki
1405
1406
1407 ####### begin transmission
1408
1409 case $HOSTNAME in
1410 frodo)
1411 tdir=/i/k
1412 ;;
1413 kd)
1414 tdir=/d/tor
1415 ;;
1416 *)
1417 tdir=/nocow/user/tor
1418 ;;
1419 esac
1420
1421 mkdir -p $tdir
1422
1423 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
1424 # 450 seems likely to be unused. we need to specify one or else
1425 # it won't be stable across installs.
1426 if ! getent passwd debian-transmission > /dev/null; then
1427 sudo groupadd -g 450 debian-transmission
1428 sudo adduser --quiet \
1429 --gid 450 \
1430 --uid 450 \
1431 --system \
1432 --no-create-home \
1433 --disabled-password \
1434 --home /var/lib/transmission-daemon \
1435 debian-transmission
1436 fi
1437 # We want group writable stuff from transmission.
1438 # However, after setting this, I learn that transmission sets it's
1439 # own umask based on it's settings file. Well, no harm leaving this
1440 # so it's set right from the beginning.
1441 sudo chfn debian-transmission -o umask=0002
1442
1443 # note i had to do this, which is persistent:
1444 # cd /i/k
1445 # s chgrp debian-transmission torrents partial-torrents
1446
1447 # syslog says things like
1448 # 'Failed to set receive buffer: requested 4194304, got 425984'
1449 # google suggets giving it even more than that
1450 tu /etc/sysctl.conf<<'EOF'
1451 net.core.rmem_max = 67108864
1452 net.core.wmem_max = 16777216
1453 EOF
1454 sudo sysctl -p
1455
1456 # some reason it doesn\'t seem to start automatically anyways
1457 pi-nostart transmission-daemon
1458 # be extra sure its not started
1459 ser disable transmission-daemon
1460 ser stop transmission-daemon
1461
1462 # the folder was moved here after an install around 02/2017.
1463 # it contains runtime data,
1464 # plus a simple symlink to the config file which it\'s
1465 # not worth separating out.
1466 # between comps, the uid can change
1467
1468 f=$tdir/transmission-daemon
1469 for d in $tdir/partial-torrents $tdir/torrents $f; do
1470 if [[ ! -d $d ]]; then
1471 mkdir $d
1472 fi
1473 sudo chown -R debian-transmission:user2 $d
1474 done
1475 s lnf -T $f /var/lib/transmission-daemon/.config/transmission-daemon
1476 s lnf -T /etc/transmission-daemon/settings.json $f/settings.json
1477 sudo chown -R debian-transmission:debian-transmission $f
1478 sudo chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon
1479 #
1480 # config file documented here, and it\'s the same config
1481 # for daemon vs client, so it\'s documented in the gui.
1482 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
1483 #
1484 # I originaly setup rpc-whitelist, but after using
1485 # routing to a network namespace, it doesn\'t see the
1486 # real source address, so it\'s disabled.
1487 #
1488 # Changed the cache-size to 256 mb, reduces disk use.
1489 # It is a read & write cache.
1490 sudo ruby <<EOF
1491 require 'json'
1492 p = '/etc/transmission-daemon/settings.json'
1493 File.write(p, JSON.pretty_generate(JSON.parse(File.read(p)).merge({
1494 'rpc-whitelist-enabled' => false,
1495 'rpc-authentication-required' => false,
1496 'incomplete-dir' => '$tdir/partial-torrents',
1497 'incomplete-dir-enabled' => true,
1498 'download-dir' => '$tdir/torrents',
1499 "speed-limit-up" => 800,
1500 "speed-limit-up-enabled" => true,
1501 "peer-port" => 61486,
1502 "cache-size-mb" => 256,
1503 "ratio-limit" => 5.0,
1504 "ratio-limit-enabled" => false,
1505 })) + "\n")
1506 EOF
1507
1508 ####### end transmission
1509
1510 case $HOSTNAME in
1511 kd)
1512 # to persist upload/dl metadata. initially, moved all the stuff
1513 # in /var/lib/transmission-daemon to /d/tor
1514 s usermod --home /d/tor debian-transmission
1515 sgo transmission-daemon-nn
1516
1517 ;;
1518 esac
1519
1520
1521 ######### begin transmission client setup ######
1522
1523 if [[ -e /p/transmission-rpc-pass ]]; then
1524 # arch had a default config,
1525 # debian had nothing until you start it.
1526 # With a little trial an error, here is a minimal config
1527 # taken from the generated one, plus changes that the
1528 # settings ui does, without a bunch of ui crap settings.
1529 #
1530 # only settings I set were
1531 # hostname
1532 # auto-connect
1533 # password
1534
1535 # the password is randomly generated on first run, i copied it out
1536 # so it could be used by other hosts.
1537 sudo ruby <<'EOF'
1538 require 'json'
1539 p = '/etc/transmission-daemon/settings.json'
1540 s = JSON.parse(File.read(p))
1541 s["rpc-password"] = File.read("/p/transmission-rpc-pass").chomp
1542 # default is 0022 (18 in decimal)
1543 s["umask"] = 2
1544 File.write p, JSON.pretty_generate(s)
1545 EOF
1546
1547 rpc_pass=$(</p/transmission-rpc-pass)
1548 for f in /home/*; do
1549 u=${f##*/}
1550 uid=$(id -u $u 2>/dev/null) || continue
1551 if [[ ! $uid -ge 1000 ]]; then
1552 continue
1553 fi
1554 d=$f/.config/transmission-remote-gtk
1555 sudo -u $u mkdir -p $d
1556 # i tried setting hostname to transmission.b8.nz, so i could dynamically change where
1557 # this connects to, but it said some 421 denied error when I did that. Then it
1558 # froze X when i ran it under strace. Whatever.
1559 sudo -u $u dd of=$d/config.json <<EOF
1560 {
1561 "profiles" : [
1562 {
1563 "profile-name" : "Default",
1564 "hostname" : "10.173.0.2",
1565 "rpc-url-path" : "/transmission/rpc",
1566 "username" : "",
1567 "password" : "$rpc_pass",
1568 "auto-connect" : true,
1569 "ssl" : false,
1570 "timeout" : 40,
1571 "retries" : 3,
1572 "update-active-only" : false,
1573 "activeonly-fullsync-enabled" : false,
1574 "activeonly-fullsync-every" : 2,
1575 "update-interval" : 3,
1576 "min-update-interval" : 3,
1577 "session-update-interval" : 60,
1578 "exec-commands" : [],
1579 "destinations" : []
1580 }
1581 ],
1582 "profile-id" : 0,
1583 "add-options-dialog" : false
1584 }
1585 EOF
1586 done
1587 fi
1588 ######### end transmission client setup ######
1589
1590
1591 ### printer setup
1592 pi cups
1593
1594 sudo gpasswd -a $USER lpadmin # based on ubuntu wiki
1595 # goto http://127.0.0.1:631
1596 # administration tab, add new printer button.
1597 # In debian, I could use hte recommended driver,
1598 # in arch, I had to pick out the 6L driver.
1599
1600
1601 # bridge networking as user fails. google lead here, but it doesn\'t work:
1602 # oh well, I give up.
1603 # http://wiki.qemu.org/Features-Done/HelperNetworking
1604 # s mkdir /etc/qemu
1605 # f=/etc/qemu/bridge.conf
1606 # sd $f <<'EOF'
1607 # allow br0
1608 # EOF
1609 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
1610 # s chmod 640 $f
1611
1612 # general known for debian/ubuntu, not for fedora
1613
1614 m /a/bin/buildscripts/go
1615 m /a/bin/buildscripts/rust
1616 m /a/bin/buildscripts/misc
1617 m /a/bin/buildscripts/pithosfly
1618 m /a/bin/buildscripts/alacritty
1619
1620 pi-nostart virtinst virt-manager
1621 soff libvirtd
1622 # i cant if this is whats causing it to start even though
1623 # its disabled. note: it leaves around dnsmasq instances even
1624 # if you stop it. what the hell systemd?
1625 soff libvirt-guests
1626 # allow user to run vms, from debian handbook. libvirt-qemu
1627 # based on https://www.whonix.org/wiki/KVM#First-time_User.3F
1628 for x in iank user2; do s usermod -a -G libvirt,kvm,libvirt-qemu $x; done
1629
1630
1631 pi --no-install-recommends kdeconnect
1632 ### kdeconnect for gnome. started in /a/bin/distro-setup/desktop-20-autostart.sh
1633 ### but gnome + xmonad not working in flidas, so i disabled it
1634 # pi libgtk-3-dev python3-requests-oauthlib valac cmake python-nautilus libappindicator3-dev
1635 # cd /a/opt/indicator-kdeconnect
1636 # mkdir -p build
1637 # cd build
1638 # cmake .. -DCMAKE_INSTALL_PREFIX=/usr
1639 # make
1640 # sudo make install
1641 # # we can start it manually with /usr/lib/x86_64-linux-gnu/libexec/kdeconnectd
1642 # # it seems, according to
1643 # # /etc/xdg/autostart/kdeconnectd.desktop
1644 # # I'm not seeing the icon, but the clipboard replication is working
1645
1646
1647 ### model 01 arduino support ###
1648 # https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux
1649 # also built latest arduino in /a/opt/Arduino, (just cd build; ant build; ant run )
1650 # set arduino var in bashrc,
1651 # have system config file setup too.
1652 sudo adduser $USER dialout
1653
1654 # this is for the mail command too. update-alternatives is kind of misleading
1655 # since at least it's main commands pretend mail does not exist.
1656 # bsd's mail got pulled in on some dumb dependency, i dunno how.
1657 sudo update-alternatives --set mailx /usr/bin/mail.mailutils
1658
1659 ######### end misc packages #########
1660
1661
1662 # packages I once used before and liked, but don\'t want installed now for
1663 # various reasons:
1664 # python-sqlite is used for offlineimap
1665 # lxappearance python-sqlite dolphin paman dconf-editor
1666
1667
1668
1669 ######## unfinished
1670
1671 # todo, finish configuring smart.
1672
1673 pi smartmontools
1674 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
1675 # turn on smart. background on options:
1676 # first line, -a = test everyting on all devices.
1677 # -S on, turn on disk internal saving of vendor specific info,
1678 # from google, seems like this is usually already on and fairly standard.
1679 # -o on, turn on 4 hour period non-performance degrading testing.
1680 # short test daily 2-3am, extended tests Saturdays between 3-4am:
1681 sched="-s (S/../.././02|L/../../6/03)"
1682 sudo sed -i --follow-symlinks "s#^[[:space:]]*DEVICESCAN.*#\
1683 DEVICESCAN -a -o on -S on -n standby,q $sched \
1684 -m root@mail.iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
1685
1686 # in the default configuration of at least ubuntu 14.04, resolvconf is
1687 # configured to order any nameservers associated with tun* or tap*
1688 # before the normal internet interfaces, which means they are always
1689 # consulted first. This is often slower and undesirable, ie. local dns
1690 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
1691 # can do:
1692 #sudo sed -i --follow-symlinks '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
1693 # however, this breaks dns lookup for hosts on the openvpn lan.
1694 # I can\'t figure out why hosts on the normal lan would not be
1695 # broken under the default ordering, except the host I was
1696 # testing with previously had an entry in /etc/hosts.
1697
1698 ############# end unfinished
1699
1700 ########### misc stuff
1701
1702 if [[ $HOSTNAME != frodo ]]; then
1703 s cedit hole /etc/hosts <<EOF ||:
1704 10.5.5.3 amy amy.b8.nz
1705 10.5.5.5 frodo frodo.b8.nz
1706 10.5.5.6 wclient wclient.b8.nz
1707 EOF
1708 fi
1709
1710 if [[ ! -e ~/.local/bin/pip ]]; then
1711 tmp=$(mktemp)
1712 wget -O$tmp https://bootstrap.pypa.io/get-pip.py
1713 python3 $tmp --user
1714 hash -r
1715 fi
1716
1717
1718 ### begin timetrap setup
1719 if mountpoint /p &>/dev/null; then
1720 mkdir -p ~/.timetrap/
1721 ln -sf /a/opt/timetrap_formatters ~/.timetrap/formatters
1722 if ! type -p t &>/dev/null; then
1723 pi ruby-dev libsqlite3-dev
1724 gem install --user timetrap
1725 fi
1726 fi
1727 ### end timetrap setup
1728
1729 # leftover cleanup for t9
1730 pu resolvconf
1731
1732 case $codename in
1733 # needed for debootstrap scripts for fai since fai requires debian
1734 flidas)
1735 pi dnsmasq
1736 pi-nostart network-manager
1737 # i hate networkmanager. noo, of course disabling it doesnt work
1738 # unless you add a hack. found this by doing
1739 # systemd-analyze dot > x.dot
1740 # less x.dot
1741 # /networkman
1742 soff NetworkManager
1743 soff NetworkManager-wait-online.service
1744 # make networkmanager use resolvconf instead of its own dnsmasq which
1745 # conflicts with the normal dnsmasq package.
1746 f=/etc/NetworkManager/NetworkManager.conf
1747 m=$(md5sum $f)
1748 sudo sed -ri '/ *\[main\]/,/^ *\[[^]]+\]/{/^\s*dns[[:space:]=]/d}' $f
1749 sudo sed -ri '/ *\[main\]/a dns=default' $f
1750 if [[ $m != $(md5sum $f) ]]; then
1751 srestart NetworkManager
1752 fi
1753 # networkmanager has this nasty behavior on flidas: if the machine
1754 # crashes with dnsmasq running, on subsequent boot, it adds an entry to
1755 # resolvconf for 127.0.0.1 in some stupid attempt to restore
1756 # nameservers.
1757 # This can be manually fixed by stoping dnsmasq,
1758 # then based on whats in /run/dnsmasq/, i see we can run
1759 # s resolvconf -d NetworkManager
1760 # oh ya, and stoping NetworkManager leaves this crap behind without cleaning it up.
1761 ser disable NetworkManager
1762 ;;
1763 esac
1764
1765 # I have no use for avahi,
1766 # had to run this twice when doing manually, i dunno why
1767 soff avahi-daemon ||:
1768 sleep 1
1769 soff avahi-daemon
1770
1771 # make my /etc/fonts/conf.d/ get used.
1772 # I have a new sans-serif font there because the default one
1773 # displays l and I as the same char, grrrrr.
1774 sudo fc-cache
1775
1776 pi desktop-file-utils
1777 m /a/bin/distro-setup/mymimes
1778
1779
1780 sgo dynamicipupdate.timer
1781
1782
1783 # stop autopoping windows when i plug in an android phone.
1784 # dbus-launch makes this work within an ssh connection, otherwise you get this message,
1785 # with still 0 exit code.
1786 # dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
1787 m dbus-launch gsettings set org.gnome.desktop.media-handling automount-open false
1788
1789
1790 # on grub upgrade, we get prompts unless we do this
1791 devs=()
1792 for dev in $(s btrfs fil show /boot | sed -nr 's#.*path\s+(\S+)$#\1#p'); do
1793 devs+=("$(devbyid $dev),")
1794 done
1795 devs[-1]=${devs[-1]%,} # jonied by commas
1796 sudo debconf-set-selections <<EOF
1797 grub-pc grub-pc/install_devices multiselect ${devs[*]}
1798 EOF
1799
1800 # btrfs maintenance
1801 sgo btrfsmaint.timer
1802 sgo btrfsmaintstop.timer
1803
1804 sgo systemstatus.timer
1805
1806
1807 if grep -xFq $HOSTNAME /a/bin/ds/machine_specific/btrbk.hosts; then
1808 sgo btrbk.timer
1809 fi
1810 # note: to see when it was last run,
1811 # ser list-timers
1812
1813 case $HOSTNAME in
1814 kd)
1815 sgo btrbkrust.timer
1816 ;;
1817 esac
1818
1819 end_msg <<'EOF'
1820 In mate settings settings, change scrolling to two-finger,
1821 because the default edge scroll doesn\'t work. Originally found this in debian.
1822 EOF
1823
1824 # Remove dep that came in with desktop to fix associations.
1825 m pu transmission-gtk
1826
1827 case $HOSTNAME in
1828 kd)
1829 lnf -T /d/vidshare /home/iank/Videos
1830 ;;
1831 esac
1832
1833 # # Based on guix manual instructions, also added code to profile.
1834 # # disabled since i'm not using it now.
1835 # pi nscd
1836 # if ! type -p guix >/dev/null; then
1837 # cd $(mktemp -d)
1838 # wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
1839 # # added some stuff to envonment.sh for profile based on
1840 # # manual instructions
1841 # # wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
1842 # # echo is to get past prompt
1843 # yes | sudo -E HOME=$HOME bash guix-install.sh || [[ $? == 141 ]]
1844 # guix install glibc-utf8-locales
1845 # guix package --install guile
1846 # fi
1847
1848 lnf -T /a/opt ~/src
1849
1850 pi tor
1851 m /a/bin/buildscripts/tor-browser
1852 # one root command needed to install
1853 s ln -sf /a/opt/tor-browser_en-US/Browser/start-tor-browser /usr/local/bin
1854
1855
1856 # nfs server
1857 pi-nostart nfs-kernel-server
1858
1859 if [[ $HOSTNAME == tp ]]; then
1860 sd /etc/wireguard/wg0.conf <<EOF
1861 [Interface]
1862 PrivateKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.key)
1863 Address = 10.3.0.2/24, fdfd::2/64
1864
1865 [Peer]
1866 PresharedKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.psk)
1867 PublicKey = 9RnAsJB+ISrA/9lmDKBoT08oBiKwzA64exBBj+rO+ng=
1868 Endpoint = b8.nz:26000
1869 AllowedIPs = 10.3.0.1/24, fdfd::1/64
1870 PersistentKeepalive = 20
1871 EOF
1872 sudo systemctl enable wg-quick@wg0
1873 sudo systemctl start wg-quick@wg0
1874 fi
1875
1876
1877 if [[ $HOSTNAME == kw ]]; then
1878 # hosts 1-199. 200+ are dynamic, avoid those
1879 tu /etc/exports <<'EOF'
1880 /root/.ianktrisquel_9/.iank/e/e 192.168.0.0/25(rw,no_root_squash,async,no_subtree_check) 192.168.0.128/26(rw,no_root_squash,async,no_subtree_check) 192.168.0.192/29(rw,no_root_squash,async,no_subtree_check)
1881 /home/iank/.iank/e/e 192.168.0.0/25(rw,no_root_squash,async,no_subtree_check) 192.168.0.128/26(rw,no_root_squash,async,no_subtree_check) 192.168.0.192/29(rw,no_root_squash,async,no_subtree_check)
1882 EOF
1883 ekw
1884 sgo nfs-server
1885 sudo exportfs -rav
1886 fi
1887
1888
1889 # if I was going to create a persistent vm, i might do it like this:
1890 # variant=something # from: virt-install --os-variant list
1891 # s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
1892 # --disk=/a/images/some_name.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
1893 # -n some_name --import --os-variant $variant --cpu host-model-only
1894
1895
1896 # for brother HL-2270DW, this worked:
1897 # https://askubuntu.com/questions/1067234/cant-use-wireless-brother-printer-2270dw-ubuntu-18-04
1898 # /a/opt/linux-brprinter-installer-2.2.2-1
1899 # answer n when it asks about uri.
1900 # Then go to cups, delete the existing printer, added on with dnssd url. browsed to
1901 # ppd at /usr/share/ppd/HL2270DW.ppd, which is duplicated at /usr/share/cups/model/HL2270DW.ppd
1902 # ppd file got installed from bash -x ./usr/local/Brother/Printer/HL2270DW/cupswrapper/cupswrap,
1903 # which I downloaded from their driver. but dont do that again, i copied it to /a/opt/HL2270DW.ppd,
1904 # use that.
1905
1906 # I had to reset it to use wired instead of wifi. it only uses 1 at a time. boot with go button held, after lights turn off, tap go 6 times.
1907 # Then it was already configured, but if i needed to, go to its web ui, default pass is "access".
1908
1909 ######### begin stuff belonging at the end ##########
1910
1911 end