2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
5 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
9 exec &> >(sudo
tee -a /var
/log
/distro-end
)
10 echo "$0: $(date): starting now)"
12 src
="${BASH_SOURCE%/*}"
16 IFS
= read -r -d '' y ||
:
20 spa
() { # simple package add
43 if [[ $HOSTNAME != lj
&& $HOSTNAME != lk
]]; then
69 transmission-remote-gtk
76 ########### begin section including lj ################
87 # ubuntu 14.04 uses b-cron,
88 # but its not maintained in arch.
89 # of the ones in the main repos, cronie is only one maintained.
90 # fcron appears abandoned software.
94 *) : ;; # other distros come with cron.
124 arch
) spa the_silver_searcher
;;
125 debian|ubuntu
) spa silversearcher-ag
;;
130 debian|ubuntu
) spa ntp
;;
139 # no equivalent in other distros:
144 # for debconf-get-selections
150 ubuntu|debian
) spa ack-grep
;;
151 arch|fedora
) spa ack
;;
167 case $
(distro-name
) in
169 # allows me to pipe with ssh -t, and gets rid of spam
170 # http://forums.debian.net/viewtopic.php?f=5&t=85822
171 # i'd rather disable the service than comment the init file
172 # this says disabling the service, it will still get restarted
173 # but this script doesn't do anything on restart, so it should be fine
174 s
dd of
=/var
/run
/motd.dynamic
if=/dev
/null
175 s update-rc.d motd disable
178 # this isn't a complete solution. It still shows me when updates are available,
179 # but it's no big deal.
180 s t
/etc
/update-motd.d
/10-help-text /etc
/update-motd.d
/00-header
186 # https://debian-handbook.info/browse/stable/sect.regular-upgrades.html
187 # /etc/cron.daily/apt calls unattended-upgrades
188 # /usr/share/doc/unattended-upgrades# cat README.md
189 # /etc/apt/apt.conf.d/50unattended-upgrades
191 pi unattended-upgrades
192 s
dd of
=/etc
/apt
/apt.conf.d
/10periodic
<<'EOF'
193 # this file was mostly just comments.
194 APT::Periodic::Update-Package-Lists "1";
195 APT::Periodic::Download-Upgradeable-Packages "1";
196 APT::Periodic::AutocleanInterval "7";
197 APT::Periodic::Unattended-Upgrade "1";
202 Unattended-Upgrade::Mail "root";
203 Unattended-Upgrade::MailOnlyOnError "true";
204 Unattended-Upgrade::Remove-Unused-Dependencies "true";
205 Unattended-Upgrade::Origins-Pattern {
206 # default is just upgrade main and security, not updates.
208 if isdebian-testing
; then
210 # for testing, only do security updates.
211 "origin=Debian,codename=${distro_codename},label=Debian-Security";
215 # These are stable packages only getting bugfixes anyways.
222 } | s
dd of
=/etc
/apt
/apt.conf.d
/50unattended
-upgrades
235 pi
"${simple_packages[@]}"
239 # start=' *<source lang="bash"> *'
240 # end=' *<\/source> *'
241 # ruby <<'EOF' | sed -rn "/^$start$/,/^$end$/{s/^$start|$end$/# \0/;p}" | bash
243 # puts JSON.parse(`curl 'https://ofswiki.org/w/api.php?\
244 # action=query&titles=Mediawiki_Setup_Guide&prop=revisions&rvprop=content&\
245 # format=json'`.chomp)['query']['pages'].values[0]['revisions'][0]['*']
247 # nginx-site iankelling.org
249 echo "$0: $(date): ending now)"
254 ########### end section including lj ###############
258 arch
) pi syncthing
;;
260 # google led me here:
261 # https://apt.syncthing.net/
262 curl
-s https
://syncthing.net
/release-key.txt | sudo apt-key add
-
263 s
="deb http://apt.syncthing.net/ syncthing release"
264 if [[ $
(cat /etc
/apt
/sources.list.d
/syncthing.list
) != $s ]]; then
265 echo "$s" | s
dd of
=/etc
/apt
/sources.list.d
/syncthing.list
271 # installed via f-droid
272 # top right, actions, device id
274 # for installing on a remote comp:
275 # ssh -L 8384:localhost:8384 -N frodo
276 # went to http://localhost:8384/
278 # add folder to sync phone,
279 # staggered file versioning would be my normal choice, but choose
280 # trash can versioning for sake of space on phone, with
281 # clean out after 7 days.
283 # did ser syncthing@ian start
284 # then on phone, add device, hit bar code icon,
285 # install bar code scanner.
288 # no equivalent in other distros:
291 # for gui bug reporting
297 ####### misc packages ###########
300 if [[ $HOSTNAME == frodo
]]; then
303 # note i had to do this, which is persistent:
305 # s chgrp debian-transmission torrents partial-torrents
307 # syslog says things like
308 # 'Failed to set receive buffer: requested 4194304, got 425984'
309 # google suggets giving it even more than that
310 tu
/etc
/sysctl.conf
<<'EOF'
311 net.core.rmem_max = 67108864
312 net.core.wmem_max = 16777216
316 # some reason it doesn't seem to start automatically anyways
317 pi-nostart transmission-daemon
318 # config file documented here, and it's the same config
319 # for daemon vs client, so it's documented in the gui.
320 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
323 p = '/etc/transmission-daemon/settings.json'
324 File.write(p, JSON.pretty_generate(JSON.parse(File.read(p)).merge({
325 'rpc-whitelist' => '127.0.0.1,192.168.1.*',
326 'rpc-authentication-required' => false,
327 'incomplete-dir' => '/i/k/partial-torrents',
328 'download-dir' => '/i/k/torrents',
329 "speed-limit-up" => 700,
330 "speed-limit-up-enabled" => true,
331 "ratio-limit" => 1.4000,
332 "ratio-limit-enabled" => true,
335 sgo transmission-daemon
338 # todo, setup it's config file & daemon
344 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
345 if ! getent passwd debian-transmission
> /dev
/null
; then
351 --home-dir /var
/lib
/transmission-daemon \
360 --disabled-password \
361 --home /var
/lib
/transmission-daemon \
367 # arch had a default config,
368 # debian had nothing until you start it.
369 # With a little trial an error, here is a minimal config
370 # taken from the generated one, plus changes that the
371 # settings ui does, without a bunch of ui crap settings.
373 # only settings I set were
378 d
=$f/.config
/transmission-remote-gtk
381 s
-u $u dd of
=$d/config.json
<<'EOF'
385 "profile-name" : "Default",
386 "hostname" : "frodo",
387 "rpc-url-path" : "/transmission/rpc",
390 "auto-connect" : true,
394 "update-active-only" : false,
395 "activeonly-fullsync-enabled" : false,
396 "activeonly-fullsync-every" : 2,
397 "update-interval" : 3,
398 "min-update-interval" : 3,
399 "session-update-interval" : 60,
407 "add-options-dialog" : false
415 # pi-nostart this doesnt seem to be good enough?
416 ser disable openvpn@client
429 wget
-N https
://dl.google.com
/linux
/direct
/google-chrome-stable_current_amd64.deb
431 s dpkg
-i google-chrome-stable_current_amd64.deb
&> $log
436 if grep '^dpkg: dependency problems prevent configuration of' \
437 $log &>/dev
/null
; then
438 s apt-get
-fy install
457 pi cups ghostscript gsfonts
# from arch wiki cups page
458 pi hplip
# from google
459 s gpasswd
-a $USER sys
# from arch wiki
460 sgo org.cups.cupsd.service
461 # goto http://127.0.0.1:631
462 # administration tab, add new printer button.
463 # In debian, I could use hte recommended driver,
464 # in arch, I had to pick out the 6L driver.
469 # other distros unknown
474 ubuntu|debian
) pi
--no-install-recommends mairix notmuch
;;
475 fedora|arch
) spa mairix notmuch
;;
478 arch
) spa nfs-utils
;;
479 ubuntu|debian
) spa nfs-client
;;
482 ubuntu|debian
) spa par2
;;
483 arch|fedora
) spa par2cmdline
;;
486 # needed for my tex resume
488 ubuntu|debian
) spa texlive-full
;;
489 arch
) spa texlive-most
;;
495 # flash, unrar, codecs, ms fonts.
496 # This has a manual prompt.
497 spa ubuntu-restricted-extras
501 # rpm fusion recommended codecs
502 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"
503 pi gstreamer-plugins-ugly gstreamer-plugins-bad gstreamer-ffmpeg\
504 xine-lib-extras-freeworld
509 # optional dep for firefox for h.264 video
510 arch
) spa gst-libav
;;
511 # other distros, probably come by default
515 fedora|ubuntu|debian
) spa gnupg-agent
;;
521 fedora
) spa pinentry-gtk
;;
522 *) : ;; # comes default or with other packages
526 arch
) spa firefox pulseaudio
;;
527 *) : ;; # comes default or with other packages
532 arch
) spa ttf-dejavu
;;
533 debian|ubuntu
) spa fonts-dejavu
;;
540 debian|ubuntu
) spa x11-utils
;;
545 arch
) pi virt-install
;;&
546 debian|ubuntu
) pi virtinst
;;&
547 *) pi virt-manager
;; # creates the libvirt group in debian at least
550 # allow user to run vms, from debian handbook
551 for x
in ian traci
; do s usermod
-a -G libvirt
,kvm
$x; done
552 # bridge networking as user fails. google lead here, but it doesn't work:
553 # oh well, I give up.
554 # http://wiki.qemu.org/Features-Done/HelperNetworking
556 # f=/etc/qemu/bridge.conf
560 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
566 debian|ubuntu
) spa genisoimage
;;
571 arch
) spa spice-gtk3
;;
572 debian|ubuntu
) spa spice-client-gtk
;;
576 # general known for debian/ubuntu, not for fedora
579 # cdrkit for cloud-init isos
580 # dnsmasq & ebtables for nat networking in libvirt
581 # qemu for qemu-img, bind-tools for dig
582 # dmidecode just because syslog complains
583 pi
unzip xorg-xmodmap dmidecode ebtables\
584 bridge-utils dnsmasq qemu bind-tools
585 # otherwise we get error about accessing kvm module.
586 # seems like there might be a better way, but google was a bit vague.
587 s
sed -ri '/^ *user *=/d' /etc
/libvirt
/qemu.conf
588 echo 'user = "root"' | s
tee -a /etc
/libvirt
/qemu.conf
589 # https://bbs.archlinux.org/viewtopic.php?id=206206
590 # # this should prolly go in the wiki
592 # guessing this is not needed
593 #sgo virtlogd.service
600 arch
) pi virtviewer
;;
601 *) : ;; # other distros have it as a dependency afaik.
607 fedora
) cabal
install shellcheck
;;
609 # unknown for older ubuntu
614 arch|debian|ubuntu
) spa pumpa
;;
615 # others unknown. do have a buildscript:
616 # /a/bin/buildscripts/pumpa ;;
621 debian|ubuntu
) spa android-tools-adb
/unstable
;;
622 arch
) spa android-tools
;;
623 # other distros unknown
628 if [[ `debian-archive` == testing
]]; then
629 # has no unstable dependencies
630 spa bitcoin-qt
/unstable
633 # other distros unknown
637 # proprietary flash. going without for now
640 # pi flashplugin-nonfree
648 wget http
://tamacom.com
/global
/global-6.3
.2.
tar.gz
651 # based on https://github.com/leoliu/ggtags
652 .
/configure
--with-exuberant-ctags=/usr
/bin
/ctags
655 s pip
install pygments
671 pi task-cinnamon-desktop
672 # in settings, change scrolling to two-finger,
673 # because the default edge scroll doesn\'t work.
682 # already in debian jessie
688 # note this failed running at the beginning of this file,
689 # because no systemd user instance was running.
690 # Doing systemd --user resulted in
691 # Trying to run as user instance, but $XDG_RUNTIME_DIR is not set
693 # ubuntu unknown. probably the same as debian, just check if the
694 # init scripts come with the package.
696 # copied from arch, but moved to etc
697 s
dd of
=/etc
/systemd
/user
/synergys.service
<<'EOF'
699 Description=Synergy Server Daemon
704 ExecStart=/usr/bin/synergys --no-daemon --config /etc/synergy.conf
708 WantedBy=multi-user.target
710 s
dd of
=/etc
/systemd
/user
/synergys.socket
<<'EOF'
712 Conflicts=synergys@.service
719 WantedBy=sockets.target
724 # taken from arch wiki.
725 s
dd of
=/etc
/systemd
/system
/synergyc@.service
<<'EOF'
727 Description=Synergy Client
732 ExecStart=/usr/bin/synergyc --no-daemon treetowl
734 # per man systemd.unit, StartLimitInterval, by default we
735 # restart more than 5 times in 10 seconds.
736 # And this param defaults too 200 miliseconds.
740 WantedBy=multi-user.target
744 ser
enable synergyc@ian
745 ser start synergyc@ian ||
: # X might not be running yet
746 systemctl
--user start synergys ||
:
747 systemctl
--user enable synergys
749 treetowl
) systemctl
--user enable synergys
;;
755 ######### end misc packages #########
758 # packages I once used before and liked, but don't want installed now for
760 # python-sqlite is used for offlineimap
761 # lxappearance python-sqlite dolphin paman dconf-editor
767 # todo, finish configuring smart.
770 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
771 # turn on smart. background on options:
772 # first line, -a = test everyting on all devices.
773 # -S on, turn on disk internal saving of vendor specific info,
774 # from google, seems like this is usually already on and fairly standard.
775 # -o on, turn on 4 hour period non-performance degrading testing.
776 # short test daily 2-3am, extended tests Saturdays between 3-4am:
777 sched
="-s (S/../.././02|L/../../6/03)"
778 s
sed -i "s#^[[:space:]]*DEVICESCAN.*#\
779 DEVICESCAN -a -o on -S on -n standby,q $sched\
780 -m ian@iankelling.org -M exec /usr/local/bin/smart-notify#" /etc
/smartd.conf
782 # in the default configuration of at least ubuntu 14.04, resolvconf is
783 # configured to order any nameservers associated with tun* or tap*
784 # before the normal internet interfaces, which means they are always
785 # consulted first. This is often slower and undesirable, ie. local dns
786 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
788 #sudo sed -i '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
789 # however, this breaks dns lookup for hosts on the openvpn lan.
790 # I can\'t figure out why hosts on the normal lan would not be
791 # broken under the default ordering, except the host I was
792 # testing with previously had an entry in /etc/hosts.
794 ############# end unfinished
796 ########### misc stuff
801 case `debian-archive` in
803 s
dd of
=/etc
/apt
/preferences.d
/unison-gtk
<<'EOF'
804 Explanation: Allow unison-gtk to be upgraded
806 Pin: release a=unstable
809 # dont think using testing is needed since I figured out how to
810 # deal with mismatching unison compilers, but I dont
811 # see any reason to revert it, since it only installs
812 # a single package which is primarily a single binary
813 pi unison-gtk
/testing unison
/testing
827 # default is alsa, doesn\'t work with with pianobar
828 s
dd of
=/etc
/libao.conf
<<'EOF'
834 # not using it atm, and for jessie, it depends on a higher version of btrfs-tools
836 # arch|debian|ubuntu) pi btrbk ;;
840 if [[ $HOSTNAME == treetowl
]] && [[ `debian-archive` != testing
]]; then
841 # fail2 ban is broken, with a workaround, per
842 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=770171
843 # ill wait a while to see if it gets fixed
853 debian|ubuntu
) s gpasswd
-a ian adm
;; #needed for reading logs
859 # https://www.torproject.org/docs/rpms.html.en
860 # https://www.torproject.org/docs/debian.html.en
861 # todo: figure out if the running service needs to be restarted upon updates
864 # todo on fedora: setup non-dev packages
866 s
dd of
=/etc
/yum.repos.d
/torproject.repo
<<'EOF'
868 name=Tor experimental repo
870 baseurl=http://deb.torproject.org/torproject.org/rpm/tor-testing/fc/20/$basearch/
872 gpgkey=http://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org.asc
875 name=Tor experimental source repo
878 baseurl=http://deb.torproject.org/torproject.org/rpm/tor-testing/fc/20/SRPMS
880 gpgkey=http://deb.torproject.org/torproject.org/rpm/RPM-GPG-KEY-torproject.org.asc
883 # to be secure, take a look at the fingerprint reported from the following install, and see if it matches from the link above:
884 # 3B9E EEB9 7B1E 827B CF0A 0D96 8AF5 653C 5AC0 01F1
886 /a
/bin
/buildscripts
/tor-browser
889 tu
/etc
/apt
/sources.list
"deb http://deb.torproject.org/torproject.org $(debian-codename) main"
890 gpg
--keyserver keys.gnupg.net
--recv 886DDD89
891 gpg
--export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add
-
893 pi deb.torproject.org-keyring
895 /a
/bin
/buildscripts
/tor-browser
899 /a
/bin
/buildscripts
/tor-browser
902 pi tor tor-browser-en
912 fedora todo: disable the firewall or find a way to automate it.
913 there's an unused section in t.org for tramikssion firewall setup
915 fedora manual config for nfs:
917 change to permanent configuration
918 check the box for nfs
919 was hard to figure this out, not sure if this is all needed, but
921 mountd: udp/tcp 20048
922 portmapper, in firewall-config its called rpc-bind: udp/tcp 111
923 troubleshooting, unblock things in rpcinfo -p
924 make sure to reload the firewall to load the persistent configuration
935 pi nfs-utils || pending_reboot
=true
937 # this failed until I rebooted
942 if [[ $HOSTNAME == frodo
]]; then
943 tu
/etc
/exports
<<'EOF'
944 /k 192.168.1.0/24(rw,nohide,no_subtree_check,insecure)
949 if [[ -e /k
/video
]]; then
950 # nohide = export filesystems mounted deeper than the export point
951 # fsid=0 makes this export the "root" export
952 # not documented in the man page, but this means
953 # 1. it can be mounted with a shorthand of server:/
954 # 2. exports that are subdirectories of this one will automatically be mounted
955 tu
/etc
/exports
'/i/video 192.168.1.0/24(rw,fsid=0,nohide,no_root_squash,async,no_subtree_check,insecure)'
957 showmount
-e localhost
965 # persistent virtual machines
973 # distro may not know about win 10 yet.
975 if ! virt-install
--os-variant list
&>/dev
/null
; then # we are using a newer virt-install
976 for v
in 10 8.1 8; do
977 if osinfo-query os | gr
"^\s*win${v/./\\.}\s" &>/dev
/null
; then
984 if ! s virsh list
--all --name |
grep -xF win10
&>/dev
/null
; then
986 # created account with
987 # win10vmian@outlook.com, and easy to remember password
988 # win 10 virtio, makes disk way way way faster
989 # wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso
990 # https://wiki.archlinux.org/index.php/QEMU#Change_Existing_Windows_VM_to_use_virtio
991 # for installing virtio after initial install instead of with initial iso:
992 # qemu-img create -f qcow2 fake.qcow2 1G
993 # --disk=/a/images/virtio-win.iso,device=cdrom \
994 # --disk=/a/images/fake.qcow2,bus=virtio
996 # went to device manager, saw 2 pci devices with yellow !,
997 # did search for drivers, pick cdrom location, done.
999 # from http://www.tenforums.com/tutorials/4189-fast-startup-turn-off-windows-10-a.html.
1000 # google said there was a control panel option for it, but
1001 # that turned out to be a lie.
1002 # Put this in a .bat file and run as administrator to turn off
1003 # hyberboot which fucks things up.
1004 # REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V HiberbootEnabled /T REG_dWORD /D 0 /F
1005 # power settings, turn off display: never
1006 # run "control userpasswords2", turn on automatic login.
1007 # note: when changing devices, I just undefine, the create the vm again.
1009 s virt-install
--noautoconsole --graphics spice
,listen
=0.0.0.0 \
1010 --disk=/a
/images
/win10.qcow2
,bus
=virtio
--vcpus 2 -r 4096 -w bridge
=br0 \
1011 -n win10
--import --os-variant $variant --cpu host-model-only
1013 s virsh destroy win10
1015 # this one hasn\'t had the virtio fix done yet.
1016 s virt-install
--noautoconsole --graphics spice
,listen
=0.0.0.0 \
1017 --disk=/a
/images
/win7.qcow2
--vcpus 2 -r 4096 -w bridge
=br0 \
1018 -n win7
--import --os-variant win7
--cpu host-model-only
1019 s virsh destroy win7
1020 # had a problem with --cpu host, so trying out
1021 # --cpu host-model-only
1027 # note samba re-reads it's config every 1 minute
1029 arch
) s
cp /etc
/samba
/smb.conf.default
/etc
/samba
/smb.conf
;;
1032 # add 2 lines after workgroup option
1033 s
sed -ri '/^\s*encrypt passwords\s*=/d' /etc
/samba
/smb.conf
1034 s
sed -ri '/^\s*map to guest\s*=/d' /etc
/samba
/smb.conf
1035 s
sed -i 's/\(\s*workgroup\s*=\).*/\1 WORKGROUP\n\tencrypt passwords = yes\n\tmap to guest = bad password/' /etc
/samba
/smb.conf
1036 # remove default homes section. not sharing that.
1037 s
sed -ri '/^\s*\[homes\]/,/\s*\[/d' /etc
/samba
/smb.conf
1039 if ! grep -xF '[public]' /etc
/samba
/smb.conf
&>/dev
/null
; then
1040 s
tee -a /etc
/samba
/smb.conf
<<'EOF'
1050 # systemd claims it generates units from /etc/init.d, but it clearly doesn't
1051 # in debian. I have no idea how they are related. fuck debian right now. It's
1052 # not documented. samba has a systemd init file linked to /dev/null.
1053 # There's this https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=769714 which
1054 # claims samba's sub-services will be started automatically by systemd... it
1055 # didn't on install, wonder if it will on boot. It clued me in how to start
1056 # it manually though. Nothing in /usr/share/doc/samba, debian admin guide
1057 # says nothing about any of this. (this is in debian testing as of 4/2016).
1059 s
/etc
/init.d
/samba start
1066 tu
/etc
/hosts
<<< "127.0.1.1 $(hostname).lan $(hostname)"
1070 rootdev
=$
(mount |
sed -rn 's#^(\S+) on / .*#\1#p')
1072 tu
/etc
/fstab
<<< "$rootdev /mnt/root btrfs noatime,subvolid=0 0 0"
1073 mountpoint
/mnt
/root || s mount
/mnt
/root
1074 idev
=$
(mount |
sed -rn 's#^(\S+) on /i .*#\1#p')
1075 if [[ $idev != $rootdev ]]; then
1077 tu
/etc
/fstab
<<< "$idev /mnt/iroot btrfs noatime,subvolid=0 0 0"
1078 mountpoint
/mnt
/iroot || s mount
/mnt
/iroot
1082 ######### begin stuff belonging at the end ##########
1085 # Apps we want to override others for default file handler:
1086 # simplest way in debian is to just install them last.
1099 pi
"${simple_packages[@]}"
1102 if $pending_reboot; then
1103 echo "$0: pending reboot and then finished. doing it now."
1106 echo "$0: $(date): ending now)"