mostly fixes
[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 nabia)
528 # note, to get the latest, it would be n=bullseye*
529 # but that has conflicting package versions, so this does the old one.
530 # I only use it for special rare purposes. Just keep in mind it is an
531 # outdated insecure version.
532 sd /etc/apt/preferences.d/chromium-bullseye <<EOF
533 Package: chromium chromium-* libicu67 libjpeg62-turbo libjsoncpp24 libre2-9 libwebpmux3
534 Pin: release o=Debian*,n=bullseye
535 Pin-Priority: 500
536 EOF
537 ;;
538 esac
539
540
541
542 ##### begin automatic upgrades (after checkrestart has been installed) ####
543 # if apt-config-auto-update is installed,
544 # it also has similar config, in a file 10something,
545 # but i think his overrides it since its higher number.
546 # This file was part of the automatic-updates package,
547 # and it has a configu option to not get new package lists,
548 # which seems pretty stupid to me, you cant actually upgrade
549 # anything if you dont have the new package list.
550 sd /etc/apt/apt.conf.d/20auto-upgrades <<'EOF'
551 APT::Periodic::Update-Package-Lists "1";
552 APT::Periodic::Download-Upgradeable-Packages "1";
553 APT::Periodic::AutocleanInterval "7";
554 APT::Periodic::Unattended-Upgrade "1";
555 EOF
556
557 # fyi: default file has comments about available options,
558 # you may want to read that, do pkx unattended-upgrades
559 # default is just security updates. this list found from reading
560 # match_whitelist_string() in $(which unattended-upgrades)
561 sd /etc/apt/apt.conf.d/50unattended-upgrades <<EOF
562 Unattended-Upgrade::Mail "root";
563 Unattended-Upgrade::MailOnlyOnError "true";
564 Unattended-Upgrade::Remove-Unused-Dependencies "true";
565 Unattended-Upgrade::Origins-Pattern {
566 "o=*,l=*,a=*,c=*,site=*,n=*";
567 };
568 EOF
569
570 # old files
571 sudo rm -f /etc/cron.d/unattended-upgrade-reboot /usr/local/bin/zelous-unattended-reboot /etc/cron.d/myupgrade
572
573 # myupgrade cron exists in /etc/cron.d/ian
574
575 ##### end automatic upgrades ####
576
577
578 # commented in case i want to use this sometime later
579 # sd /etc/apt/preferences.d/buster-backports <<EOF
580 # Package: *
581 # Pin: release a=buster-backports
582 # Pin-Priority: 500
583 # EOF
584
585 if [[ -e /etc/wireguard/wghole.conf ]]; then
586 reload=false
587 if [[ ! -e /etc/systemd/system/wg-quick@wghole.service.d/override.conf ]]; then
588 reload=true
589 fi
590 sudo mkdir -p /etc/systemd/system/wg-quick@wghole.service.d
591 sd /etc/systemd/system/wg-quick@wghole.service.d/override.conf <<'EOF'
592 [Unit]
593 StartLimitIntervalSec=0
594
595 [Service]
596 Restart=on-failure
597 RestartSec=20
598 EOF
599 if $reload; then ser daemon-reload; fi
600 sgo wg-quick@wghole
601 fi
602
603 ###### begin website setup
604 case $HOSTNAME in
605 li|bk|je)
606 pi bind9
607 f=/var/lib/bind/db.b8.nz
608 if [[ ! -e $f ]]; then
609 dnsb8
610 fi
611
612 pi prometheus-node-exporter
613
614 # ex for exporter
615 web-conf -p 9101 -f 9100 - apache2 ${HOSTNAME}ex.b8.nz <<'EOF'
616 <Location "/">
617 AuthType Basic
618 AuthName "basic_auth"
619 # created with
620 # htpasswd -c prometheus-export-htpasswd USERNAME
621 AuthUserFile "/etc/prometheus-export-htpasswd"
622 Require valid-user
623 </Location>
624 EOF
625 ;;&
626
627 bk)
628 sgo wg-quick@wgmail
629
630 # i just dont feel like setting up a special purpose ssh key to do this automatically.
631 end_msg <<'EOF'
632 # run this once for bk on local machine:
633 # only used for old openvpn setup
634 /a/exe/vpn-mk-client-cert -c bk.b8.nz -b expertpath -n mail li.iankelling.org
635 EOF
636 end
637 ;;
638 je)
639 end
640 ;;
641 li)
642
643 m /a/h/setup.sh iankelling.org
644
645 # start mumble only when im going to use it, since i dont use it much
646 pi-nostart mumble-server
647 sudo $sed -ri "s/^ *(serverpassword=).*/\1$(< /a/bin/bash_unpublished/mumble_pass)/" /etc/mumble-server.ini
648
649 # do certificate to avoid warning about unsigned cert,
650 # which is overkill for my use, but hey, I'm cool, I know
651 # how to do this.
652 m web-conf apache2 mumble.iankelling.org
653 sudo rm -fv /etc/apache2/sites-enabled/mumble.iankelling.org
654
655 # general vpn for as needed use
656 vpn-server-setup -d -r -4 10.5.5 -p 443 -n hole
657
658 # todo: consider if this should exist for the
659 # other vpn server
660 teeu /etc/openvpn/server/hole.conf <<'EOF'
661 client-to-client
662 EOF
663
664 # sullivan d8
665 sd /etc/openvpn/client-config-hole/sd8 <<'EOF'
666 ifconfig-push 10.5.5.41 255.255.255.0
667 EOF
668 # hsieh d8
669 sd /etc/openvpn/client-config-hole/hd8 <<'EOF'
670 ifconfig-push 10.5.5.42 255.255.255.0
671 EOF
672
673 sd /etc/openvpn/client-config-hole/onep9 <<'EOF'
674 ifconfig-push 10.5.5.14 255.255.255.0
675 EOF
676 sd /etc/openvpn/client-config-hole/bo <<'EOF'
677 ifconfig-push 10.5.5.13 255.255.255.0
678 EOF
679 sd /etc/openvpn/client-config-hole/sy <<'EOF'
680 ifconfig-push 10.5.5.12 255.255.255.0
681 EOF
682 sd /etc/openvpn/client-config-hole/kw <<'EOF'
683 ifconfig-push 10.5.5.9 255.255.255.0
684 EOF
685 sd /etc/openvpn/client-config-hole/x3 <<'EOF'
686 ifconfig-push 10.5.5.8 255.255.255.0
687 EOF
688 sd /etc/openvpn/client-config-hole/x2 <<'EOF'
689 ifconfig-push 10.5.5.7 255.255.255.0
690 EOF
691 sd /etc/openvpn/client-config-hole/wclient <<'EOF'
692 ifconfig-push 10.5.5.6 255.255.255.0
693 EOF
694 sd /etc/openvpn/client-config-hole/frodo <<'EOF'
695 ifconfig-push 10.5.5.5 255.255.255.0
696 EOF
697 sd /etc/openvpn/client-config-hole/amy <<'EOF'
698 ifconfig-push 10.5.5.3 255.255.255.0
699 EOF
700 sd /etc/openvpn/client-config-hole/kd <<'EOF'
701 ifconfig-push 10.5.5.2 255.255.255.0
702 EOF
703
704 # for adding to current system:
705 #vpn-mk-client-cert -s "" -n hole 72.14.176.105
706 # adding to remove system 107,
707 #vpn-mk-client-cert -s "" -n hole -c 10.2.0.107 -b hd8 iankelling.org
708 #
709 # for wireguard hole vpn
710 # wghole
711
712 # requested from linode via a support ticket.
713 # https://www.linode.com/docs/networking/an-overview-of-ipv6-on-linode/
714 # ipv6 stuff pieced together
715 # via slightly wrong information from
716 # https://github.com/angristan/openvpn-install/blob/master/openvpn-install.sh
717 # https://community.openvpn.net/openvpn/wiki/IPv6
718 # and man openvpn.
719 #
720 # This uses a public /64, but afaik, that is not needed for my
721 # current use case, since I'm doing ipv6 nat, they could be private
722 # and nat to a public address. I'm doing ipv6 nat in order to have 2
723 # vpn clients that externally share the same ip when sending so they
724 # share ip reputation. Note, the eth0 and tunx needed to be
725 # different subnets. On the same, I saw some neighbor packet go
726 # unanswered, tcpdump showed packets getting lost. I tried splitting the
727 # /64, it didn't work but I didn't investigate closely.
728
729
730 # not starting as i intend to replace it
731 m vpn-server-setup -s -i tunmail -n mail -d -6 2600:3c00:e002:3800::/64 2600:3c00:e002:3800::1/64
732 sudo tee /etc/openvpn/client-config-mail/mailclient <<'EOF'
733 ifconfig-push 10.8.0.4 255.255.255.0
734 ifconfig-ipv6-push 2600:3c00:e002:3800::4/64
735 EOF
736 sudo tee /etc/openvpn/client-config-mail/expertpath <<'EOF'
737 ifconfig-push 10.8.0.5 255.255.255.0
738 ifconfig-ipv6-push 2600:3c00:e002:3800::5/64
739 EOF
740
741
742 sudo dd of=/etc/systemd/system/vpn-mail-forward.service <<'EOF'
743 [Unit]
744 Description=Turns on iptables mail nat
745 BindsTo=openvpn-server@mail.service
746
747 [Service]
748 Type=oneshot
749 RemainAfterExit=yes
750 ExecStart=/a/bin/distro-setup/vpn-mail-forward tunmail start
751 ExecStop=/a/bin/distro-setup/vpn-mail-forward tunmail stop
752
753 [Install]
754 RequiredBy=openvpn-server@mail.service
755 EOF
756 ser daemon-reload
757
758
759 # needed for li's local mail delivery.
760 tu /etc/hosts <<<"10.8.0.4 mx.iankelling.org"
761
762 # wgmail handles this.
763 #sgo vpn-mail-forward.service
764 # old:
765 #sgo openvpn-server@mail
766 sgo wg-quick@wgmail
767
768 # setup let's encrypt cert
769 m web-conf apache2 mail.iankelling.org
770 # TODO, i expanded the above cert manually to mx.iankelling.org, this should be captured
771 # in the automation here. We use mail.iankelling.org as our ehlo name when sending mail
772 # but our mx record is mx.iankelling.org. Initially I was just using mail.iankelling.org,
773 # but the problem is I want multiple ips to be able to identify as mail.iankelling.org,
774 # but a subset to be mx.iankelling.org. Afaik, there is no problem with having
775 # our mail cert be for mail.iankelling.org, and have people connect to mx.ian...,
776 # but it doesn't make logical sense to do this.
777 sudo rm -fv /etc/apache2/sites-enabled/mail.iankelling.org{,-redir}.conf
778 ser reload apache2
779
780 a2enmod -q proxy proxy_http
781 domain=cal.iankelling.org
782 web-conf -f 10.8.0.4:5232 - apache2 $domain <<'EOF'
783 # https://radicale.org/2.1.html
784 #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
785 # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
786 <Location /radicale/>
787 Options +FollowSymLinks +Multiviews +Indexes
788 AllowOverride None
789 AuthType basic
790 AuthName "Authentication Required"
791 # setup one time, with root:www-data, 640
792 AuthUserFile "/etc/caldav-htpasswd"
793 Require valid-user
794 RequestHeader set X-Script-Name /radicale/
795 RequestHeader set X-Remote-User expr=%{REMOTE_USER}
796 ProxyPass "http://10.8.0.4:5232/" retry=0
797 ProxyPassReverse "http://10.8.0.4:5232/"
798 </Location>
799 EOF
800 # nginx version of above would be:
801 # auth_basic "Not currently available";
802 # auth_basic_user_file /etc/nginx/caldav/htpasswd;
803
804
805
806 ###### begin znc setup #####
807 pi znc
808
809 # https://wiki.znc.in/FAQ seems to imply that znc doesn\'t need restart after cert change.
810 # to get into the web interface,
811 # then use non-main browser or else it doebsn't allow it based on ocsp stapling from my main site.
812 # https://iankelling.org:12533/
813 # login as ian, pass is in pass store, the part after :
814
815 # znc config generated by doing
816 # znc --makeconf
817 # selected port is also used in erc config
818 # comma separated channel list worked.
819 # while figuring things out, running znc -D for debug in foreground.
820 # to exit and save config:
821 # /msg *status shutdown
822 # configed auth on freenode by following
823 # https://wiki.znc.in/Sasl:
824 # /query *sasl
825 # RequireAuth yes
826 # Mechanism PLAIN
827 # Set MyNickservName pa$$w0rd
828 # created the system service after, and had to do
829 # mv /home/iank/.znc/* /var/lib/znc
830 # sed -i 's,/home/iank/.znc/,/var/lib/znc,' /var/lib/znc/config/znc.conf
831 # and made a copy of the config files into /p/c
832 # /msg *status LoadMod --type=global log -sanitize
833 # todo: in config file AllowWeb = true should be false. better security if that is off unless we need it.
834 # /msg *status LoadMod --type=network perform
835 # /query *perform add PRIVMSG ChanServ :invite #fsf-office
836 # /msg *perform add JOIN #fsf-office
837 # /msg *status LoadMod NickServ
838 #
839 # i set Buffer = 500
840 # also ran /znc LoadMod clearbufferonmsg
841 # it would be nice if erc supported erc query buffers by doing
842 # /msg *status clearbuffer <name of the query/receiver
843 # on killing the,
844 # an example seems to be here: https://github.com/zenspider/elisp/blob/master/rwd-irc.el
845 # if that was the case i could remove the module clearbufferonmsg
846 # also would be nice if erc supported
847 # https://wiki.znc.in/self-message
848 # https://wiki.znc.in/Query_buffers \
849 #
850 # for geekshed, there was no sasl support as far as I can tell,
851 # so I set to msg nickserv to identify upon connect.
852 if ! getent passwd znc > /dev/null; then
853 sudo useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
854 fi
855 sudo chmod 700 /var/lib/znc
856 sudo chown -R znc:znc /var/lib/znc
857 # Avoid restarting if possible, reconnecting to irc is annoying.
858 # The unit file was made active with conflink.
859 # Note, avoid using ser here because we wrap sudo to prints the command first.
860 if [[ $(systemctl is-active znc) != active ]]; then
861 sgo znc
862 fi
863 ###### stop znc setup #####
864
865 end
866 ;;
867 esac
868 ###### end website setup
869
870 ########### end section including li/lj ###############
871
872
873 #### desktop stuff
874
875 ### system76 things ###
876 case $HOSTNAME in
877 sy|bo)
878 # note, i stored the initial popos packages at /a/bin/data/popos-pkgs
879 if [[ ! -e /etc/apt/sources.list.d/system76.list ]]; then
880 # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
881 sd /etc/apt/sources.list.d/system76.list <<EOF
882 deb http://ppa.launchpad.net/system76-dev/stable/ubuntu $codename_compat main
883 deb-src http://ppa.launchpad.net/system76-dev/stable/ubuntu $codename_compat main
884 EOF
885 # ubuntu keyserver is prone to intermittent failures
886 trysleep 4 15 s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5D1F3A80254F6AFBA254FED5ACD442D1C8B7748B
887 p update
888 # https://support.system76.com/articles/install-ubuntu/
889 # but i'm hoping this is not needed
890 # sd /etc/apt/preferences.d/system76 <<'EOF'
891 # Package: *
892 # Pin: release o=LP-PPA-system76-dev-stable
893 # Pin-Priority: 1001
894 # EOF
895 #
896 # TODO: I had to uninstall linux-image-generic-hwe-20.04 because of a conflict
897 # about linux-firmware. Should probably install it to begin with in fai if
898 # i'm going to use.
899 pi system76-driver system76-firmware
900 # if you get a notice about a firmware update, the notifier on i3
901 # is too dumb to do anything when you click it. so to see
902 # a changelog, cd to
903 # /var/cache/system76-firmware-daemon
904 # extract the xz files there, one will contain a changelog.
905 # then to install an update:
906 # s system76-firmware-cli schedule
907 fi
908 ;;
909 esac
910
911 case $distro in
912 trisquel|ubuntu)
913
914 # ppa:obsproject/obs-studio
915 if [[ ! -s /etc/apt/sources.list.d/obs.list ]]; then
916 # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
917 sd /etc/apt/sources.list.d/obs.list <<EOF
918 deb http://ppa.launchpad.net/obsproject/obs-studio/ubuntu $codename_compat main
919 deb-src http://ppa.launchpad.net/obsproject/obs-studio/ubuntu $codename_compat main
920 EOF
921 trysleep 4 15 s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BC7345F522079769F5BBE987EFC71127F425E228
922 p update
923 fi
924 ;;
925 esac
926
927 case $codename_compat in
928 xenial)
929 # mate-indicator-applet and beyond are msc things I noticed diffing a
930 # standard install with mine.
931 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras mate-indicator-applet anacron
932 ;;
933 stretch)
934 pi task-mate-desktop
935 ;;
936 buster)
937 # todo: figure out mate for buster
938 # pi task-gnome-desktop
939 ;;
940 bionic|focal)
941 # i had installing mate-indicator-applet, but im not sure why so i removed
942 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras anacron
943
944 # pi gnome-core
945 # # apt-get update periodically fails with an appstream error.
946 # # this removes gnome-core, but its just a package for dependencies
947 # p -y remove appstream
948
949
950 # by default, it sleeps when not logged in to x/wayland and on ac power.
951 # stop that.
952 if id -u gdm &>/dev/null; then
953 sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
954 fi
955 ;;&
956 focal)
957 # lightdm startup fails without this. on etiona, we got unity-greeter installed automatically,
958 # it would probably work on nabia too, but google just lead me to this and it works fine.
959 pi lightdm-gtk-greeter
960 # ok, this is really weird
961 # normally this file has
962 sd /etc/X11/Xsession.d/99x11-common_start <<'EOF'
963 # this is very odd.
964 # this file normally just has: exec $STARTUP
965 # but then ~/.xsession-errors
966 # says $STARTUP is not found, which appears to be the real
967 # error, but normal bash doesnt operate that way.
968 # https://bugs.launchpad.net/ubuntu/+source/im-config/+bug/1879352
969 eval exec $STARTUP
970 EOF
971 # also, gdm wayland was default, had to do
972 # dpkg-reconfigure gdm3
973 # and choose lightdm.
974 #
975 ;;
976 esac
977
978
979 if [[ $codename_compat == flidas ]]; then
980 # doesnt exist in newer
981 pi gnupg-doc
982 fi
983
984
985 case $distro in
986 trisquel)
987 case $codename in
988 *)
989 # firefox would work here too, apt would select abrowser.
990 # and the update-alternatives thing i think is becuz firefox is
991 # generally available before abrowser and this helps fix things
992 # up when we have both.
993 pi abrowser
994 s update-alternatives --set x-www-browser /usr/bin/abrowser
995 ;;
996 esac
997 ;;
998 ubuntu)
999 pi firefox
1000 ;;
1001 debian)
1002 pi firefox-esr
1003 ;;
1004 esac
1005
1006 # newer distros just use adb for package name it seems
1007 case $codename_compat in
1008 bionic|stretch)
1009 pi android-tools-adbd
1010 ;;
1011 esac
1012
1013 case $codename_compat in
1014 focal)
1015 pi libext2fs-dev libzstd-dev
1016 cd /a/opt/btrfs-progs
1017 ;;
1018 esac
1019
1020
1021 case $codename_compat in
1022 bionic)
1023 pi python-vte
1024 ;;
1025 *)
1026 pi reportbug-gtk
1027 ;;
1028 esac
1029
1030 # not packaged in newer distros it seems
1031 case $codename_compat in
1032 bionic|buster|stretch)
1033 pi dtrx
1034 ;;
1035 esac
1036
1037
1038 # TODO: some of the X programs can be removed from pall when using wayland
1039
1040 # depends gcc is a way to install suggests. this is apparently the only
1041 # way to install suggests even if the main package is already
1042 # installed. reinstall doesn't work, uninstalling can cause removing
1043 # dependent packages.
1044 pi ${pall[@]} $(apt-cache search ruby[.0-9]+-doc| awk '{print $1}') $($src/distro-pkgs)
1045
1046
1047 # commented, not worth the hassle i think.
1048 #seru enable psd
1049 #seru start psd
1050
1051
1052 # old filename
1053 sudo rm -fv /etc/systemd/resolved.conf.d/iank.conf
1054
1055 # website is dead june 14 2019. back in october, but meh
1056 sudo rm -fv /etc/apt/sources.list.d/iridium-browser.list
1057 # case $distro in
1058 # debian)
1059 # pi chromium ;;
1060 # trisquel|ubuntu)
1061 # wget -qO - https://downloads.iridiumbrowser.de/ubuntu/iridium-release-sign-01.pub|sudo apt-key add -
1062 # t=$(mktemp)
1063 # cat >$t <<EOF
1064 # deb [arch=amd64] https://downloads.iridiumbrowser.de/deb/ stable main
1065 # #deb-src https://downloads.iridiumbrowser.de/deb/ stable main
1066 # EOF
1067 # f=/etc/apt/sources.list.d/iridium-browser.list
1068 # if ! diff -q $t $f; then
1069 # s cp $t $f
1070 # s chmod 644 $f
1071 # p update
1072 # fi
1073 # pi iridium-browser
1074 # ;;
1075 # esac
1076
1077
1078 ### begin home vpn server setup
1079
1080
1081 # # this section done initially to make persistent keys.
1082 # # Also note, I temporarily set /etc/hosts so my host was
1083 # # b8.nz when running this, since the vpn client config
1084 # # generator assumes we need to go to that server to get
1085 # # server keys.
1086 # vpn-server-setup -rds
1087 # s cp -r --parents /etc/openvpn/easy-rsa/keys /p/c/filesystem
1088 # s chown -R 1000:1000 /p/c/filesystem/etc/openvpn/easy-rsa/keys
1089 # # kw = kgpe work machine.
1090 # for host in x2 x3 kw; do
1091 # vpn-mk-client-cert -b $host -n home b8.nz 1196
1092 # dir=/p/c/machine_specific/$host/filesystem/etc/openvpn/client
1093 # mkdir -p $dir
1094 # s bash -c "cp /etc/openvpn/client/home* $dir"
1095 # # note: /etc/update-resolv-conf-home also exists for all systems with /p
1096 # done
1097
1098 # key already exists, so this won't generate one, just the configs.
1099 # m vpn-server-setup -rds
1100 # sudo tee -a /etc/openvpn/server/server.conf <<'EOF'
1101 # push "dhcp-option DNS 10.0.0.1"
1102 # push "route 10.0.0.0 255.255.0.0"
1103 # client-connect /a/bin/distro-setup/vpn-client-connect
1104 # EOF
1105 # sudo sed -i --follow-symlinks 's/10.8./10.9./g;s/^\s*port\s.*/port 1196/' /etc/openvpn/server/server.conf
1106
1107 # if [[ $HOSTNAME == tp ]]; then
1108 # if [[ -e /lib/systemd/system/openvpn-server@.service ]]; then
1109 # vpn_service=openvpn-server@server
1110 # else
1111 # vpn_service=openvpn@server
1112 # fi
1113 # sgo $vpn_service
1114 # fi
1115 ### end vpn server setup
1116
1117 ##### rss2email
1118 if mountpoint /p &>/dev/null; then
1119 # note, see bashrc for more documentation.
1120 pi rss2email
1121 sd /etc/systemd/system/rss2email.service <<'EOF'
1122 [Unit]
1123 Description=rss2email
1124 After=multi-user.target
1125
1126 [Service]
1127 User=iank
1128 Type=oneshot
1129 # about 24 hours of failures
1130 # it copies over its files without respecting symlinks, so
1131 # we pass options to use different location.
1132 ExecStart=/usr/local/bin/sysd-mail-once -288 rss2email r2e -d /p/c/rss2email.json -c /p/c/rss2email.cfg run
1133 EOF
1134 sd /etc/systemd/system/rss2email.timer <<'EOF'
1135 [Unit]
1136 Description=rss2email
1137
1138 [Timer]
1139 # for initial run. required.
1140 OnActiveSec=30
1141 # for subsequent runs.
1142 OnUnitInactiveSec=300
1143
1144 [Install]
1145 WantedBy=timers.target
1146 EOF
1147 sudo systemctl daemon-reload
1148 fi
1149
1150
1151 ######### begin irc periodic backup #############
1152 if [[ $HOSTNAME == frodo ]]; then
1153 sd /etc/systemd/system/ircbackup.service <<'EOF'
1154 [Unit]
1155 Description=irc li backup
1156 After=multi-user.target
1157
1158 [Service]
1159 User=iank
1160 Type=oneshot
1161 ExecStart=/usr/local/bin/sysd-mail-once irc-backup rsync -rlptDhSAX root@iankelling.org:/var/lib/znc/moddata/log/iank/freenode/ /k/irclogs
1162 EOF
1163 sd /etc/systemd/system/ircbackup.timer <<'EOF'
1164 [Unit]
1165 Description=irc li backup hourly
1166
1167 [Timer]
1168 OnCalendar=hourly
1169
1170 [Install]
1171 WantedBy=timers.target
1172 EOF
1173 sudo systemctl daemon-reload
1174 sgo ircbackup.timer
1175 fi
1176
1177
1178 ######### end irc periodic backup #############
1179
1180
1181 pi-nostart openvpn
1182 # pi-nostart does not disable
1183 ser disable openvpn
1184
1185
1186 if [[ -e /p/c/gen-fsf-vpn ]]; then
1187 /p/c/gen-fsf-vpn
1188 fi
1189
1190 if [[ -e /p/c/machine_specific/$HOSTNAME/filesystem/etc/openvpn/client/hole.crt ]]; then
1191 sgo openvpn-client@hole
1192 fi
1193
1194 if [[ $HOSTNAME == frodo ]]; then
1195 vpn-mk-client-cert -b frodo -n hole iankelling.org
1196 fi
1197
1198 ############# begin syncthing setup ###########
1199 case $HOSTNAME in
1200 kd|frodo)
1201 f=/usr/share/keyrings/syncthing-archive-keyring.gpg
1202 if [[ ! -e $f ]]; then
1203 s curl -s -o $f https://syncthing.net/release-key.gpg
1204 fi
1205 s="deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable"
1206 if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != "$s" ]]; then
1207 echo "$s" | sd /etc/apt/sources.list.d/syncthing.list
1208 p update
1209 fi
1210 pi syncthing
1211 ;;&
1212 frodo)
1213 m lnf -T /w/syncthing /home/iank/.config/syncthing
1214 ser daemon-reload # syncthing likely not properly packaged
1215 sgo syncthing@iank # runs as iank
1216 ;;
1217 kd)
1218
1219 # 1003 just happens to be what was on my system
1220 if ! getent passwd ziva; then
1221 s groupadd -g 1003 ziva
1222 # syncthing state / config / db are all in ~/.config/syncthing
1223 s useradd -g 1003 -u 1003 -d /d/ziva-home -c ziva -s /bin/bash ziva
1224 fi
1225 sgo syncthing@ziva
1226 ;;
1227 esac
1228
1229 # user for short term use dropping of privileges
1230
1231 if ! getent group zu &>/dev/null; then
1232 s groupadd -g 1023 zu
1233 fi
1234 if ! getent passwd zu &>/dev/null; then
1235 s useradd -g 1023 -u 1023 -c zu -s /bin/bash zu
1236 fi
1237
1238
1239 # these things persist in ~/.config/syncthing, which I save in
1240 # /w/syncthing (not in /p, because syncthing should continue to
1241 # run on home server even when using laptop as primary device)
1242 # open http://localhost:8384/
1243 # change listen address from default to tcp://:22001,
1244 # this is because we do port forward so it doesn\'t have to use
1245 # some external server, but the syncthing is broken for port forward,
1246 # you get a message, something "like connected to myself, this should not happen"
1247 # when connecting to other local devices, so I bump the port up by 1,
1248 # based on
1249 # https://forum.syncthing.net/t/connected-to-myself-should-not-happen/1763/19.
1250 # Without this, it was being stuck syncing at 0%.
1251 # Set gui username and password.
1252 #
1253 # install syncthing via f-droid,
1254 # folder setting, turn off send only.
1255 # on phone, add device, click bar code icon
1256 # on dekstop, top right, actions, device id
1257 # after adding, notification will appear on desktop to confirm
1258 #
1259 # syncing folder. from phone to desktop: select desktop in the
1260 # folder on phone\'s sync options, notification will appear in
1261 # desktop\'s web ui within a minute. For the reverse, the
1262 # notification will appear in android\'s notifications, you have to
1263 # swipe down and tap it to add the folder. It won\'t appear in the
1264 # syncthing ui, which would be intuitive, but don\'t wait for it
1265 # there. The notification may not work, instead open the web gui
1266 # from in the app, there should be a notification within there.
1267 #
1268 # On phone, set settings to run syncthing all the time, and
1269 # show no notification.
1270 #
1271 # Folder versioning would make sense if I didn\'t already use btrfs
1272 # for backups. I would choose staggered, or trash can for more space.
1273 #
1274 # if needed to install on a remote comp:
1275 # ssh -L 8384:localhost:8384 -N frodo
1276 # open http://localhost:8384/
1277 #
1278 # Note, the other thing i did was port forward port 22000,
1279 # per https://docs.syncthing.net/users/firewall.html
1280
1281 ############# end syncthing setup ###########
1282
1283
1284
1285 ####### begin misc packages ###########
1286
1287 # template
1288 case $codename in
1289 flidas)
1290 :
1291 ;;
1292 esac
1293
1294 sudo update-alternatives --set pinentry /usr/bin/pinentry-gtk-2
1295
1296
1297 # sakura config is owned by ian
1298 m reset-sakura
1299 m reset-konsole
1300 m sudo -u user2 -i reset-konsole
1301 # user2 xscreensaver we don't want to reset
1302 m reset-xscreensaver
1303
1304
1305 # this would install from cabal for newer / consistent version across os, but it screws up xmonad, so disabled for now.
1306 # this is also in primary-setup
1307 # pi libxss-dev # dependency based on build failure
1308 # cabal update
1309 # cabal install --upgrade-dependencies --force-reinstalls arbtt
1310 # also, i assume syncing this between machines somehow messed up the data.
1311 if mountpoint /p &>/dev/null; then
1312 case $codename in
1313 etiona|nabia)
1314 pi arbtt
1315 # same as seru enable arbtt, but works over ssh when systemctl --user causes error:
1316 # Failed to connect to bus: No such file or directory
1317 lnf -T /a/bin/ds/subdir_files/.config/systemd/user/arbtt.service /home/iank/.config/systemd/user/default.target.wants/arbtt.service
1318 # allow failure
1319 seru start arbtt ||:
1320 ;;
1321 esac
1322 fi
1323
1324
1325 m primary-setup
1326
1327 if [[ ! -e ~/.linphonerc && -e /p/.linphonerc-initial ]]; then
1328 m cp /p/.linphonerc-initial ~/.linphonerc
1329 fi
1330
1331 # linphone in t10 wont do dns with systemd-resolved or something
1332 s teeu /etc/hosts <<'EOF'
1333 74.94.156.215 watson.fsf.org
1334 EOF
1335
1336
1337
1338 ### begin spd install
1339 if mountpoint /p &>/dev/null; then
1340 pi libswitch-perl libdigest-md5-file-perl libgnupg-interface-perl
1341 t=$(mktemp)
1342 m wget -O $t http://mirror.fsf.org/fsfsys-trisquel/fsfsys-trisquel/pool/main/s/spd-perl/spd-perl_0.2-1_amd64.deb
1343 sudo dpkg -i $t
1344 m rm $t
1345 # this guesses at the appropriate directory, adjust if needed
1346 perldir=(/usr/lib/x86_64-linux-gnu/perl/5.*)
1347 m sudo ln -sf ../../../perl/5.18.2/SPD/ ${perldir[0]}
1348 # newer distro had gpg2 as default, older one, flidas, need to make it that way
1349 gpgpath=$(which gpg2) ||:
1350 if [[ $gpgpath ]]; then
1351 sudo mkdir -p /usr/local/spdhackfix
1352 s lnf -T $gpgpath /usr/local/spdhackfix/gpg
1353 fi
1354 fi
1355 ### end spd install
1356
1357
1358 # nagstamon setting which were set through the ui
1359 # monitor url https://klaxon.fsf.org/cgi-bin
1360 # monitor url cgi https://klaxon.fsf.org/cgi-bin
1361 # in filters tab:
1362 # all unknown services
1363 # all warning services
1364 # acknowledged hosts & services
1365 # hosts & services down for maintenence
1366 # services on down hosts
1367 # services on hosts in maintenece
1368 # services on unreachable osts
1369 # hosts in soft state
1370 # services in soft state
1371 # in display tab: fullscreen
1372
1373 # these translate to these settings I think
1374 # filter_acknowledged_hosts_services = True
1375 # filter_all_unknown_services = True
1376 # filter_all_warning_services = True
1377 # filter_hosts_in_soft_state = True
1378 # filter_hosts_services_maintenance = True
1379 # filter_services_in_soft_state = True
1380 # filter_services_on_down_hosts = True
1381 # filter_services_on_hosts_in_maintenance = True
1382 # filter_services_on_unreachable_hosts = True
1383 # notify_if_up = False
1384 # statusbar_floating = False
1385 # fullscreen = True
1386 # but i'm just going to rely on the webpage plus sms for now.
1387
1388
1389 # it asks if it should make users in it's group capture packets without root,
1390 # which is arguably more secure than running wireshark as root. default is no,
1391 # which is what i prefer, since I plan to use tcpdump to input to wireshark.
1392 s DEBIAN_FRONTEND=noninteractive pi wireshark-gtk
1393
1394 # /run and /dev/shm are listed as required for pulseaudio. All 4 in the group
1395 # listed in the default config as suggested.
1396 # /run/usr/1000 i noticed was missing for pulseaudio
1397 # /run/user/0 just seemed like a not bad idea, given the above
1398 tu /etc/schroot/desktop/fstab <<'EOF'
1399 /p /p none rw,bind 0 0
1400 /a /a none rw,bind 0 0
1401 /run /run none rw,bind 0 0
1402 /run/lock /run/lock none rw,bind 0 0
1403 /dev/shm /dev/shm none rw,bind 0 0
1404 /run/shm /run/shm none rw,bind 0 0
1405 /run/user/1000 /run/user/1000 none rw,bind 0 0
1406 /run/user/1001 /run/user/1001 none rw,bind 0 0
1407 /run/user/0 /run/user/0 none rw,bind 0 0
1408 EOF
1409
1410 # todo: consider if this should use the new sysd-prom-fail
1411 sd /etc/systemd/system/schrootupdate.service <<'EOF'
1412 [Unit]
1413 Description=schrootupdate
1414 After=multi-user.target
1415
1416 [Service]
1417 Type=oneshot
1418 ExecStart=/usr/local/bin/sysd-mail-once schrootupdate /a/bin/distro-setup/schrootupdate
1419 EOF
1420 sd /etc/systemd/system/schrootupdate.timer <<'EOF'
1421 [Unit]
1422 Description=schrootupdate
1423
1424 [Timer]
1425 OnCalendar=*-*-* 04:20:00 America/New_York
1426
1427 [Install]
1428 WantedBy=timers.target
1429 EOF
1430 ser daemon-reload
1431 sgo schrootupdate.timer
1432
1433
1434
1435 # for my roommate
1436 case $distro in
1437 trisquel)
1438 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/bullseye.list/BULLSEYE_FREE \
1439 debian bullseye firefox-esr pulseaudio chromium anki
1440 case $(debian-codename) in
1441 etiona|nabia)
1442 # we have a lot of t8 stuff, useful to have
1443 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/flidas.list/FLIDAS \
1444 trisquel flidas
1445 tu /nocow/schroot/flidas/etc/sudoers <<EOF
1446 $USER ALL=(ALL) NOPASSWD: ALL
1447 Defaults env_keep += SUDOD
1448 Defaults always_set_home
1449 Defaults !umask
1450 EOF
1451 sd /nocow/schroot/flidas//etc/locale.gen <<'EOF'
1452 en_US.UTF-8 UTF-8
1453 EOF
1454 s schroot -c flidas locale-gen
1455 s schroot -c flidas update-locale LANG=en_US.UTF-8
1456
1457 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/testing.list/TESTING_NONFREE debian unstable debootstrap
1458 sudo cp -a /nocow/schroot/unstable/usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
1459
1460 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/impish.list/IMPISH ubuntu impish
1461
1462 ;;
1463 esac
1464 ;;
1465 debian)
1466 pi chromium
1467 ;;
1468 esac
1469
1470 sudo mkdir -p /nocow/user
1471 sudo chown $USER:$USER /nocow/user
1472 pi anki
1473
1474
1475 ####### begin transmission
1476
1477 case $HOSTNAME in
1478 frodo)
1479 tdir=/i/k
1480 ;;
1481 kd)
1482 tdir=/d/tor
1483 ;;
1484 *)
1485 tdir=/nocow/user/tor
1486 ;;
1487 esac
1488
1489 mkdir -p $tdir
1490
1491 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
1492 # 450 seems likely to be unused. we need to specify one or else
1493 # it won't be stable across installs.
1494 if ! getent passwd debian-transmission > /dev/null; then
1495 sudo groupadd -g 450 debian-transmission
1496 sudo adduser --quiet \
1497 --gid 450 \
1498 --uid 450 \
1499 --system \
1500 --no-create-home \
1501 --disabled-password \
1502 --home /var/lib/transmission-daemon \
1503 debian-transmission
1504 fi
1505 # We want group writable stuff from transmission.
1506 # However, after setting this, I learn that transmission sets it's
1507 # own umask based on it's settings file. Well, no harm leaving this
1508 # so it's set right from the beginning.
1509 sudo chfn debian-transmission -o umask=0002
1510
1511 # note i had to do this, which is persistent:
1512 # cd /i/k
1513 # s chgrp debian-transmission torrents partial-torrents
1514
1515 # syslog says things like
1516 # 'Failed to set receive buffer: requested 4194304, got 425984'
1517 # google suggets giving it even more than that
1518 tu /etc/sysctl.conf<<'EOF'
1519 net.core.rmem_max = 67108864
1520 net.core.wmem_max = 16777216
1521 EOF
1522 sudo sysctl -p
1523
1524 # some reason it doesn\'t seem to start automatically anyways
1525 pi-nostart transmission-daemon
1526 # be extra sure its not started
1527 ser disable transmission-daemon
1528 ser stop transmission-daemon
1529
1530 # the folder was moved here after an install around 02/2017.
1531 # it contains runtime data,
1532 # plus a simple symlink to the config file which it\'s
1533 # not worth separating out.
1534 # between comps, the uid can change
1535
1536 f=$tdir/transmission-daemon
1537 for d in $tdir/partial-torrents $tdir/torrents $f; do
1538 if [[ ! -d $d ]]; then
1539 mkdir $d
1540 fi
1541 sudo chown -R debian-transmission:user2 $d
1542 done
1543 s lnf -T $f /var/lib/transmission-daemon/.config/transmission-daemon
1544 s lnf -T /etc/transmission-daemon/settings.json $f/settings.json
1545 sudo chown -R debian-transmission:debian-transmission $f
1546 sudo chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon
1547 #
1548 # config file documented here, and it\'s the same config
1549 # for daemon vs client, so it\'s documented in the gui.
1550 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
1551 #
1552 # I originaly setup rpc-whitelist, but after using
1553 # routing to a network namespace, it doesn\'t see the
1554 # real source address, so it\'s disabled.
1555 #
1556 # Changed the cache-size to 256 mb, reduces disk use.
1557 # It is a read & write cache.
1558 if ! systemctl is-active transmission-daemon-nn &>/dev/null && \
1559 ! systemctl is-active transmission-daemon; then
1560 tmp=$(mktemp)
1561 command sudo ruby <<EOF >$tmp
1562 require 'json'
1563 p = '/etc/transmission-daemon/settings.json'
1564 s = {
1565 'rpc-whitelist-enabled' => false,
1566 'rpc-authentication-required' => false,
1567 'incomplete-dir' => '$tdir/partial-torrents',
1568 'incomplete-dir-enabled' => true,
1569 'download-dir' => '$tdir/torrents',
1570 "speed-limit-up" => 800,
1571 "speed-limit-up-enabled" => true,
1572 "peer-port" => 61486,
1573 "cache-size-mb" => 256,
1574 "ratio-limit" => 5.0,
1575 "ratio-limit-enabled" => false,
1576 }
1577 puts(JSON.pretty_generate(JSON.parse(File.read(p)).merge(s)))
1578 EOF
1579 cat $tmp | sudo dd of=/etc/transmission-daemon/settings.json
1580
1581 fi
1582
1583 ####### end transmission
1584
1585 case $HOSTNAME in
1586 kd)
1587 # to persist upload/dl metadata. initially, moved all the stuff
1588 # in /var/lib/transmission-daemon to /d/tor
1589 s usermod --home /d/tor debian-transmission
1590 sgo transmission-daemon-nn
1591
1592 ;;
1593 esac
1594
1595
1596 ######### begin transmission client setup ######
1597
1598 if [[ -e /p/transmission-rpc-pass ]]; then
1599 # arch had a default config,
1600 # debian had nothing until you start it.
1601 # With a little trial an error, here is a minimal config
1602 # taken from the generated one, plus changes that the
1603 # settings ui does, without a bunch of ui crap settings.
1604 #
1605 # only settings I set were
1606 # hostname
1607 # auto-connect
1608 # password
1609
1610 # the password is randomly generated on first run, i copied it out
1611 # so it could be used by other hosts.
1612 sudo ruby <<'EOF'
1613 require 'json'
1614 p = '/etc/transmission-daemon/settings.json'
1615 s = JSON.parse(File.read(p))
1616 s["rpc-password"] = File.read("/p/transmission-rpc-pass").chomp
1617 # default is 0022 (18 in decimal)
1618 s["umask"] = 2
1619 File.write p, JSON.pretty_generate(s)
1620 EOF
1621
1622 rpc_pass=$(</p/transmission-rpc-pass)
1623 for f in /home/*; do
1624 u=${f##*/}
1625 uid=$(id -u $u 2>/dev/null) || continue
1626 if [[ ! $uid -ge 1000 ]]; then
1627 continue
1628 fi
1629 d=$f/.config/transmission-remote-gtk
1630 sudo -u $u mkdir -p $d
1631 # i tried setting hostname to transmission.b8.nz, so i could dynamically change where
1632 # this connects to, but it said some 421 denied error when I did that. Then it
1633 # froze X when i ran it under strace. Whatever.
1634 sudo -u $u dd of=$d/config.json <<EOF
1635 {
1636 "profiles" : [
1637 {
1638 "profile-name" : "Default",
1639 "hostname" : "10.173.0.2",
1640 "rpc-url-path" : "/transmission/rpc",
1641 "username" : "",
1642 "password" : "$rpc_pass",
1643 "auto-connect" : true,
1644 "ssl" : false,
1645 "timeout" : 40,
1646 "retries" : 3,
1647 "update-active-only" : false,
1648 "activeonly-fullsync-enabled" : false,
1649 "activeonly-fullsync-every" : 2,
1650 "update-interval" : 3,
1651 "min-update-interval" : 3,
1652 "session-update-interval" : 60,
1653 "exec-commands" : [],
1654 "destinations" : []
1655 }
1656 ],
1657 "profile-id" : 0,
1658 "add-options-dialog" : false
1659 }
1660 EOF
1661 done
1662 fi
1663 ######### end transmission client setup ######
1664
1665
1666 ### printer setup
1667 pi cups
1668
1669 sudo gpasswd -a $USER lpadmin # based on ubuntu wiki
1670 # goto http://127.0.0.1:631
1671 # administration tab, add new printer button.
1672 # In debian, I could use hte recommended driver,
1673 # in arch, I had to pick out the 6L driver.
1674
1675
1676 # bridge networking as user fails. google lead here, but it doesn\'t work:
1677 # oh well, I give up.
1678 # http://wiki.qemu.org/Features-Done/HelperNetworking
1679 # s mkdir /etc/qemu
1680 # f=/etc/qemu/bridge.conf
1681 # sd $f <<'EOF'
1682 # allow br0
1683 # EOF
1684 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
1685 # s chmod 640 $f
1686
1687 # general known for debian/ubuntu, not for fedora
1688
1689 m /a/bin/buildscripts/go
1690 m /a/bin/buildscripts/rust
1691 m /a/bin/buildscripts/misc
1692 m /a/bin/buildscripts/pithosfly
1693 #m /a/bin/buildscripts/alacritty
1694 #m /a/bin/buildscripts/kitty
1695
1696 pi-nostart virtinst virt-manager
1697 soff libvirtd
1698 # i cant if this is whats causing it to start even though
1699 # its disabled. note: it leaves around dnsmasq instances even
1700 # if you stop it. what the hell systemd?
1701 soff libvirt-guests
1702 # allow user to run vms, from debian handbook. libvirt-qemu
1703 # based on https://www.whonix.org/wiki/KVM#First-time_User.3F
1704 for x in iank user2; do s usermod -a -G libvirt,kvm,libvirt-qemu $x; done
1705
1706
1707 pi --no-install-recommends kdeconnect
1708 ### kdeconnect for gnome. started in /a/bin/distro-setup/desktop-20-autostart.sh
1709 ### but gnome + xmonad not working in flidas, so i disabled it
1710 # pi libgtk-3-dev python3-requests-oauthlib valac cmake python-nautilus libappindicator3-dev
1711 # cd /a/opt/indicator-kdeconnect
1712 # mkdir -p build
1713 # cd build
1714 # cmake .. -DCMAKE_INSTALL_PREFIX=/usr
1715 # make
1716 # sudo make install
1717 # # we can start it manually with /usr/lib/x86_64-linux-gnu/libexec/kdeconnectd
1718 # # it seems, according to
1719 # # /etc/xdg/autostart/kdeconnectd.desktop
1720 # # I'm not seeing the icon, but the clipboard replication is working
1721
1722
1723 ### model 01 arduino support ###
1724 # https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux
1725 # also built latest arduino in /a/opt/Arduino, (just cd build; ant build; ant run )
1726 # set arduino var in bashrc,
1727 # have system config file setup too.
1728 sudo adduser $USER dialout
1729
1730 # this is for the mail command too. update-alternatives is kind of misleading
1731 # since at least it's main commands pretend mail does not exist.
1732 # bsd's mail got pulled in on some dumb dependency, i dunno how.
1733 sudo update-alternatives --set mailx /usr/bin/mail.mailutils
1734
1735 ######### end misc packages #########
1736
1737
1738 # packages I once used before and liked, but don\'t want installed now for
1739 # various reasons:
1740 # python-sqlite is used for offlineimap
1741 # lxappearance python-sqlite dolphin paman dconf-editor
1742
1743
1744
1745 ######## unfinished
1746
1747 # todo, finish configuring smart.
1748
1749 pi smartmontools
1750 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
1751 # turn on smart. background on options:
1752 # first line, -a = test everyting on all devices.
1753 # -S on, turn on disk internal saving of vendor specific info,
1754 # from google, seems like this is usually already on and fairly standard.
1755 # -o on, turn on 4 hour period non-performance degrading testing.
1756 # short test daily 2-3am, extended tests Saturdays between 3-4am:
1757 sched="-s (S/../.././02|L/../../6/03)"
1758 sudo sed -i --follow-symlinks "s#^[[:space:]]*DEVICESCAN.*#\
1759 DEVICESCAN -a -o on -S on -n standby,q $sched \
1760 -m root@mail.iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
1761
1762 # in the default configuration of at least ubuntu 14.04, resolvconf is
1763 # configured to order any nameservers associated with tun* or tap*
1764 # before the normal internet interfaces, which means they are always
1765 # consulted first. This is often slower and undesirable, ie. local dns
1766 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
1767 # can do:
1768 #sudo sed -i --follow-symlinks '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
1769 # however, this breaks dns lookup for hosts on the openvpn lan.
1770 # I can\'t figure out why hosts on the normal lan would not be
1771 # broken under the default ordering, except the host I was
1772 # testing with previously had an entry in /etc/hosts.
1773
1774 ############# end unfinished
1775
1776 ########### misc stuff
1777
1778 if [[ $HOSTNAME != frodo ]]; then
1779 # remove. i moved this into dns
1780 echo | s cedit hole /etc/hosts ||:
1781 fi
1782
1783 if [[ ! -e ~/.local/bin/pip ]]; then
1784 tmp=$(mktemp)
1785 wget -O$tmp https://bootstrap.pypa.io/get-pip.py
1786 python3 $tmp --user
1787 hash -r
1788 fi
1789
1790
1791 ### begin timetrap setup
1792 if mountpoint /p &>/dev/null; then
1793 mkdir -p ~/.timetrap/
1794 ln -sf /a/opt/timetrap_formatters ~/.timetrap/formatters
1795 if ! type -p t &>/dev/null; then
1796 pi ruby-dev libsqlite3-dev
1797 gem install --user timetrap
1798 fi
1799 fi
1800 ### end timetrap setup
1801
1802 # leftover cleanup for t9
1803 pu resolvconf
1804
1805 case $codename in
1806 # needed for debootstrap scripts for fai since fai requires debian
1807 flidas)
1808 pi dnsmasq
1809 pi-nostart network-manager
1810 # i hate networkmanager. noo, of course disabling it doesnt work
1811 # unless you add a hack. found this by doing
1812 # systemd-analyze dot > x.dot
1813 # less x.dot
1814 # /networkman
1815 soff NetworkManager
1816 soff NetworkManager-wait-online.service
1817 # make networkmanager use resolvconf instead of its own dnsmasq which
1818 # conflicts with the normal dnsmasq package.
1819 f=/etc/NetworkManager/NetworkManager.conf
1820 m=$(md5sum $f)
1821 sudo sed -ri '/ *\[main\]/,/^ *\[[^]]+\]/{/^\s*dns[[:space:]=]/d}' $f
1822 sudo sed -ri '/ *\[main\]/a dns=default' $f
1823 if [[ $m != $(md5sum $f) ]]; then
1824 srestart NetworkManager
1825 fi
1826 # networkmanager has this nasty behavior on flidas: if the machine
1827 # crashes with dnsmasq running, on subsequent boot, it adds an entry to
1828 # resolvconf for 127.0.0.1 in some stupid attempt to restore
1829 # nameservers.
1830 # This can be manually fixed by stoping dnsmasq,
1831 # then based on whats in /run/dnsmasq/, i see we can run
1832 # s resolvconf -d NetworkManager
1833 # oh ya, and stoping NetworkManager leaves this crap behind without cleaning it up.
1834 ser disable NetworkManager
1835 ;;
1836 esac
1837
1838 # I have no use for avahi,
1839 # had to run this twice when doing manually, i dunno why
1840 soff avahi-daemon ||:
1841 sleep 1
1842 soff avahi-daemon
1843
1844 # make my /etc/fonts/conf.d/ get used.
1845 # I have a new sans-serif font there because the default one
1846 # displays l and I as the same char, grrrrr.
1847 sudo fc-cache
1848
1849 pi desktop-file-utils
1850 m /a/bin/distro-setup/mymimes
1851
1852
1853 # stop autopoping windows when i plug in an android phone.
1854 # dbus-launch makes this work within an ssh connection, otherwise you get this message,
1855 # with still 0 exit code.
1856 # dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
1857 m dbus-launch gsettings set org.gnome.desktop.media-handling automount-open false
1858
1859
1860 # on grub upgrade, we get prompts unless we do this
1861 devs=()
1862 for dev in $(s btrfs fil show /boot | sed -nr 's#.*path\s+(\S+)$#\1#p'); do
1863 devs+=("$(devbyid $dev),")
1864 done
1865 devs[-1]=${devs[-1]%,} # jonied by commas
1866 sudo debconf-set-selections <<EOF
1867 grub-pc grub-pc/install_devices multiselect ${devs[*]}
1868 EOF
1869
1870
1871 sysd-prom-fail-install dynamicipupdate
1872 sysd-prom-fail-install systemstatus
1873 sysd-prom-fail-install btrfsmaintstop
1874 sgo btrfsmaint.timer
1875 sgo btrfsmaintstop
1876 sgo systemstatus
1877 sgo dynamicipupdate
1878
1879
1880 if grep -xFq $HOSTNAME /a/bin/ds/machine_specific/btrbk.hosts; then
1881 sgo btrbk.timer
1882 fi
1883 # note: to see when it was last run,
1884 # ser list-timers
1885
1886 case $HOSTNAME in
1887 kd)
1888 sgo btrbkrust.timer
1889 ;;
1890 esac
1891
1892 ### begin prometheus ###
1893
1894 case $HOSTNAME in
1895 kd)
1896 /a/bin/buildscripts/prometheus
1897 # Font awesome is needed for the alertmanager ui.
1898 pi prometheus-alertmanager prometheus prometheus-node-exporter fonts-font-awesome
1899 web-conf -p 9091 -f 9090 - apache2 i.b8.nz <<'EOF'
1900 <Location "/">
1901 AuthType Basic
1902 AuthName "basic_auth"
1903 # created with
1904 # htpasswd -c prometheus-htpasswd USERNAME
1905 AuthUserFile "/etc/prometheus-htpasswd"
1906 Require valid-user
1907 </Location>
1908 EOF
1909
1910 web-conf -p 9094 -f 9093 - apache2 i.b8.nz <<'EOF'
1911 <Location "/">
1912 AuthType Basic
1913 AuthName "basic_auth"
1914 # created with
1915 # htpasswd -c prometheus-htpasswd USERNAME
1916 AuthUserFile "/etc/prometheus-htpasswd"
1917 Require valid-user
1918 </Location>
1919 EOF
1920
1921 # by default, the alertmanager web ui is not enabled other than a page
1922 # that suggests to use the amtool cli. that tool is good, but you cant
1923 # silence things nearly as fast.
1924 if [[ ! -e /usr/share/prometheus/alertmanager/ui/index.html ]]; then
1925 sudo chroot /nocow/schroot/bullseye prometheus-alertmanager
1926 sudo chroot /nocow/schroot/bullseye /usr/share/prometheus/alertmanager/generate-ui.sh
1927 sudo rsync -avih /nocow/schroot/bullseye/usr/share/prometheus/alertmanager/ui/ /usr/share/prometheus/alertmanager/ui
1928 ser restart prometheus-alertmanager
1929 fi
1930
1931 for ser in prometheus-node-exporter prometheus-alertmanager prometheus; do
1932 sysd-prom-fail-install $ser
1933 done
1934
1935 ;;
1936 *)
1937 pi prometheus-node-exporter
1938 ;;
1939 esac
1940
1941 case $HOSTNAME in
1942 # frodo needs upgrade first.
1943 frodo) : ;;
1944 # todo, for limiting node exporter http,
1945 # either use iptables or, in
1946 # /etc/default/prometheus-node-exporter
1947 # listen on the wireguard interface
1948 *)
1949 wgip=$(command sudo sed -rn 's,^ *Address *= *([^/]+).*,\1,p' /etc/wireguard/wghole.conf)
1950 # old filename. remove once all hosts are updated.
1951 s rm -fv /etc/apache2/sites-enabled/${HOSTNAME}wg.b8.nz.conf
1952 web-conf -i -a $wgip -p 9101 -f 9100 - apache2 ${HOSTNAME}wg.b8.nz <<'EOF'
1953 <Location "/">
1954 AuthType Basic
1955 AuthName "basic_auth"
1956 # created with
1957 # htpasswd -c prometheus-export-htpasswd USERNAME
1958 AuthUserFile "/etc/prometheus-export-htpasswd"
1959 Require valid-user
1960 </Location>
1961 EOF
1962 # For work, i think we will just use the firewall for hosts in the main data center, and
1963 # vpn for hosts outside it.
1964
1965 # TODO: figure out how to detect the ping failure and try again.
1966
1967 # Binding to the wg interface, it might go down, so always restart, and wait for it on boot.
1968 s mkdir /etc/systemd/system/apache2.service.d
1969 sd /etc/systemd/system/apache2.service.d/restart.conf <<EOF
1970 [Unit]
1971 After=wg-quick@wghole.service
1972 StartLimitIntervalSec=0
1973
1974 [Service]
1975 Restart=always
1976 RestartSec=30
1977 EOF
1978
1979 ;;
1980 esac
1981
1982 ### end prometheus ###
1983
1984
1985 end_msg <<'EOF'
1986 In mate settings settings, change scrolling to two-finger,
1987 because the default edge scroll doesn\'t work. Originally found this in debian.
1988 EOF
1989
1990 # Remove dep that came in with desktop to fix associations.
1991 m pu transmission-gtk
1992
1993 case $HOSTNAME in
1994 kd)
1995 lnf -T /d/vidshare /home/iank/Videos
1996 ;;
1997 esac
1998
1999 # # Based on guix manual instructions, also added code to profile.
2000 # # disabled since i'm not using it now.
2001 # pi nscd
2002 # if ! type -p guix >/dev/null; then
2003 # cd $(mktemp -d)
2004 # wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
2005 # # added some stuff to envonment.sh for profile based on
2006 # # manual instructions
2007 # # wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
2008 # # echo is to get past prompt
2009 # yes | sudo -E HOME=$HOME bash guix-install.sh || [[ $? == 141 ]]
2010 # guix install glibc-utf8-locales
2011 # guix package --install guile
2012 # fi
2013
2014 lnf -T /a/opt ~/src
2015
2016 pi tor
2017 m /a/bin/buildscripts/tor-browser
2018 # one root command needed to install
2019 s ln -sf /a/opt/tor-browser_en-US/Browser/start-tor-browser /usr/local/bin
2020
2021
2022 # nfs server
2023 pi-nostart nfs-kernel-server
2024
2025 # todo, this is old, probably needs removing
2026 if [[ $HOSTNAME == tp ]]; then
2027 sd /etc/wireguard/wg0.conf <<EOF
2028 [Interface]
2029 PrivateKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.key)
2030 Address = 10.3.0.2/24, fdfd::2/64
2031
2032 [Peer]
2033 PresharedKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.psk)
2034 PublicKey = 9RnAsJB+ISrA/9lmDKBoT08oBiKwzA64exBBj+rO+ng=
2035 Endpoint = b8.nz:26000
2036 AllowedIPs = 10.3.0.1/24, fdfd::1/64
2037 PersistentKeepalive = 20
2038 EOF
2039 sudo systemctl enable wg-quick@wg0
2040 sudo systemctl start wg-quick@wg0
2041 fi
2042
2043
2044 if [[ $HOSTNAME == kw ]]; then
2045 # hosts 1-199. 200+ are dynamic, avoid those
2046 tu /etc/exports <<'EOF'
2047 /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)
2048 /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)
2049 EOF
2050 ekw
2051 sgo nfs-server
2052 sudo exportfs -rav
2053 fi
2054
2055
2056 # if I was going to create a persistent vm, i might do it like this:
2057 # variant=something # from: virt-install --os-variant list
2058 # s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
2059 # --disk=/a/images/some_name.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
2060 # -n some_name --import --os-variant $variant --cpu host-model-only
2061
2062
2063 # for brother HL-2270DW, this worked:
2064 # https://askubuntu.com/questions/1067234/cant-use-wireless-brother-printer-2270dw-ubuntu-18-04
2065 # /a/opt/linux-brprinter-installer-2.2.2-1
2066 # answer n when it asks about uri.
2067 # Then go to cups, delete the existing printer, added on with dnssd url. browsed to
2068 # ppd at /usr/share/ppd/HL2270DW.ppd, which is duplicated at /usr/share/cups/model/HL2270DW.ppd
2069 # ppd file got installed from bash -x ./usr/local/Brother/Printer/HL2270DW/cupswrapper/cupswrap,
2070 # which I downloaded from their driver. but dont do that again, i copied it to /a/opt/HL2270DW.ppd,
2071 # use that.
2072
2073 # 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.
2074 # Then it was already configured, but if i needed to, go to its web ui, default pass is "access".
2075
2076 ######### begin stuff belonging at the end ##########
2077
2078 end