add copyright headers, fix a few things
[distro-setup] / distro-end
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 errcatch
17
18 set -x
19
20 exec &> >(sudo tee -a /var/log/distro-end)
21 echo "$0: $(date): starting now)"
22
23 src="${BASH_SOURCE%/*}"
24
25 end_msg() {
26 = local y
27 IFS= read -r -d '' y ||:
28 end_msg_var+="$y"
29 }
30
31 spa() { # simple package add
32 simple_packages+=($@)
33 }
34
35 distro=$(distro-name)
36
37 pending_reboot=false
38
39 # template
40 case $distro in
41 esac
42
43 pup
44
45 simple_packages=(
46 htop
47 mailutils
48 nmon
49 rdiff-backup
50 ruby
51 ruby-rest-client
52 tree
53 vim
54 )
55
56 case $HOSTNAME in
57 lj|li) : ;;
58 *)
59 # universal packages
60 # swh-plugins is for karaoke pulsaudio filter.
61 # mutagen for pithos
62 # lib32stdc++6/default-jdk for android studio
63 # android site says it needs a bunch of packages for ubuntu,
64 # but I googled for debian, and someone says you just need one, plus the
65 # jdk
66 # https://pid7007blog.blogspot.com/2015/07/installing-android-studio-in-debian-8.html
67 # see w.org for more android studio details
68 #
69 simple_packages+=(
70 apache2
71 bwm-ng
72 chromium
73 default-jdk
74 duplicity
75 evince
76 fdupes
77 filelight
78 gdb
79 gitk
80 goaccess
81 gnome-screenshot
82 jq
83 locate
84 lib32stdc++6
85 manpages
86 meld
87 nmap
88 offlineimap
89 p7zip
90 paprefs
91 pavucontrol
92 pdfgrep
93 pianobar
94 pidgin
95 python3-mutagen
96 slock
97 squashfs-tools
98 swh-plugins
99 tcpdump
100 transmission-remote-gtk
101 vlc
102 )
103 ;;
104 esac
105
106
107
108 ########### begin section including li ################
109
110
111 case $distro in
112 debian)
113 if [[ `debian-archive` == testing ]]; then
114 pi acme-tiny
115 fi
116 esac
117
118 case $distro in
119 fedora) spa unrar ;;
120 *) spa unrar-free ;;
121 esac
122
123
124 case $distro in
125 arch)
126 # ubuntu 14.04 uses b-cron,
127 # but its not maintained in arch.
128 # of the ones in the main repos, cronie is only one maintained.
129 # fcron appears abandoned software.
130 pi cronie
131 sgo cronie
132 ;;
133 *) : ;; # other distros come with cron.
134 esac
135
136
137 case $distro in
138 debian|ubuntu)
139 pi debian-goodies
140 ;;
141 esac
142
143
144 case $distro in
145 *) pi at ;;&
146 arch) sgo atd ;;
147 esac
148
149
150 case $distro in
151 debian) pi curl;;
152 arch) : ;;
153 # fedora: unknown
154 esac
155
156 case $distro in
157 # tk for gitk
158 arch) spa git tk ;;
159 *) spa git ;;
160 esac
161
162 case $distro in
163 arch) spa the_silver_searcher ;;
164 debian|ubuntu) spa silversearcher-ag ;;
165 # fedora unknown
166 esac
167
168 case $distro in
169 debian|ubuntu) spa ntp;;
170 arch)
171 pi ntp
172 sgo ntpd
173 ;;
174 # others unknown
175 esac
176
177
178 # no equivalent in other distros:
179 case $distro in
180 debian|ubuntu)
181 pi apt-file aptitude
182 s apt-file update
183 # for debconf-get-selections
184 spa debconf-utils
185 ;;
186 esac
187
188 case $distro in
189 ubuntu|debian) spa ack-grep ;;
190 arch|fedora) spa ack ;;
191 # fedora unknown
192 esac
193
194 case $distro in
195 arch|debian|ubuntu)
196 spa bash-completion
197 ;;
198 # others unknown
199 esac
200
201
202
203
204
205 # disable motd junk.
206 case $(distro-name) in
207 debian)
208 # allows me to pipe with ssh -t, and gets rid of spam
209 # http://forums.debian.net/viewtopic.php?f=5&t=85822
210 # i'd rather disable the service than comment the init file
211 # this says disabling the service, it will still get restarted
212 # but this script doesn't do anything on restart, so it should be fine
213 s dd of=/var/run/motd.dynamic if=/dev/null
214 # stretch doesn't have initscripts pkg installed by default
215 if [[ $(debian-codename) == jessie ]]; then
216 s update-rc.d motd disable
217 fi
218 ;;
219 ubuntu)
220 # this isn't a complete solution. It still shows me when updates are available,
221 # but it's no big deal.
222 s t /etc/update-motd.d/10-help-text /etc/update-motd.d/00-header
223 ;;
224 esac
225
226 # automatic updates
227 # reference:
228 # https://debian-handbook.info/browse/stable/sect.regular-upgrades.html
229 # /etc/cron.daily/apt calls unattended-upgrades
230 # /usr/share/doc/unattended-upgrades# cat README.md
231 # /etc/apt/apt.conf.d/50unattended-upgrades
232 if isdebian; then
233 setup-debian-auto-update
234 fi
235
236 # we've got a few dependencies later on, so install them now.
237 pi "${simple_packages[@]}"
238 simple_packages=()
239
240 case $HOSTNAME in
241 lj|li)
242
243 case $HOSTNAME in
244 lj) domain=iank.bid ;;
245 li) domain=iankelling.org ;;
246 esac
247 /a/h/setup.sh $domain
248 /a/h/build.rb
249
250 sudo -E /a/bin/mediawiki-setup/mw-setup-script
251 #$src/phab-setup
252
253 echo "$0: $(date): ending now)"
254 exit 0
255 ;;
256 esac
257
258 ########### end section including li/lj ###############
259
260
261 if [[ $HOSTNAME == frodo ]]; then
262 case $distro in
263 ubunut|debian)
264 pi libsqlite3-dev
265 cd /a/opt/duperemove
266 make clean
267 make
268 s make install
269 ;;
270 #others unknown
271 esac
272 fi
273
274 case $distro in
275 arch) pi syncthing ;;
276 ubuntu|debian)
277 # testing has relatively up to date packages
278 if ! isdebian-testing; then
279 # based on error when doing apt-get update:
280 # E: The method driver /usr/lib/apt/methods/https could not be found.
281 pi apt-transport-https
282 # google led me here:
283 # https://apt.syncthing.net/
284 curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
285 s="deb http://apt.syncthing.net/ syncthing release"
286 if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != $s ]]; then
287 echo "$s" | s dd of=/etc/apt/sources.list.d/syncthing.list
288 p update
289 fi
290 fi
291 pi syncthing
292 ;;
293 esac
294 # installed via f-droid
295 # top right, actions, device id
296 #
297 # for installing on a remote comp:
298 # ssh -L 8384:localhost:8384 -N frodo
299 # went to http://localhost:8384/
300 #
301 # add folder to sync phone,
302 # staggered file versioning would be my normal choice, but choose
303 # trash can versioning for sake of space on phone, with
304 # clean out after 7 days.
305 #
306 # did:
307 # ser start syncthing@ian
308 # then on phone, add device, hit bar code icon,
309 # install bar code scanner.
310
311
312 # no equivalent in other distros:
313 case $distro in
314 debian|ubuntu)
315 # for gui bug reporting
316 spa python-vte
317 ;;
318 esac
319
320
321 ####### misc packages ###########
322
323
324 if [[ $HOSTNAME == treetowl ]]; then
325 case $distro in
326 debian|ubuntu)
327 # note i had to do this, which is persistent:
328 # cd /i/k
329 # s chgrp debian-transmission torrents partial-torrents
330
331 # syslog says things like
332 # 'Failed to set receive buffer: requested 4194304, got 425984'
333 # google suggets giving it even more than that
334 tu /etc/sysctl.conf<<'EOF'
335 net.core.rmem_max = 67108864
336 net.core.wmem_max = 16777216
337 EOF
338 s sysctl -p
339
340 # some reason it doesn't seem to start automatically anyways
341 pi-nostart transmission-daemon
342 # config file documented here, and it's the same config
343 # for daemon vs client, so it's documented in the gui.
344 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
345 s ruby <<'EOF'
346 require 'json'
347 p = '/etc/transmission-daemon/settings.json'
348 File.write(p, JSON.pretty_generate(JSON.parse(File.read(p)).merge({
349 'rpc-whitelist' => '127.0.0.1,192.168.1.*',
350 'rpc-authentication-required' => false,
351 'incomplete-dir' => '/i/k/partial-torrents',
352 'download-dir' => '/i/k/torrents',
353 "speed-limit-up" => 700,
354 "speed-limit-up-enabled" => true,
355 "ratio-limit" => 1.4000,
356 "ratio-limit-enabled" => true,
357 })) + "\n")
358 EOF
359 sgo transmission-daemon
360 ;;
361 arch)
362 # todo, setup it's config file & daemon
363 pi transmission-cli
364 ;;
365 esac
366 fi
367
368 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
369 if ! getent passwd debian-transmission > /dev/null; then
370 case $distro in
371 arch)
372 s useradd \
373 --system \
374 --create-home \
375 --home-dir /var/lib/transmission-daemon \
376 --shell /bin/false \
377 debian-transmission
378 ;;
379 *)
380 s adduser --quiet \
381 --system \
382 --group \
383 --no-create-home \
384 --disabled-password \
385 --home /var/lib/transmission-daemon \
386 debian-transmission
387 ;;
388 esac
389 fi
390
391 # dunno why it's there, but get rid of it
392 case $HOSTNAME in
393 li|lj) s rm -rf /home/linode ;;
394 esac
395
396 # arch had a default config,
397 # debian had nothing until you start it.
398 # With a little trial an error, here is a minimal config
399 # taken from the generated one, plus changes that the
400 # settings ui does, without a bunch of ui crap settings.
401 #
402 # only settings I set were
403 # hostname
404 # auto-connect
405 for f in /home/*; do
406 d=$f/.config/transmission-remote-gtk
407 u=${f##*/}
408 s -u $u mkdir -p $d
409 s -u $u dd of=$d/config.json <<'EOF'
410 {
411 "profiles" : [
412 {
413 "profile-name" : "Default",
414 "hostname" : "treetowl",
415 "rpc-url-path" : "/transmission/rpc",
416 "username" : "",
417 "password" : "",
418 "auto-connect" : true,
419 "ssl" : false,
420 "timeout" : 40,
421 "retries" : 3,
422 "update-active-only" : false,
423 "activeonly-fullsync-enabled" : false,
424 "activeonly-fullsync-every" : 2,
425 "update-interval" : 3,
426 "min-update-interval" : 3,
427 "session-update-interval" : 60,
428 "exec-commands" : [
429 ],
430 "destinations" : [
431 ]
432 }
433 ],
434 "profile-id" : 0,
435 "add-options-dialog" : false
436 }
437 EOF
438 done
439
440 case $distro in
441 debian|ubuntu)
442 pi-nostart openvpn
443 # pi-nostart this doesnt seem to be good enough?
444 ser disable openvpn@client
445 ser disable openvpn
446 ;;
447 # suggests because we want the resolvconf package
448 *) pi --install-suggests openvpn;;
449 esac
450
451 pi wget
452 case $HOSTNAME in
453 tp|frodo)
454 case $distro in
455 debian|ubuntu)
456 log=$(mktemp)
457 cd /a/opt
458 wget -nv -N https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
459 errallow
460 set -o pipefail
461 s dpkg -i google-chrome-stable_current_amd64.deb |& tee $log
462 code=$?
463 errcatch
464 case $code in
465 0) : ;;
466 *)
467 # previously I had a more specific search, but dpkg
468 # changed it's output as of 7/2016
469 if grep 'dependency problems' \
470 $log &>/dev/null; then
471 s apt-get -fy install
472 else
473 exit 1
474 fi
475 ;;
476 esac
477 ;;
478 arch)
479 pi google-chrome
480 ;;
481 esac
482 ;;
483 esac
484
485 # printer
486 case $distro in
487 arch)
488 pi cups ghostscript gsfonts # from arch wiki cups page
489 pi hplip # from google
490 s gpasswd -a $USER sys # from arch wiki
491 sgo org.cups.cupsd.service
492 # goto http://127.0.0.1:631
493 # administration tab, add new printer button.
494 # In debian, I could use hte recommended driver,
495 # in arch, I had to pick out the 6L driver.
496 ;;
497 debian|ubuntu)
498 spa hplip
499 ;;
500 # other distros unknown
501 esac
502
503
504 case $distro in
505 ubuntu|debian) pi --no-install-recommends mairix notmuch ;;
506 fedora|arch) spa mairix notmuch ;;
507 esac
508 case $distro in
509 arch) spa nfs-utils ;;
510 ubuntu|debian) spa nfs-client ;;
511 esac
512 case $distro in
513 ubuntu|debian) spa par2 ;;
514 arch|fedora) spa par2cmdline ;;
515 esac
516
517 # needed for my tex resume
518 case $distro in
519 ubuntu|debian) spa texlive-full ;;
520 arch) spa texlive-most ;;
521 # fedora unknown
522 esac
523
524 case $distro in
525 ubuntu)
526 # flash, unrar, codecs, ms fonts.
527 # This has a manual prompt.
528 spa ubuntu-restricted-extras
529 ;;
530 fedora)
531 pi yum-utils
532 # rpm fusion recommended codecs
533 s su -c "yum localinstall -y --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm"
534 pi gstreamer-plugins-ugly gstreamer-plugins-bad gstreamer-ffmpeg\
535 xine-lib-extras-freeworld
536 ;;
537 esac
538
539 case $distro in
540 # optional dep for firefox for h.264 video
541 arch) spa gst-libav ;;
542 # other distros, probably come by default
543 esac
544
545 case $distro in
546 fedora|ubuntu|debian) spa gnupg-agent ;;
547 arch) : ;;
548 esac
549
550
551 case $distro in
552 fedora) spa pinentry-gtk ;;
553 *) : ;; # comes default or with other packages
554 esac
555
556 case $distro in
557 arch) spa firefox pulseaudio;;
558 *) : ;; # comes default or with other packages
559 esac
560
561
562 case $distro in
563 arch) spa ttf-dejavu;;
564 debian|ubuntu) spa fonts-dejavu ;;
565 # others unknown
566 esac
567
568
569 case $distro in
570 arch) spa xorg-xev;;
571 debian|ubuntu) spa x11-utils ;;
572 # others unknown
573 esac
574
575 case $distro in
576 arch) pi virt-install;;&
577 debian|ubuntu) pi virtinst ;;&
578 *) pi virt-manager ;; # creates the libvirt group in debian at least
579 # others unknown
580 esac
581 # allow user to run vms, from debian handbook
582 for x in ian traci; do s usermod -a -G libvirt,kvm $x; done
583 # bridge networking as user fails. google lead here, but it doesn't work:
584 # oh well, I give up.
585 # http://wiki.qemu.org/Features-Done/HelperNetworking
586 # s mkdir /etc/qemu
587 # f=/etc/qemu/bridge.conf
588 # s dd of=$f <<'EOF'
589 # allow br0
590 # EOF
591 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
592 # s chmod 640 $f
593
594
595 case $distro in
596 arch) spa cdrkit;;
597 debian|ubuntu) spa genisoimage;;
598 # others unknown
599 esac
600
601 case $distro in
602 arch) spa spice-gtk3 ;;
603 debian|ubuntu) spa spice-client-gtk;;
604 # others unknown
605 esac
606
607 # general known for debian/ubuntu, not for fedora
608 case $distro in
609 arch)
610 # cdrkit for cloud-init isos
611 # dnsmasq & ebtables for nat networking in libvirt
612 # qemu for qemu-img, bind-tools for dig
613 # dmidecode just because syslog complains
614 pi unzip xorg-xmodmap dmidecode ebtables\
615 bridge-utils dnsmasq qemu bind-tools
616 # otherwise we get error about accessing kvm module.
617 # seems like there might be a better way, but google was a bit vague.
618 s sed -ri --follow-symlinks '/^ *user *=/d' /etc/libvirt/qemu.conf
619 echo 'user = "root"' | s tee -a /etc/libvirt/qemu.conf
620 # https://bbs.archlinux.org/viewtopic.php?id=206206
621 # # this should prolly go in the wiki
622 sgo virtlogd.socket
623 # guessing this is not needed
624 #sgo virtlogd.service
625 sgo libvirtd
626
627 ;;
628 esac
629
630 case $distro in
631 arch) pi virtviewer ;;
632 *) : ;; # other distros have it as a dependency afaik.
633 esac
634
635
636
637 case $distro in
638 fedora) cabal install shellcheck ;;
639 *) spa shellcheck ;;
640 # unknown for older ubuntu
641 esac
642
643
644 case $distro in
645 arch|debian|ubuntu) spa pumpa ;;
646 # others unknown. do have a buildscript:
647 # /a/bin/buildscripts/pumpa ;;
648 esac
649
650
651 case $distro in
652 debian|ubuntu) spa android-tools-adb/unstable ;;
653 arch) spa android-tools ;;
654 # other distros unknown
655 esac
656
657 case $distro in
658 debian)
659 if [[ `debian-archive` == testing ]]; then
660 # has no unstable dependencies
661 spa bitcoin-qt/unstable
662 fi
663 ;;
664 # other distros unknown
665 esac
666
667
668 # proprietary flash. going without for now
669 # case $distro in
670 # debian)
671 # pi flashplugin-nonfree
672 # esac
673
674
675
676 case $distro in
677 fedora)
678 cd $(mktemp -d)
679 wget http://tamacom.com/global/global-6.3.2.tar.gz
680 ex global*
681 cd global-6.3.2
682 # based on https://github.com/leoliu/ggtags
683 ./configure --with-exuberant-ctags=/usr/bin/ctags
684 make
685 s make install
686 s pip install pygments
687 ;;
688 *)
689 pi global
690 ;;&
691 arch)
692 pi python2-pygments
693 ;;
694 debian|ubuntu)
695 pi python-pygments
696 ;;
697 esac
698
699
700 case $distro in
701 debian)
702 pi task-cinnamon-desktop
703 # in settings, change scrolling to two-finger,
704 # because the default edge scroll doesn\'t work.
705 pu transmission-gtk
706 ;;
707 # others unknown
708 esac
709
710 case $distro in
711 arch) spa apg ;;
712
713 # already in debian jessie
714 esac
715
716
717
718
719 # note this failed running at the beginning of this file,
720 # because no systemd user instance was running.
721 # Doing systemd --user resulted in
722 # Trying to run as user instance, but $XDG_RUNTIME_DIR is not set
723
724 if isdebian-testing; then
725 # as of 7/2016, has no unstable deps, and is not in testing anymore.
726 pi synergy/unstable
727 else
728 pi synergy
729 fi
730
731 # case $distro in
732 # # ubuntu unknown. probably the same as debian, just check if the
733 # # init scripts come with the package.
734 # debian)
735 # # copied from arch, but moved to etc
736 # s dd of=/etc/systemd/user/synergys.service <<'EOF'
737 # [Unit]
738 # Description=Synergy Server Daemon
739 # After=network.target
740
741 # [Service]
742 # User=%i
743 # ExecStart=/usr/bin/synergys --no-daemon --config /etc/synergy.conf
744 # Restart=on-failure
745
746 # [Install]
747 # WantedBy=multi-user.target
748 # EOF
749 # s dd of=/etc/systemd/user/synergys.socket <<'EOF'
750 # [Unit]
751 # Conflicts=synergys@.service
752
753 # [Socket]
754 # ListenStream=24800
755 # Accept=false
756
757 # [Install]
758 # WantedBy=sockets.target
759 # EOF
760 # # had this fail with 'Failed to connect to bus: No such file or directory'
761 # # then when I tried it manually, it worked fine...
762 # if ! systemctl --user daemon-reload; then
763 # sleep 2
764 # echo retrying systemd user daemon reload
765 # systemctl --user daemon-reload
766 # fi
767 # ;;&
768 # *)
769 # # taken from arch wiki.
770 # s dd of=/etc/systemd/system/synergyc@.service <<'EOF'
771 # [Unit]
772 # Description=Synergy Client
773 # After=network.target
774
775 # [Service]
776 # User=%i
777 # ExecStart=/usr/bin/synergyc --no-daemon frodo
778 # Restart=on-failure
779 # # per man systemd.unit, StartLimitInterval, by default we
780 # # restart more than 5 times in 10 seconds.
781 # # And this param defaults too 200 miliseconds.
782 # RestartSec=3s
783
784 # [Install]
785 # WantedBy=multi-user.target
786 # EOF
787 # s systemctl daemon-reload
788 # case $HOSTNAME in
789 # x2|treetowl)
790 # ser enable synergyc@ian
791 # ser start synergyc@ian ||: # X might not be running yet
792 # ;;
793 # frodo)
794 # systemctl --user start synergys ||:
795 # systemctl --user enable synergys
796 # ;;
797 # esac
798 # ;;
799 # esac
800
801
802 ######### end misc packages #########
803
804
805 # packages I once used before and liked, but don't want installed now for
806 # various reasons:
807 # python-sqlite is used for offlineimap
808 # lxappearance python-sqlite dolphin paman dconf-editor
809
810
811
812 ######## unfinished
813
814 # todo, finish configuring smart.
815
816 pi smartmontools
817 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
818 # turn on smart. background on options:
819 # first line, -a = test everyting on all devices.
820 # -S on, turn on disk internal saving of vendor specific info,
821 # from google, seems like this is usually already on and fairly standard.
822 # -o on, turn on 4 hour period non-performance degrading testing.
823 # short test daily 2-3am, extended tests Saturdays between 3-4am:
824 sched="-s (S/../.././02|L/../../6/03)"
825 s sed -i --follow-symlinks "s#^[[:space:]]*DEVICESCAN.*#\
826 DEVICESCAN -a -o on -S on -n standby,q $sched \
827 -m ian@iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
828
829 # in the default configuration of at least ubuntu 14.04, resolvconf is
830 # configured to order any nameservers associated with tun* or tap*
831 # before the normal internet interfaces, which means they are always
832 # consulted first. This is often slower and undesirable, ie. local dns
833 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
834 # can do:
835 #sudo sed -i --follow-symlinks '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
836 # however, this breaks dns lookup for hosts on the openvpn lan.
837 # I can\'t figure out why hosts on the normal lan would not be
838 # broken under the default ordering, except the host I was
839 # testing with previously had an entry in /etc/hosts.
840
841 ############# end unfinished
842
843 ########### misc stuff
844
845
846 s cedit /etc/goaccess.conf <<'EOF' || [[ $? == 1 ]]
847 # all things found from looking around the default config
848 # copied existing NCSA Combined Log Format with Virtual Host, plus %L
849 log-format %^:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u" %D
850 time-format %H:%M:%S
851 date-format %d/%b/%Y
852 log-file /var/log/apache2/access.log
853 color-scheme 2
854
855 # tip: copy access.log files to a stretch host directory, then run
856 # jessie's goaccess is too old for some options, and it's
857 # not easily installed from a testing.
858 # goaccess --ignore-crawlers -f <(cat *) -a -o html > x.html
859 EOF
860
861
862 if [[ $HOSTNAME == treetowl ]] && ! sudo test -e /etc/openvpn/client.key; then
863 /a/bin/vpn-setup/vpn-mk-client-cert dopub
864 fi
865
866
867 case $distro in
868 debian|ubuntu)
869 case `debian-archive` in
870 stable)
871 s dd of=/etc/apt/preferences.d/unison-gtk <<'EOF'
872 Explanation: Allow unison-gtk to be upgraded
873 Package: unison-gtk
874 Pin: release a=unstable
875 Pin-Priority: 500
876 EOF
877 # dont think using testing is needed since I figured out how to
878 # deal with mismatching unison compilers, but I dont
879 # see any reason to revert it, since it only installs
880 # a single package which is primarily a single binary
881 ;;
882 esac
883 pi unison/testing
884 pi unison-gtk/testing # after to make it the default unison
885 ;;
886 arch)
887 pi unison gtk2
888 ;;
889 esac
890
891 case $distro in
892 arch)
893 # default is alsa, doesn\'t work with with pianobar
894 s dd of=/etc/libao.conf <<'EOF'
895 default_driver=pulse
896 EOF
897 ;;
898 esac
899
900 # note, for jessie, it depends on a higher version of btrfs-tools
901 # case $distro in
902 # arch|debian|ubuntu) pi btrbk ;;
903 # # others unknown
904 # esac
905 cd /a/opt/btrbk
906 s make install
907
908 if [[ $HOSTNAME == treetowl ]] && [[ `debian-archive` != testing ]]; then
909 # fail2 ban is broken, with a workaround, per
910 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=770171
911 # ill wait a while to see if it gets fixed
912 pi fail2ban
913 sgo fail2ban
914 fi
915
916
917
918
919
920 case $distro in
921 debian|ubuntu) s gpasswd -a ian adm ;; #needed for reading logs
922 esac
923
924 # tor
925 case $distro in
926 # based on
927 # https://www.torproject.org/docs/rpms.html.en
928 # https://www.torproject.org/docs/debian.html.en
929 # todo: figure out if the running service needs to be restarted upon updates
930
931
932 # todo on fedora: setup non-dev packages
933 fedora)
934 s dd of=/etc/yum.repos.d/torproject.repo <<'EOF'
935 [tor]
936 name=Tor experimental repo
937 enabled=1
938 baseurl=http://deb.torproject.org/torproject.org/rpm/tor-testing/fc/20/$basearch/
939 gpgcheck=1
940 gpgkey=http://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org.asc
941
942 [tor-source]
943 name=Tor experimental source repo
944 enabled=1
945 autorefresh=0
946 baseurl=http://deb.torproject.org/torproject.org/rpm/tor-testing/fc/20/SRPMS
947 gpgcheck=1
948 gpgkey=http://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org.asc
949 EOF
950
951 # to be secure, take a look at the fingerprint reported from the following install, and see if it matches from the link above:
952 # 3B9E EEB9 7B1E 827B CF0A 0D96 8AF5 653C 5AC0 01F1
953 sgo tor
954 /a/bin/buildscripts/tor-browser
955 ;;
956 ubuntu)
957 tu /etc/apt/sources.list "deb http://deb.torproject.org/torproject.org $(debian-codename) main"
958 gpg --keyserver keys.gnupg.net --recv 886DDD89
959 gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
960 p update
961 pi deb.torproject.org-keyring
962 pi tor
963 /a/bin/buildscripts/tor-browser
964 ;;
965 debian)
966 pi tor
967 /a/bin/buildscripts/tor-browser
968 ;;
969 arch)
970 pi tor tor-browser-en
971 sgo tor
972 ;;
973 # ubuntu unknown
974 esac
975
976 # nfs server
977 case $distro in
978 fedora)
979 end_msg <<'EOF'
980 fedora todo: disable the firewall or find a way to automate it.
981 there's an unused section in t.org for tramikssion firewall setup
982
983 fedora manual config for nfs:
984 s firewall-config
985 change to permanent configuration
986 check the box for nfs
987 was hard to figure this out, not sure if this is all needed, but
988 unblock these too
989 mountd: udp/tcp 20048
990 portmapper, in firewall-config its called rpc-bind: udp/tcp 111
991 troubleshooting, unblock things in rpcinfo -p
992 make sure to reload the firewall to load the persistent configuration
993
994
995 EOF
996 pi nfs-utils
997 sgo nfs-server
998 ;;
999 debian|ubuntu)
1000 pi nfs-server
1001 ;;
1002 arch)
1003 pi nfs-utils || pending_reboot=true
1004 sgo rpcbind
1005 # this failed until I rebooted
1006 sgo nfs-server
1007 ;;
1008 esac
1009
1010 if [[ $HOSTNAME == treetowl ]]; then
1011 # nohide = export filesystems mounted deeper than the export point
1012 # fsid=0 makes this export the "root" export
1013 # not documented in the man page, but this means
1014 # 1. it can be mounted with a shorthand of server:/
1015 # 2. exports that are subdirectories of this one will automatically be mounted
1016 tu /etc/exports <<'EOF'
1017 /k 192.168.1.0/24(rw,fsid=0,nohide,no_root_squash,async,no_subtree_check,insecure)
1018 EOF
1019 s exportfs -rav
1020 fi
1021
1022
1023 e "$end_msg_var"
1024
1025
1026 # persistent virtual machines
1027
1028 case $distro in
1029 debian|ubuntu)
1030 pi libosinfo-bin;
1031 ;;
1032 esac
1033
1034 # distro may not know about win 10 yet.
1035 variant=win7
1036 if ! virt-install --os-variant list &>/dev/null; then # we are using a newer virt-install
1037 for v in 10 8.1 8; do
1038 if osinfo-query os | gr "^\s*win${v/./\\.}\s" &>/dev/null; then
1039 variant=win$v
1040 break
1041 fi
1042 done
1043 fi
1044
1045 if ! s virsh list --all --name | grep -xF win10 &>/dev/null; then
1046
1047 # created account with
1048 # win10vmian@outlook.com, and easy to remember password
1049 # win 10 virtio, makes disk way way way faster
1050 # wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso
1051 # https://wiki.archlinux.org/index.php/QEMU#Change_Existing_Windows_VM_to_use_virtio
1052 # for installing virtio after initial install instead of with initial iso:
1053 # qemu-img create -f qcow2 fake.qcow2 1G
1054 # --disk=/a/images/virtio-win.iso,device=cdrom \
1055 # --disk=/a/images/fake.qcow2,bus=virtio
1056 # Also,
1057 # went to device manager, saw 2 pci devices with yellow !,
1058 # did search for drivers, pick cdrom location, done.
1059 #
1060 # from http://www.tenforums.com/tutorials/4189-fast-startup-turn-off-windows-10-a.html.
1061 # google said there was a control panel option for it, but
1062 # that turned out to be a lie.
1063 # Put this in a .bat file and run as administrator to turn off
1064 # hyberboot which fucks things up.
1065 # REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V HiberbootEnabled /T REG_dWORD /D 0 /F
1066 # power settings, turn off display: never
1067 # run "control userpasswords2", turn on automatic login.
1068 # note: when changing devices, I just undefine, the create the vm again.
1069
1070 s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
1071 --disk=/a/images/win10.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
1072 -n win10 --import --os-variant $variant --cpu host-model-only
1073
1074 s virsh destroy win10
1075
1076 # this one hasn\'t had the virtio fix done yet.
1077 s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
1078 --disk=/a/images/win7.qcow2 --vcpus 2 -r 4096 -w bridge=br0 \
1079 -n win7 --import --os-variant win7 --cpu host-model-only
1080 s virsh destroy win7
1081 # had a problem with --cpu host, so trying out
1082 # --cpu host-model-only
1083
1084 fi
1085
1086
1087 if [[ $HOSTNAME == treetowl ]]; then
1088 pi samba
1089 # note samba re-reads it\'s config every 1 minute
1090 case $distro in
1091 arch) s cp /etc/samba/smb.conf.default /etc/samba/smb.conf ;;
1092 esac
1093
1094 # add 2 lines after workgroup option
1095 s sed -ri --follow-symlinks '/^\s*encrypt passwords\s*=/d' /etc/samba/smb.conf
1096 s sed -ri --follow-symlinks '/^\s*map to guest\s*=/d' /etc/samba/smb.conf
1097 s sed -i --follow-symlinks 's/\(\s*workgroup\s*=\).*/\1 WORKGROUP\n\tencrypt passwords = yes\n\tmap to guest = bad password/' /etc/samba/smb.conf
1098 # remove default homes section. not sharing that.
1099 s sed -ri --follow-symlinks '/^\s*\[homes\]/,/\s*\[/d' /etc/samba/smb.conf
1100
1101 if ! grep -xF '[public]' /etc/samba/smb.conf &>/dev/null; then
1102 s tee -a /etc/samba/smb.conf <<'EOF'
1103 [public]
1104 guest ok = yes
1105 read only = no
1106 path = /kr
1107 EOF
1108 fi
1109
1110 case $distro in
1111 debian|ubuntu)
1112 # systemd claims it generates units from /etc/init.d, but it
1113 # clearly doesn\'t in debian. I have no idea how they are
1114 # related. fuck debian right now. It\'s not documented. samba
1115 # has a systemd init file linked to /dev/null. There\'s this
1116 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=769714 which
1117 # claims samba\'s sub-services will be started automatically by
1118 # systemd... it didn\'t on install, wonder if it will on
1119 # boot. It clued me in how to start it manually though. Nothing
1120 # in /usr/share/doc/samba, debian admin guide says nothing about
1121 # any of this. (this is in debian testing as of 4/2016).
1122
1123 s /etc/init.d/samba start
1124 ;;
1125 arch)
1126 sgo samba
1127 ;;
1128 esac
1129 fi
1130
1131 tu /etc/hosts <<< "127.0.1.1 $(hostname).lan $(hostname)"
1132
1133
1134 ######### begin stuff belonging at the end ##########
1135
1136
1137 # Apps we want to override others for default file handler:
1138 # simplest way in debian is to just install them last.
1139 simple_packages+=(
1140 mpv
1141 )
1142
1143 case $distro in
1144 ubuntu|debian)
1145 spa spacefm-gtk3 ;;
1146 arch)
1147 spa spacefm ;;
1148 esac
1149
1150
1151 pi "${simple_packages[@]}"
1152
1153
1154 if $pending_reboot; then
1155 echo "$0: pending reboot and then finished. doing it now."
1156 s reboot now
1157 else
1158 echo "$0: $(date): ending now)"
1159 fi