various fixes and updates
[distro-setup] / distro-end
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4 if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
5
6 ### setup
7 source /a/bin/errhandle/err
8 src="$(readlink -f -- "${BASH_SOURCE[0]}")"; src=${src%/*} # directory of this file
9
10 if [[ $EUID == 0 ]]; then
11 echo "$0: error: run as regular user" >&2
12 exit 1
13 fi
14
15 err-cleanup() {
16 echo 1 >~/.local/distro-end
17 }
18
19 # shellcheck source=./pkgs
20 source $src/pkgs
21
22 echo "$0: $(date) starting now)"
23 # see example of usage to understand.
24 end_msg() {
25 local y
26 IFS= read -r -d '' y ||:
27 end_msg_var+="$y"
28 }
29 end() {
30 e "$end_msg_var"
31 echo 0 >~/.local/distro-end
32 if $pending_reboot; then
33 echo "$0: pending reboot and then finished. doing it now."
34 echo "exiting with status 0"
35 sudo reboot now
36 else
37 echo "$0: $(date): ending now)"
38 echo "exiting with status 0"
39 fi
40 exit 0
41 }
42 pre="${0##*/}:"
43 sudo() {
44 printf "$pre %s\n" "$*"
45 SUDOD="$PWD" command sudo "$@";
46 }
47 sd() {
48 sudo dd of="$1" 2>/dev/null
49 }
50 m() { printf "$pre %s\n" "$*"; "$@"; }
51 e() { printf "$pre %s\n" "$*"; }
52 err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; }
53 distro=$(distro-name)
54 codename=$(debian-codename)
55 codename_compat=$(debian-codename-compat)
56 pending_reboot=false
57 sed="sed --follow-symlinks"
58 ## template:
59 # case $distro in
60 # esac
61
62 #### initial packages
63 pup
64 if isdeb; then
65 pi aptitude
66 fi
67
68 # avoid prompts
69 sudo debconf-set-selections <<EOF
70 popularity-contest popularity-contest/participate boolean true
71 EOF
72
73 ########### begin section including linode ################
74 pi ${p2[@]}
75
76
77 conflink
78
79 # no equivalent in other distros:
80 if isdeb && pcheck apt-file; then
81 # this condition is just a speed optimization
82 pi apt-file
83 sudo apt-file update
84 fi
85
86
87 # disable motd junk.
88 case $distro in
89 debian)
90 # allows me to pipe with ssh -t, and gets rid of spam
91 # http://forums.debian.net/viewtopic.php?f=5&t=85822
92 # i'd rather disable the service than comment the init file
93 # this says disabling the service, it will still get restarted
94 # but this script doesn't do anything on restart, so it should be fine
95 sudo truncate -s0 /var/run/motd.dynamic
96 ;;
97 trisquel|ubuntu)
98 # this isn't a complete solution. It still shows me when updates are available,
99 # but it's no big deal.
100 sudo rm -fv /etc/update-motd.d/10-help-text /etc/update-motd.d/00-header
101 ;;
102 esac
103
104
105
106
107 ### begin certbot install ###
108 if [[ $distro == debian || $codename_compat == bionic ]]; then
109 # note, need python-certbot-nginx for nginx, but it depends on nginx,
110 # and I'm not installing nginx by default right now.
111 pi certbot python3-certbot-apache
112 elif [[ $codename_compat == xenial ]]; then
113 # not packaged in xenial or flidas
114 pi software-properties-common
115 l="deb http://ppa.launchpad.net/certbot/certbot/ubuntu xenial main"
116 if ! grep -xFq "$l" /etc/apt/sources.list{,.d/*.list}; then
117 sudo add-apt-repository -y ppa:certbot/certbot ||:
118 m p update
119 fi
120 pi python-certbot-apache
121 else
122 err "distro unknown for certbot"
123 fi
124 # make a version of the certbot timer that emails me.
125 x=/systemd/system/certbot
126 $sed -r -f - /lib$x.timer <<'EOF' |sd /etc${x}mail.timer
127 s,^Description.*,\0 mail version,
128 EOF
129 $sed -r -f - /lib$x.service <<'EOF' |sd /etc${x}mail.service
130 s,(ExecStart=)(/usr/bin/certbot),\1/a/bin/log-quiet/sysd-mail-once certbotmail \2 --renew-hook /a/bin/distro-setup/certbot-renew-hook,
131 EOF
132 ser daemon-reload
133 sgo certbotmail.timer
134 ### end certbot install ###
135
136
137 # dogcam setup. not using atm
138 # case $HOSTNAME in
139 # lj|li)
140 # /a/bin/webcam/install-server
141 # ;;
142 # kw)
143 # /a/bin/webcam/install-client
144 # ;;
145 # esac
146
147
148 ## not actually using prometheus just yet
149 # # office is not exposed to internet yet
150 # if [[ $HOSTNAME != kw ]]; then
151 # ## prometheus node exporter setup
152 # web-conf -f 9100 -p 9101 apache2 $(hostname -f) <<'EOF'
153 # #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
154 # # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
155 # <Location />
156 # AllowOverride None
157 # AuthType basic
158 # AuthName "Authentication Required"
159 # # setup one time, with root:www-data, 640
160 # AuthUserFile "/etc/prometheus-htpasswd"
161 # Require valid-user
162 # </Location>
163 # EOF
164 # fi
165
166
167 ######### begin flidas pinned packages ######
168 case $(debian-codename) in
169 # needed for debootstrap scripts for fai since fai requires debian
170 flidas)
171 curl http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg | s apt-key add -
172 sd /etc/apt/preferences.d/flidas-xenial <<EOF
173 Package: *
174 Pin: release a=xenial
175 Pin-Priority: -100
176
177 Package: *
178 Pin: release a=xenial-updates
179 Pin-Priority: -100
180
181 Package: *
182 Pin: release a=xenial-security
183 Pin-Priority: -100
184
185 Package: firefox
186 Pin: release n=xenial
187 Pin-Priority: 500
188 EOF
189 sd /etc/apt/sources.list.d/xenial.list 2>/dev/null <<EOF
190 deb http://us.archive.ubuntu.com/ubuntu/ xenial main
191 deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main
192 deb http://us.archive.ubuntu.com/ubuntu/ xenial-security main
193 EOF
194
195 if ! apt-key list | grep /C0B21F32 &>/dev/null; then
196 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
197 sd /etc/apt/preferences.d/flidas-bionic <<EOF
198 Package: *
199 Pin: release a=bionic
200 Pin-Priority: -100
201
202 Package: *
203 Pin: release a=bionic-updates
204 Pin-Priority: -100
205
206 Package: *
207 Pin: release a=bionic-security
208 Pin-Priority: -100
209 EOF
210 fi
211
212 # better to run btrfs-progs which matches our kernel version
213 # (note, renamed from btrfs-tools)
214 sd /etc/apt/preferences.d/btrfs-progs <<EOF
215 Package: btrfs-progs libzstd1
216 Pin: release a=bionic
217 Pin-Priority: 1005
218
219 Package: btrfs-progs libzstd1
220 Pin: release a=bionic-updates
221 Pin-Priority: 1005
222
223 Package: btrfs-progs libzstd1
224 Pin: release a=bionic-security
225 Pin-Priority: 1005
226 EOF
227
228
229 t=$(mktemp)
230 cat >$t <<EOF
231 deb http://us.archive.ubuntu.com/ubuntu/ bionic main
232 deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main
233 deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main
234 EOF
235 f=/etc/apt/sources.list.d/bionic.list
236 if ! diff -q $t $f; then
237 sudo cp $t $f
238 sudo chmod 644 $f
239 m p update
240 fi
241
242 # no special reason, but its better for btrfs-progs to
243 # be closer to our kernel version
244 pi btrfs-progs
245
246 if [[ ! -e /usr/share/debootstrap/scripts/xenial ]]; then
247 t=$(mktemp -d)
248 cd $t
249 m aptitude download debootstrap/xenial
250 m ex ./*
251 sudo cp ./usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
252 fi
253
254 sd /etc/apt/preferences.d/flidas-etiona <<EOF
255 Package: *
256 Pin: release a=etiona
257 Pin-Priority: -100
258
259 Package: *
260 Pin: release a=etiona-updates
261 Pin-Priority: -100
262
263 Package: *
264 Pin: release a=etiona-security
265 Pin-Priority: -100
266
267 Package: *
268 Pin: release a=etiona-backports
269 Pin-Priority: -100
270 EOF
271
272 t=$(mktemp)
273 cat >$t <<EOF
274 deb http://mirror.fsf.org/trisquel/ etiona main
275 deb http://mirror.fsf.org/trisquel/ etiona-updates main
276 deb http://archive.trisquel.info/trisquel/ etiona-security main
277 deb http://mirror.fsf.org/trisquel/ etiona-backports main
278 EOF
279 f=/etc/apt/sources.list.d/etiona.list
280 if ! diff -q $t $f; then
281 sudo cp $t $f
282 n s chmod 644 $f
283 m p update
284 fi
285
286 sd /etc/apt/preferences.d/debian-goodies <<EOF
287 Package: debian-goodies
288 Pin: release n=etiona
289 Pin-Priority: 1005
290 EOF
291
292
293 sd /etc/apt/preferences.d/flidas-buster <<EOF
294 Package: *
295 Pin: release n=buster
296 Pin-Priority: -100
297
298 Package: *
299 Pin: release n=buster-updates
300 Pin-Priority: -100
301 EOF
302
303 # dont use buster because it causes dist-upgrade to think its downgrading
304 # packages while really just reinstalling the same version.
305 f=/etc/apt/apt.conf.d/01iank
306 sudo rm -fv $f
307 # # stupid buster uses some key algorithm not supported by flidas gpg that apt uses.
308 # sd /etc/apt/apt.conf.d/01iank <<'EOF'
309 # Acquire::AllowInsecureRepositories "true";
310 # EOF
311
312 f=/etc/apt/sources.list.d/buster.list
313 sudo rm -fv $f
314 # t=$(mktemp)
315 # cat >$t <<EOF
316 # deb http://http.us.debian.org/debian buster main
317 # deb-src http://http.us.debian.org/debian buster main
318
319 # deb http://security.debian.org/ buster/updates main
320 # deb-src http://security.debian.org/ buster/updates main
321
322 # deb http://http.us.debian.org/debian buster-updates main
323 # deb-src http://http.us.debian.org/debian buster-updates main
324 # EOF
325 # if ! diff -q $t $f; then
326 # s cp $t $f
327 # s chmod 644 $f
328 # p update
329 # fi
330
331 # newer version needed for false positive in checkrestart.
332 # I did buster at first, but other problem above with having
333 # buster repos. not sure if the false positive exists in etiona.
334 pi debian-goodies
335
336 sd /etc/apt/preferences.d/shellcheck <<EOF
337 Package: shellcheck
338 Pin: release a=etiona
339 Pin-Priority: 1005
340
341 Package: shellcheck
342 Pin: release a=etiona-updates
343 Pin-Priority: 1005
344
345 Package: shellcheck
346 Pin: release a=etiona-security
347 Pin-Priority: 1005
348 EOF
349
350 sd /etc/apt/preferences.d/bash <<EOF
351 Package: bash
352 Pin: release a=etiona
353 Pin-Priority: 1005
354
355 Package: bash
356 Pin: release a=etiona-updates
357 Pin-Priority: 1005
358
359 Package: bash
360 Pin: release a=etiona-security
361 Pin-Priority: 1005
362 EOF
363
364
365 ;;
366 *)
367 if isdeb; then
368 pi debian-goodies shellcheck
369 fi
370 ;;
371 esac
372 ######### end flidas pinned packages ######
373
374 ##### begin automatic upgrades (after checkrestart has been installed) ####
375 sd /etc/apt/apt.conf.d/10periodic <<'EOF'
376 # this file was mostly just comments.
377 APT::Periodic::Update-Package-Lists "1";
378 APT::Periodic::Download-Upgradeable-Packages "1";
379 APT::Periodic::AutocleanInterval "7";
380 APT::Periodic::Unattended-Upgrade "1";
381 EOF
382
383 sd /etc/apt/apt.conf.d/50unattended-upgrades <<EOF
384 # fyi: default file has comments about available options,
385 # you may want to read that, do pkx unattended-upgrades
386 Unattended-Upgrade::Mail "root";
387 Unattended-Upgrade::MailOnlyOnError "true";
388 Unattended-Upgrade::Remove-Unused-Dependencies "true";
389 Unattended-Upgrade::Origins-Pattern {
390 # default is just security updates. this list found from reading
391 # match_whitelist_string() in $(which unattended-upgrades)
392 "o=*,l=*,a=*,c=*,site=*,n=*";
393 };
394 EOF
395
396 # old names, too verbose
397 sudo rm -f /etc/cron.d/unattended-upgrade-reboot /usr/local/bin/zelous-unattended-reboot
398
399 sd /etc/cron.d/myupgrade <<'EOF'
400 # Setup reboots when running outdated stuff, unattended upgrades happen
401 # at 6 am + rand(60 min).
402
403 # default is /bin/sh
404 SHELL=/bin/bash
405 # default is /usr/bin:/bin
406 PATH=/usr/bin:/bin:/usr/local/bin
407 20 7 * * * iank myupgrade |& log-once -1 myupgrade
408 0 * * * * root mycheckrestart |& log-once -1 mycheckrestart
409 EOF
410 ##### end automatic upgrades ####
411
412
413
414 ###### begin website setup
415 case $HOSTNAME in
416 li|l2)
417 pi bind9
418 f=/var/lib/bind/db.b8.nz
419 if [[ ! -e $f ]]; then
420 ser stop bind9
421 sudo rm -fv $f.jnl
422 sudo install -m 644 -o bind -g bind /p/c/machine_specific/linode/bind-initial/db.b8.nz $f
423 ser restart bind9
424 fi
425 ;;&
426 l2)
427 # setup let's encrypt cert
428 m web-conf apache2 l2.b8.nz
429 sudo rm -fv /etc/apache2/sites-enabled/l2.b8.nz{,-redir}.conf
430 ser reload apache2
431 s lnf -T /etc/letsencrypt/live/l2.b8.nz/fullchain.pem /etc/exim4/exim.crt
432 if [[ ! -L /etc/exim4/exim.key ]]; then
433 s lnf -T /etc/letsencrypt/live/l2.b8.nz/privkey.pem /etc/exim4/exim.key
434 mail-setup
435 fi
436 end
437 ;;
438 li)
439
440 case $HOSTNAME in
441 li)
442 m /a/h/setup.sh iankelling.org
443 ;;
444 tp)
445 m /a/h/setup.sh -s b8.nz
446 ;;
447 *)
448 # allow symlinks on non-main hosts so i can host files in arbitrary paths
449 m /a/h/setup.sh -s -p 80
450 ;;
451 esac
452 m /a/h/build.rb
453
454 # start mumble only when im going to use it, since i dont use it much
455 pi-nostart mumble-server
456 sudo $sed -ri "s/^ *(serverpassword=).*/\1$(< /a/bin/bash_unpublished/mumble_pass)/" /etc/mumble-server.ini
457
458 # do certificate to avoid warning about unsigned cert,
459 # which is overkill for my use, but hey, I'm cool, I know
460 # how to do this.
461 m web-conf apache2 mumble.iankelling.org
462 sudo rm -fv /etc/apache2/sites-enabled/mumble.iankelling.org
463 s <<'EOF'
464 export RENEWED_LINEAGE=/etc/letsencrypt/live/mumble.iankelling.org
465 /a/bin/distro-setup/certbot-renew-hook
466 EOF
467
468
469 # requested from linode via a support ticket.
470 # https://www.linode.com/docs/networking/an-overview-of-ipv6-on-linode/
471 # ipv6 stuff pieced together
472 # via slightly wrong information from
473 # https://github.com/angristan/openvpn-install/blob/master/openvpn-install.sh
474 # https://community.openvpn.net/openvpn/wiki/IPv6
475 # and man openvpn
476
477 m vpn-server-setup -rd 2600:3c00:e000:280::1/64 2600:3c00::f03c:91ff:feb4:0bf3
478 sudo tee /etc/openvpn/client-config/mail <<'EOF'
479 ifconfig-push 10.8.0.4 255.255.255.0
480 ifconfig-ipv6-push 2600:3c00:e000:280::2/64
481 EOF
482
483 if [[ -e /lib/systemd/system/openvpn-server@.service ]]; then
484 vpn_service=openvpn-server@server
485 else
486 vpn_service=openvpn@server
487 fi
488
489 sudo dd of=/etc/systemd/system/vpnmail.service <<EOF
490 [Unit]
491 Description=Turns on iptables mail nat
492
493 [Service]
494 Type=oneshot
495 RemainAfterExit=yes
496 ExecStart=/a/bin/distro-setup/vpn-mail-forward start
497 ExecStop=/a/bin/distro-setup/vpn-mail-forward stop
498
499 [Install]
500 WantedBy=$vpn_service.service
501 EOF
502 ser daemon-reload
503 sgo vpnmail.service
504 # needed for li's local mail delivery.
505 tu /etc/hosts <<<"10.8.0.4 mail.iankelling.org"
506 sgo $vpn_service
507 # setup let's encrypt cert
508 m web-conf apache2 mail.iankelling.org
509 sudo rm -fv /etc/apache2/sites-enabled/mail.iankelling.org{,-redir}.conf
510 ser reload apache2
511
512 domain=cal.iankelling.org
513 web-conf -f 10.8.0.4:5232 - apache2 $domain <<'EOF'
514 #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
515 # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
516 <Location />
517 Options +FollowSymLinks +Multiviews +Indexes
518 AllowOverride None
519 AuthType basic
520 AuthName "Authentication Required"
521 # setup one time, with root:www-data, 640
522 AuthUserFile "/etc/caldav-htpasswd"
523 Require valid-user
524 </Location>
525 EOF
526 # nginx version of above would be:
527 # auth_basic "Not currently available";
528 # auth_basic_user_file /etc/nginx/caldav/htpasswd;
529
530
531
532 ###### begin znc setup #####
533 pi znc
534
535 # https://wiki.znc.in/FAQ seems to imply that znc doesn\'t need restart after cert change.
536 # to get into the web interface,
537 # then use non-main browser or else it doebsn't allow it based on ocsp stapling from my main site.
538 # https://iankelling.org:12533/
539 s <<'EOF'
540 export RENEWED_LINEAGE=/etc/letsencrypt/live/iankelling.org
541 /a/bin/distro-setup/certbot-renew-hook
542 EOF
543
544 # znc config generated by doing
545 # znc --makeconf
546 # selected port is also used in erc config
547 # comma separated channel list worked.
548 # while figuring things out, running znc -D for debug in foreground.
549 # to exit and save config:
550 # /msg *status shutdown
551 # configed auth on freenode by following
552 # https://wiki.znc.in/Sasl:
553 # /msg *sasl RequireAuth yes
554 # /msg *sasl Mechanism PLAIN
555 # /msg *sasl Set ident_name password
556 # created the system service after, and had to do
557 # mv /home/iank/.znc/* /var/lib/znc
558 # sed -i 's,/home/iank/.znc/,/var/lib/znc,' /var/lib/znc/config/znc.conf
559 # and made a copy of the config files into /p/c
560 # /msg *status LoadMod --type=global log -sanitize
561 # todo: in config file AllowWeb = true should be false. better security if that is off unless we need it.
562 # /msg *status LoadMod --type=network perform
563 # /msg *perform add PRIVMSG ChanServ :invite #fsf-office
564 # /msg *perform add JOIN #fsf-office
565 #
566 # i set Buffer = 500
567 # also ran /znc LoadMod clearbufferonmsg
568 # it would be nice if erc supported erc query buffers by doing
569 # /msg *status clearbuffer <name of the query/receiver
570 # on killing the,
571 # an example seems to be here: https://github.com/zenspider/elisp/blob/master/rwd-irc.el
572 # if that was the case i could remove the module clearbufferonmsg
573 # also would be nice if erc supported
574 # https://wiki.znc.in/self-message
575 # https://wiki.znc.in/Query_buffers \
576 #
577 if ! getent passwd znc > /dev/null; then
578 sudo useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
579 fi
580 sudo chmod 700 /var/lib/znc
581 sudo chown -R znc:znc /var/lib/znc
582 # Avoid restarting if possible, reconnecting to irc is annoying.
583 # The unit file was made active with conflink.
584 # Note, avoid using ser here because we wrap sudo to prints the command first.
585 if [[ $(systemctl is-active znc) != active ]]; then
586 sgo znc
587 fi
588 ###### stop znc setup #####
589
590 end
591 ;;
592 esac
593 ###### end website setup
594
595 ########### end section including li/lj ###############
596
597 #### desktop stuff
598 case $codename_compat in
599 xenial)
600 # mate-indicator-applet and beyond are msc things I noticed diffing a
601 # standard install with mine.
602 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras mate-indicator-applet anacron
603 ;;
604 stretch)
605 pi task-mate-desktop
606 ;;
607 buster)
608 # mate doesnt have wayland support yet
609 pi task-gnome-desktop
610 ;;
611 bionic)
612 pi gnome-core
613 # by default, it sleeps when not logged in to x/wayland and on ac power.
614 # stop that.
615 sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
616 systemctl --user stop gvfs-daemon
617 systemctl --user disable gvfs-daemon
618 ;;
619 esac
620
621
622 if [[ $codename_compat == flidas ]]; then
623 # doesnt exist in newer
624 pi gnupg-doc
625 fi
626
627 # abrowser is not in etiona yet, abrowser version is 68,
628 # abrowser won't run on a firefox profile that was on firefox
629 # version 70. firefox in ubuntu is at version 70.
630 # have to rm compabibility.ini to even try downgrade.
631 pi firefox
632 sudo update-alternatives --set x-www-browser /usr/bin/firefox
633
634 # TODO: some of the X programs can be removed from pall when using wayland
635
636 # depends gcc is a way to install suggests. this is apparently the only
637 # way to install suggests even if the main package is already
638 # installed. reinstall doesn't work, uninstalling can cause removing
639 # dependent packages.
640 pi ${pall[@]} $(apt-cache search ruby[.0-9]+-doc| awk '{print $1}') $(apt-cache depends gcc|grep -i suggests:| awk '{print $2}') $($src/distro-pkgs)
641
642
643 # website is dead june 14 2019. back in october, but meh
644 sudo rm -fv /etc/apt/sources.list.d/iridium-browser.list
645 # case $distro in
646 # debian)
647 # pi chromium ;;
648 # trisquel|ubuntu)
649 # wget -qO - https://downloads.iridiumbrowser.de/ubuntu/iridium-release-sign-01.pub|sudo apt-key add -
650 # t=$(mktemp)
651 # cat >$t <<EOF
652 # deb [arch=amd64] https://downloads.iridiumbrowser.de/deb/ stable main
653 # #deb-src https://downloads.iridiumbrowser.de/deb/ stable main
654 # EOF
655 # f=/etc/apt/sources.list.d/iridium-browser.list
656 # if ! diff -q $t $f; then
657 # s cp $t $f
658 # s chmod 644 $f
659 # p update
660 # fi
661 # pi iridium-browser
662 # ;;
663 # esac
664
665
666 ### begin home vpn server setup
667
668
669 # # this section done initially to make persistent keys.
670 # # Also note, I temporarily set /etc/hosts so my host was
671 # # b8.nz when running this, since the vpn client config
672 # # generator assumes we need to go to that server to get
673 # # server keys.
674 # vpn-server-setup -rds
675 # s cp -r --parents /etc/openvpn/easy-rsa/keys /p/c/filesystem
676 # s chown -R 1000:1000 /p/c/filesystem/etc/openvpn/easy-rsa/keys
677 # # kw = kgpe work machine.
678 # for host in x2 x3 kw; do
679 # vpn-mk-client-cert -b $host -n home b8.nz 1196
680 # dir=/p/c/machine_specific/$host/filesystem/etc/openvpn/client
681 # mkdir -p $dir
682 # s bash -c "cp /etc/openvpn/client/home* $dir"
683 # # note: /etc/update-resolv-conf-home also exists for all systems with /p
684 # done
685
686 # key already exists, so this won't generate one, just the configs.
687 m vpn-server-setup -rds
688 sudo tee -a /etc/openvpn/server/server.conf <<'EOF'
689 push "dhcp-option DNS 10.0.0.1"
690 push "route 10.0.0.0 255.255.0.0"
691 client-connect /a/bin/distro-setup/vpn-client-connect
692 EOF
693 sudo sed -i --follow-symlinks 's/10.8./10.9./g;s/^\s*port\s.*/port 1196/' /etc/openvpn/server/server.conf
694
695 if [[ $HOSTNAME == tp ]]; then
696 if [[ -e /lib/systemd/system/openvpn-server@.service ]]; then
697 vpn_service=openvpn-server@server
698 else
699 vpn_service=openvpn@server
700 fi
701 sgo $vpn_service
702 fi
703 ### end vpn server setup
704
705
706 ##### rss2email
707 # note, see bashrc for more documentation.
708 pi rss2email
709 sd /etc/systemd/system/rss2email.service <<'EOF'
710 [Unit]
711 Description=rss2email
712 After=multi-user.target
713
714 [Service]
715 User=iank
716 Type=oneshot
717 # about 24 hours of failures
718 # it copies over its files without respecting symlinks, so
719 # we pass options to use different location.
720 ExecStart=/a/bin/log-quiet/sysd-mail-once -288 rss2email r2e -d /p/c/rss2email.json -c /p/c/rss2email.cfg run
721 EOF
722 sd /etc/systemd/system/rss2email.timer <<'EOF'
723 [Unit]
724 Description=rss2email
725
726 [Timer]
727 # for initial run. required.
728 OnActiveSec=30
729 # for subsequent runs.
730 OnUnitInactiveSec=300
731
732 [Install]
733 WantedBy=timers.target
734 EOF
735 sudo systemctl daemon-reload
736
737
738 ######### begin pump.io periodic backup #############
739 if [[ $HOSTNAME == frodo ]]; then
740 sd /etc/systemd/system/pumpbackup.service <<'EOF'
741 [Unit]
742 Description=pump li backup
743 After=multi-user.target
744
745 [Service]
746 User=iank
747 Type=oneshot
748 ExecStart=/a/bin/log-quiet/sysd-mail-once pump-backup /a/bin/distro-setup/pump-backup
749 EOF
750 sd /etc/systemd/system/pumpbackup.timer <<'EOF'
751 [Unit]
752 Description=pump li backup hourly
753
754 [Timer]
755 OnCalendar=hourly
756
757 [Install]
758 WantedBy=timers.target
759 EOF
760 ser daemon-reload
761 sgo pumpbackup.timer
762 fi
763 ######### end pump.io periodic backup #############
764
765
766 ######### begin irc periodic backup #############
767 if [[ $HOSTNAME == frodo ]]; then
768 sd /etc/systemd/system/ircbackup.service <<'EOF'
769 [Unit]
770 Description=irc li backup
771 After=multi-user.target
772
773 [Service]
774 User=iank
775 Type=oneshot
776 ExecStart=/a/bin/log-quiet/sysd-mail-once irc-backup rsync -rlptDhSAX root@iankelling.org:/var/lib/znc/moddata/log/iank/freenode/ /k/irclogs
777 EOF
778 sd /etc/systemd/system/ircbackup.timer <<'EOF'
779 [Unit]
780 Description=irc li backup hourly
781
782 [Timer]
783 OnCalendar=hourly
784
785 [Install]
786 WantedBy=timers.target
787 EOF
788 sudo systemctl daemon-reload
789 sgo ircbackup.timer
790 fi
791
792
793 ######### end irc periodic backup #############
794
795
796 case $distro in
797 debian|trisquel|ubuntu)
798 # suggests resolvconf package. installing it here is redundant, but make sure anyways.
799 # todo: check other distros to make sure it\'s installed
800 pi-nostart openvpn resolvconf
801 # pi-nostart does not disable
802 ser disable openvpn
803 ;;
804 *) pi openvpn;;
805 esac
806
807 m /a/bin/distro-setup/radicale-setup
808
809
810 ############# begin syncthing setup ###########
811 if [[ $HOSTNAME == frodo ]]; then
812 # It\'s simpler to just worry about running it in one place for now.
813 # I assume it would work to clone it\'s config to another non-phone
814 # and just run it in one place instead of the normal having a
815 # separate config. I lean toward using the same config, since btrfs
816 # syncs between comps.
817 # testing has relatively up to date packages
818 if ! isdebian-testing; then
819 # based on error when doing apt-get update:
820 # E: The method driver /usr/lib/apt/methods/https could not be found.
821 pi apt-transport-https
822 # google led me here:
823 # https://apt.syncthing.net/
824 curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
825 s="deb http://apt.syncthing.net/ syncthing release"
826 if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != "$s" ]]; then
827 echo "$s" | sd /etc/apt/sources.list.d/syncthing.list
828 p update
829 fi
830 fi
831 pi syncthing
832 m lnf -T /w/syncthing /home/iank/.config/syncthing
833 ser daemon-reload # syncthing likely not properly packaged
834 sgo syncthing@iank # runs as iank
835
836 # these things persist in ~/.config/syncthing, which I save in
837 # /w/syncthing (not in /p, because syncthing should continue to
838 # run on home server even when using laptop as primary device)
839 # open http://localhost:8384/
840 # change listen address from default to tcp://:22001,
841 # this is because we do port forward so it doesn\'t have to use
842 # some external server, but the syncthing is broken for port forward,
843 # you get a message, something "like connected to myself, this should not happen"
844 # when connecting to other local devices, so I bump the port up by 1,
845 # based on
846 # https://forum.syncthing.net/t/connected-to-myself-should-not-happen/1763/19.
847 # Without this, it was being stuck syncing at 0%.
848 # Set gui username and password.
849 #
850 # install syncthing via f-droid,
851 # folder setting, turn off send only.
852 # on phone, add device, click bar code icon
853 # on dekstop, top right, actions, device id
854 # after adding, notification will appear on desktop to confirm
855 #
856 # syncing folder. from phone to desktop: select desktop in the
857 # folder on phone\'s sync options, notification will appear in
858 # desktop\'s web ui within a minute. For the reverse, the
859 # notification will appear in android\'s notifications, you have to
860 # swipe down and tap it to add the folder. It won\'t appear in the
861 # syncthing ui, which would be intuitive, but don\'t wait for it
862 # there. The notification may not work, instead open the web gui
863 # from in the app, there should be a notification within there.
864 #
865 # On phone, set settings to run syncthing all the time, and
866 # show no notification.
867 #
868 # Folder versioning would make sense if I didn\'t already use btrfs
869 # for backups. I would choose staggered, or trash can for more space.
870 #
871 # if needed to install on a remote comp:
872 # ssh -L 8384:localhost:8384 -N frodo
873 # open http://localhost:8384/
874 #
875 # Note, the other thing i did was port forward port 22000,
876 # per https://docs.syncthing.net/users/firewall.html
877
878 fi
879 ############# end syncthing setup ###########
880
881
882
883 ####### begin misc packages ###########
884
885 case $codename in
886 flidas)
887 :
888 ;;
889 esac
890
891
892 # sakura config is owned by ian
893 m reset-sakura
894 m reset-konsole
895 m sudo -u user2 -i reset-konsole
896 # user2 xscreensaver we don't want to reset
897 m reset-xscreensaver
898
899
900 # this would install from cabal for newer / consistent version across os, but it screws up xmonad, so disabled for now.
901 # this is also in primary-setup
902 # pi libxss-dev # dependency based on build failure
903 # cabal update
904 # cabal install --upgrade-dependencies --force-reinstalls arbtt
905 # also, i assume syncing this between machines somehow messed thin
906 #lnf -T /m/arbtt-capture.log ~/.arbtt/capture.log
907
908 m primary-setup
909
910 if [[ ! -e ~/.linphonerc && -e /p/.linphonerc-initial ]]; then
911 m cp /p/.linphonerc-initial ~/.linphonerc
912 fi
913
914
915 ### begin spd install
916 pi libswitch-perl libdigest-md5-file-perl libgnupg-interface-perl
917 t=$(mktemp)
918 m wget -O $t http://mirror.fsf.org/fsfsys-trisquel/fsfsys-trisquel/pool/main/s/spd-perl/spd-perl_0.2-1_amd64.deb
919 sudo dpkg -i $t
920 m rm $t
921 # this guesses at the appropriate directory, adjust if needed
922 perldir=(/usr/lib/x86_64-linux-gnu/perl/5.*)
923 m sudo ln -sf ../../../perl/5.18.2/SPD/ ${perldir[0]}
924 # newer distro had gpg2 as default, older one, flidas, need to make it that way
925 gpgpath=$(which gpg2)
926 if [[ $x ]]; then
927 sudo mkdir -p /usr/local/spdhackfix
928 s lnf -T $gpgpath /usr/local/spdhackfix/gpg
929 fi
930 ### end spd install
931
932
933 # nagstamon setting which were set through the ui
934 # in filters tab:
935 # all unknown sources
936 # all warning services
937 # acknowledged hosts & services
938 # hosts & services down for maintenence
939 # services on down hosts
940 # services on hosts in maintenece
941 # services on unreachable osts
942 # hosts in soft state
943 # services in soft state
944 # in display tab: fullscreen
945
946 # these translate to these settings I think
947 # filter_acknowledged_hosts_services = True
948 # filter_all_unknown_services = True
949 # filter_all_warning_services = True
950 # filter_hosts_in_soft_state = True
951 # filter_hosts_services_maintenance = True
952 # filter_services_in_soft_state = True
953 # filter_services_on_down_hosts = True
954 # filter_services_on_hosts_in_maintenance = True
955 # filter_services_on_unreachable_hosts = True
956 # notify_if_up = False
957 # statusbar_floating = False
958 # fullscreen = True
959 # but i'm just going to rely on the webpage plus sms for now.
960
961
962 # it asks if it should make users in it's group capture packets without root,
963 # which is arguably more secure than running wireshark as root. default is no,
964 # which is what i prefer, since I plan to use tcpdump to input to wireshark.
965 s DEBIAN_FRONTEND=noninteractive pi wireshark-gtk
966
967 # /run and /dev/shm are listed as required for pulseaudio. All 4 in the group
968 # listed in the default config as suggested.
969 # /run/usr/1000 i noticed was missing for pulseaudio
970 # /run/user/0 just seemed like a not bad idea, given the above
971 tu /etc/schroot/desktop/fstab <<'EOF'
972 /run /run none rw,bind 0 0
973 /run/lock /run/lock none rw,bind 0 0
974 /dev/shm /dev/shm none rw,bind 0 0
975 /run/shm /run/shm none rw,bind 0 0
976 /run/user/1000 /run/user/1000 none rw,bind 0 0
977 /run/user/1001 /run/user/1001 none rw,bind 0 0
978 /run/user/0 /run/user/0 none rw,bind 0 0
979 EOF
980
981 mkschroot() {
982 distro=$1
983 shift
984 case $distro in
985 ubuntu)
986 repo=http://archive.ubuntu.com/ubuntu/
987 ;;
988 debian)
989 repo=http://deb.debian.org/debian/
990 ;;
991 esac
992 n=$1
993 shift
994 if schroot -l | grep -xFq chroot:$n; then
995 echo "$0: $n schroot already installed, skipping"
996 return 0
997 fi
998 apps=($@)
999 d=/nocow/schroot/$n
1000 sd /etc/schroot/chroot.d/$n.conf <<EOF
1001 [$n]
1002 description=$n
1003 type=directory
1004 directory=$d
1005 profile=desktop
1006 preserve-environment=true
1007 users=$USER,user2
1008 EOF
1009 if [[ -e $d/bin ]]; then
1010 sudo chroot $d apt-get update
1011 sudo chroot $d apt-get -y dist-upgrade --purge --auto-remove
1012 cd; sudo schroot -c $n -- apt-get install --allow-unauthenticated -y ${apps[@]}
1013 else
1014 sudo mkdir -p $d
1015
1016 sudo debootstrap $n $d $repo
1017 cd; sudo schroot -c $n -- apt-get install --allow-unauthenticated -y ${apps[@]}
1018 fi
1019 sudo cp -P {,$d}/etc/localtime
1020 }
1021 sd /etc/systemd/system/schrootupdate.service <<'EOF'
1022 [Unit]
1023 Description=schrootupdate
1024 After=multi-user.target
1025
1026 [Service]
1027 Type=oneshot
1028 ExecStart=/a/bin/log-quiet/sysd-mail-once schrootupdate /a/bin/distro-setup/schrootupdate
1029 EOF
1030 sd /etc/systemd/system/schrootupdate.timer <<'EOF'
1031 [Unit]
1032 Description=schrootupdate
1033
1034 [Timer]
1035 OnCalendar=*-*-* 04:20:00
1036
1037 [Install]
1038 WantedBy=timers.target
1039 EOF
1040 ser daemon-reload
1041 sgo schrootupdate.timer
1042
1043
1044
1045 # for my roommate
1046 case $distro in
1047 trisquel)
1048 m mkschroot debian stretch firefox-esr pulseaudio chromium
1049 ;;
1050 debian)
1051 pi chromium
1052 ;;
1053 esac
1054
1055 sudo mkdir -p /nocow/user
1056 sudo chown $USER:$USER /nocow/user
1057 pi anki
1058
1059
1060 ####### begin transmission
1061
1062 case $HOSTNAME in
1063 frodo)
1064 tdir=/i/k
1065 ;;
1066 *)
1067 tdir=/nocow/user
1068 ;;
1069 esac
1070
1071 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
1072 # 450 seems likely to be unused. we need to specify one or else
1073 # it won't be stable across installs.
1074 if ! getent passwd debian-transmission > /dev/null; then
1075 sudo groupadd -g 450 debian-transmission
1076 sudo adduser --quiet \
1077 --gid 450 \
1078 --uid 450 \
1079 --system \
1080 --no-create-home \
1081 --disabled-password \
1082 --home /var/lib/transmission-daemon \
1083 debian-transmission
1084 fi
1085 # We want group writable stuff from transmission.
1086 # However, after setting this, I learn that transmission sets it's
1087 # own umask based on it's settings file. Well, no harm leaving this
1088 # so it's set right from the beginning.
1089 sudo chfn debian-transmission -o umask=0002
1090
1091 # note i had to do this, which is persistent:
1092 # cd /i/k
1093 # s chgrp debian-transmission torrents partial-torrents
1094
1095 # syslog says things like
1096 # 'Failed to set receive buffer: requested 4194304, got 425984'
1097 # google suggets giving it even more than that
1098 tu /etc/sysctl.conf<<'EOF'
1099 net.core.rmem_max = 67108864
1100 net.core.wmem_max = 16777216
1101 EOF
1102 sudo sysctl -p
1103
1104 # some reason it doesn\'t seem to start automatically anyways
1105 pi-nostart transmission-daemon
1106 # be extra sure its not started
1107 ser disable transmission-daemon
1108 ser stop transmission-daemon
1109
1110 # the folder was moved here after an install around 02/2017.
1111 # it contains runtime data,
1112 # plus a simple symlink to the config file which it\'s
1113 # not worth separating out.
1114 # between comps, the uid can change
1115 f=$tdir/transmission-daemon
1116 mkdir -p $f
1117 s lnf -T $f /var/lib/transmission-daemon/.config/transmission-daemon
1118 s lnf -T /etc/transmission-daemon/settings.json $f/settings.json
1119 sudo chown -R debian-transmission:debian-transmission $f
1120 for f in $tdir/partial-torrents $tdir/torrents; do
1121 if [[ -e $f ]]; then
1122 sudo chown -R debian-transmission:user2 $f
1123 fi
1124 done
1125 sudo chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon
1126 #
1127 # config file documented here, and it\'s the same config
1128 # for daemon vs client, so it\'s documented in the gui.
1129 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
1130 #
1131 # I originaly setup rpc-whitelist, but after using
1132 # routing to a network namespace, it doesn\'t see the
1133 # real source address, so it\'s disabled.
1134 #
1135 # Changed the cache-size to 256 mb, reduces disk use.
1136 # It is a read & write cache.
1137 sudo ruby <<EOF
1138 require 'json'
1139 p = '/etc/transmission-daemon/settings.json'
1140 File.write(p, JSON.pretty_generate(JSON.parse(File.read(p)).merge({
1141 'rpc-whitelist-enabled' => false,
1142 'rpc-authentication-required' => false,
1143 'incomplete-dir' => '$tdir/partial-torrents',
1144 'incomplete-dir-enabled' => true,
1145 'download-dir' => '$tdir/torrents',
1146 "speed-limit-up" => 800,
1147 "speed-limit-up-enabled" => true,
1148 "peer-port" => 61486,
1149 "cache-size-mb" => 256,
1150 "ratio-limit" => 5.0,
1151 "ratio-limit-enabled" => true,
1152 })) + "\n")
1153 EOF
1154 ####### end transmission
1155
1156
1157
1158 # trisquel 8 = openvpn, debian stretch = openvpn-client
1159 vpn_ser=openvpn-client
1160 if [[ ! -e /lib/systemd/system/openvpn-client@.service ]]; then
1161 vpn_ser=openvpn
1162 fi
1163
1164 sd /etc/systemd/system/transmission-daemon-nn.service <<EOF
1165 [Unit]
1166 Description=Transmission BitTorrent Daemon netns
1167 After=network.target
1168 Requires=${vpn_ser}-nn@client.service
1169 After=${vpn_ser}-nn@client.service
1170 JoinsNamespaceOf=${vpn_ser}-nn@client.service
1171
1172 [Service]
1173 #User=debian-transmission
1174 # notify type doesn't work with sudo
1175 #Type=notify
1176 ExecStart=/usr/bin/nsenter --mount=/root/mount_namespaces/client sudo -u debian-transmission /usr/bin/transmission-daemon -f --log-error
1177 ExecReload=/bin/kill -s HUP \$MAINPID
1178 PrivateNetwork=true
1179 Nice=19
1180
1181 [Install]
1182 WantedBy=multi-user.target
1183 EOF
1184 ser daemon-reload
1185
1186 if [[ $HOSTNAME == frodo ]]; then
1187 sgo transmission-daemon-nn
1188 fi
1189
1190
1191 ######### begin transmission client setup ######
1192
1193 if [[ -e /p/transmission-rpc-pass ]]; then
1194 # arch had a default config,
1195 # debian had nothing until you start it.
1196 # With a little trial an error, here is a minimal config
1197 # taken from the generated one, plus changes that the
1198 # settings ui does, without a bunch of ui crap settings.
1199 #
1200 # only settings I set were
1201 # hostname
1202 # auto-connect
1203 # password
1204
1205 # the password is randomly generated on first run, i copied it out
1206 # so it could be used by other hosts.
1207 sudo ruby <<'EOF'
1208 require 'json'
1209 p = '/etc/transmission-daemon/settings.json'
1210 s = JSON.parse(File.read(p))
1211 s["rpc-password"] = File.read("/p/transmission-rpc-pass").chomp
1212 # default is 0022 (18 in decimal)
1213 s["umask"] = 2
1214 File.write p, JSON.pretty_generate(s)
1215 EOF
1216
1217 rpc_pass=$(</p/transmission-rpc-pass)
1218 for f in /home/*; do
1219 u=${f##*/}
1220 uid=$(id -u $u 2>/dev/null) || continue
1221 if [[ ! $uid -ge 1000 ]]; then
1222 continue
1223 fi
1224 d=$f/.config/transmission-remote-gtk
1225 sudo -u $u mkdir -p $d
1226 sudo -u $u dd of=$d/config.json <<EOF
1227 {
1228 "profiles" : [
1229 {
1230 "profile-name" : "Default",
1231 "hostname" : "transmission.b8.nz",
1232
1233 "rpc-url-path" : "/transmission/rpc",
1234 "username" : "",
1235 "password" : "$rpc_pass",
1236 "auto-connect" : true,
1237 "ssl" : false,
1238 "timeout" : 40,
1239 "retries" : 3,
1240 "update-active-only" : false,
1241 "activeonly-fullsync-enabled" : false,
1242 "activeonly-fullsync-every" : 2,
1243 "update-interval" : 3,
1244 "min-update-interval" : 3,
1245 "session-update-interval" : 60,
1246 "exec-commands" : [],
1247 "destinations" : []
1248 },
1249 {
1250 "profile-name" : "local",
1251 "hostname" : "10.173.0.2",
1252
1253 "username" : "",
1254 "password" : "$rpc_pass",
1255 "auto-connect" : true,
1256 "ssl" : false,
1257 "timeout" : 40,
1258 "retries" : 3,
1259 "update-active-only" : false,
1260 "activeonly-fullsync-enabled" : false,
1261 "activeonly-fullsync-every" : 2,
1262 "update-interval" : 3,
1263 "min-update-interval" : 3,
1264 "session-update-interval" : 60,
1265 "exec-commands" : [],
1266 "destinations" : []
1267 }
1268 ],
1269 "profile-id" : 0,
1270 "add-options-dialog" : false
1271 }
1272 EOF
1273 done
1274 fi
1275 ######### end transmission client setup ######
1276
1277
1278 ### printer setup
1279 pi cups hplip
1280 sudo gpasswd -a $USER lpadmin # based on ubuntu wiki
1281 # goto http://127.0.0.1:631
1282 # administration tab, add new printer button.
1283 # In debian, I could use hte recommended driver,
1284 # in arch, I had to pick out the 6L driver.
1285
1286
1287 # bridge networking as user fails. google lead here, but it doesn\'t work:
1288 # oh well, I give up.
1289 # http://wiki.qemu.org/Features-Done/HelperNetworking
1290 # s mkdir /etc/qemu
1291 # f=/etc/qemu/bridge.conf
1292 # sd $f <<'EOF'
1293 # allow br0
1294 # EOF
1295 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
1296 # s chmod 640 $f
1297
1298 # general known for debian/ubuntu, not for fedora
1299
1300 m /a/bin/buildscripts/go
1301 m /a/bin/buildscripts/rust
1302 m /a/bin/buildscripts/misc
1303
1304 pi-nostart virtinst virt-manager
1305 # allow user to run vms, from debian handbook
1306 for x in iank user2; do s usermod -a -G libvirt,kvm $x; done
1307
1308
1309 pi --no-install-recommends kdeconnect
1310 ### kdeconnect for gnome. started in /a/bin/distro-setup/desktop-20-autostart.sh
1311 ### but gnome + xmonad not working in flidas, so i disabled it
1312 # pi libgtk-3-dev python3-requests-oauthlib valac cmake python-nautilus libappindicator3-dev
1313 # cd /a/opt/indicator-kdeconnect
1314 # mkdir -p build
1315 # cd build
1316 # cmake .. -DCMAKE_INSTALL_PREFIX=/usr
1317 # make
1318 # sudo make install
1319 # # we can start it manually with /usr/lib/x86_64-linux-gnu/libexec/kdeconnectd
1320 # # it seems, according to
1321 # # /etc/xdg/autostart/kdeconnectd.desktop
1322 # # I'm not seeing the icon, but the clipboard replication is working
1323
1324
1325 ### model 01 arduino support ###
1326 # https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux
1327 # also built latest arduino in /a/opt/Arduino, (just cd build; ant build; ant run )
1328 # set arduino var in bashrc,
1329 # have system config file setup too.
1330 sudo adduser $USER dialout
1331
1332 # this is for the mail command too. update-alternatives is kind of misleading
1333 # since at least it's main commands pretend mail does not exist.
1334 # bsd's mail got pulled in on some dumb dependency, i dunno how.
1335 sudo update-alternatives --set mailx /usr/bin/mail.mailutils
1336
1337 ######### end misc packages #########
1338
1339
1340 # packages I once used before and liked, but don\'t want installed now for
1341 # various reasons:
1342 # python-sqlite is used for offlineimap
1343 # lxappearance python-sqlite dolphin paman dconf-editor
1344
1345
1346
1347 ######## unfinished
1348
1349 # todo, finish configuring smart.
1350
1351 pi smartmontools
1352 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
1353 # turn on smart. background on options:
1354 # first line, -a = test everyting on all devices.
1355 # -S on, turn on disk internal saving of vendor specific info,
1356 # from google, seems like this is usually already on and fairly standard.
1357 # -o on, turn on 4 hour period non-performance degrading testing.
1358 # short test daily 2-3am, extended tests Saturdays between 3-4am:
1359 sched="-s (S/../.././02|L/../../6/03)"
1360 sudo sed -i --follow-symlinks "s#^[[:space:]]*DEVICESCAN.*#\
1361 DEVICESCAN -a -o on -S on -n standby,q $sched \
1362 -m ian@iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
1363
1364 # in the default configuration of at least ubuntu 14.04, resolvconf is
1365 # configured to order any nameservers associated with tun* or tap*
1366 # before the normal internet interfaces, which means they are always
1367 # consulted first. This is often slower and undesirable, ie. local dns
1368 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
1369 # can do:
1370 #sudo sed -i --follow-symlinks '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
1371 # however, this breaks dns lookup for hosts on the openvpn lan.
1372 # I can\'t figure out why hosts on the normal lan would not be
1373 # broken under the default ordering, except the host I was
1374 # testing with previously had an entry in /etc/hosts.
1375
1376 ############# end unfinished
1377
1378 ########### misc stuff
1379
1380 pi-nostart network-manager
1381 # make networkmanager use resolvconf instead of its own dnsmasq which
1382 # conflicts with the normal dnsmasq package.
1383 f=/etc/NetworkManager/NetworkManager.conf
1384 m=$(md5sum $f)
1385 sudo sed -ri '/ *\[main\]/,/^ *\[[^]]+\]/{/^\s*dns[[:space:]=]/d}' $f
1386 sudo sed -ri '/ *\[main\]/a dns=default' $f
1387 if [[ $m != $(md5sum $f) ]]; then
1388 srestart NetworkManager
1389 fi
1390
1391 # make my /etc/fonts/conf.d/ get used.
1392 # I have a new sans-serif font there because the default one
1393 # displays l and I as the same char, grrrrr.
1394 sudo fc-cache
1395
1396 pi desktop-file-utils
1397 m /a/bin/distro-setup/mymimes
1398
1399
1400 sgo dynamicipupdate
1401
1402
1403 # stop autopoping windows when i plug in an android phone.
1404 # dbus-launch makes this work within an ssh connection, otherwise you get this message,
1405 # with still 0 exit code.
1406 # dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
1407 m dbus-launch gsettings set org.gnome.desktop.media-handling automount-open false
1408
1409
1410 # on grub upgrade, we get prompts unless we do this
1411 devs=()
1412 for dev in $(s btrfs fil show /boot | sed -nr 's#.*path\s+(\S+)$#\1#p'); do
1413 devs+=("$(devbyid $dev),")
1414 done
1415 devs[-1]=${devs[-1]%,} # jonied by commas
1416 sudo debconf-set-selections <<EOF
1417 grub-pc grub-pc/install_devices multiselect ${devs[*]}
1418 EOF
1419
1420 # btrfs maintenance
1421 sgo btrfsmaint.timer
1422 sgo btrfsmaintstop.timer
1423
1424 # aren't autoupdating this, but I do check on it somewhat regularly.
1425 m cd /a/opt/btrbk
1426 sudo make install
1427
1428 sgo btrbk.timer
1429 # note: to see when it was last run,
1430 # ser list-timers
1431
1432
1433 end_msg <<'EOF'
1434 In mate settings settings, change scrolling to two-finger,
1435 because the default edge scroll doesn\'t work. Originally found this in debian.
1436 EOF
1437
1438 # Remove dep that came in with desktop to fix associations.
1439 m pu transmission-gtk
1440
1441
1442 m /a/bin/buildscripts/pithosfly
1443
1444
1445 # # Based on guix manual instructions, also added code to profile.
1446 # # disabled since i'm not using it now.
1447 # pi nscd
1448 # if ! type -p guix >/dev/null; then
1449 # cd $(mktemp -d)
1450 # wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
1451 # # added some stuff to envonment.sh for profile based on
1452 # # manual instructions
1453 # # wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
1454 # # echo is to get past prompt
1455 # yes | sudo -E HOME=$HOME bash guix-install.sh || [[ $? == 141 ]]
1456 # guix install glibc-utf8-locales
1457 # guix package --install guile
1458 # fi
1459
1460
1461
1462 pi tor
1463 m /a/bin/buildscripts/tor-browser
1464
1465 # nfs server
1466 pi-nostart nfs-kernel-server
1467
1468 # networkmanager has this nasty behavior on flidas: if the machine
1469 # crashes with dnsmasq running, on subsequent boot, it adds an entry to
1470 # resolvconf for 127.0.0.1 in some stupid attempt to restore
1471 # nameservers.
1472 # This can be manually fixed by stoping dnsmasq,
1473 # then based on whats in /run/dnsmasq/, i see we can run
1474 # s resolvconf -d NetworkManager
1475 # oh ya, and stoping NetworkManager leaves this crap behind without cleaning it up.
1476 ser disable NetworkManager
1477
1478
1479 if [[ $HOSTNAME == frodo ]]; then
1480 # nohide = export filesystems mounted deeper than the export point
1481 # fsid=0 makes this export the "root" export
1482 # not documented in the man page, but this means
1483 # 1. it can be mounted with a shorthand of server:/
1484 # 2. exports that are subdirectories of this one will automatically be mounted
1485 tu /etc/exports <<'EOF'
1486 /k 10.0.0.0/24(rw,fsid=0,nohide,no_root_squash,async,no_subtree_check,insecure)
1487 EOF
1488 sudo exportfs -rav
1489 fi
1490
1491
1492
1493
1494
1495 # if I was going to create a persistent vm, i might do it like this:
1496 # variant=something # from: virt-install --os-variant list
1497 # s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
1498 # --disk=/a/images/some_name.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
1499 # -n some_name --import --os-variant $variant --cpu host-model-only
1500
1501
1502
1503 ######### begin stuff belonging at the end ##########
1504
1505 end