mostly reorganizing and cleanup
[distro-setup] / distro-begin
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 # for setting up a new machine
17 # usage: $0 [-r] HOSTNAME
18
19 # tips:
20 # run any sudo command first so your pass is cached
21 # set the scrollback to unlimited in case something goes wrong
22
23
24 ####### begin setup environment #######
25
26
27 ### make ssh interactive shell run better. for when running line interactively line by line
28 sudo bash -c 'source /a/c/.bashrc && source /a/exe/ssh-emacs-setup'
29
30
31 ##### setup error handling
32 interactive=true # set this to false to force set -x
33 [[ $- == *i* ]] || interactive=false
34 if ! $interactive; then
35 set -x
36 set -e -o pipefail
37 fi
38 set -E
39 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
40 for x in /a/bin/errhandle/*-function; do
41 source $x
42 done
43 set +e
44 $interactive || errcatch
45
46 ### setup logging
47 exec &> >(sudo tee -a /var/log/distro-begin)
48 echo "$0: $(date): starting now)"
49
50
51 ### sanity checking
52 if [[ $EUID == 0 ]]; then
53 if getent passwd iank || getent passwd ian ; then
54 echo "$0: error: running as root. unprivileged user exists. use it."
55 exit 1
56 else
57 echo "$0: warning: running as root. I will setup users then exit"
58 fi
59 fi
60
61
62 ### arg parsing
63 recompile=false
64 # for copying to a new data fs
65 bootstrapfs=false # old flag, needs new look before using.
66 while [[ $1 == -* ]]; do
67 case $1 in
68 -r) recompile=true; shift ;;
69 esac
70 done
71 if [[ $1 ]]; then
72 export HOSTNAME=$1
73 fi
74
75
76 ##### variables/env setup
77 script_dir="$(readlink -f "$BASH_SOURCE")"
78 source $script_dir/pkgs
79 set +x
80 source /a/bin/distro-functions/src/identify-distros
81 $interactive || set -x
82 for f in iank-dev htpc treetowl x2 frodo tp li lj demohost kw fz; do
83 eval "$f() { [[ $HOSTNAME == $f ]]; }"
84 done
85 has_p() { ! linode; } # when tp is tracis, then not tp either
86 has_x() { ! linode; }
87 linode() { lj || li; }
88 has_btrfs() { ! linode; }
89 home_network() { ! linode; }
90 encrypted() { has_p; }
91 shopt -s extglob
92 export GLOBIGNORE=*/.:*/..
93 umask 022
94 PATH="/a/exe:$PATH"
95 sed="sed --follow-symlinks"
96
97 ####### end setup environment #######
98
99
100
101
102 ##### begin setup encryption scripts ######
103 if encrypted; then
104 # I tried making a service which was dependent on reboot.target,
105 # but it happened too late in the shutdown process.
106 sudo dd of=/etc/systemd/system/keyscripton.service <<'EOF'
107 [Unit]
108 Description=Turn on automatic decryption of drives on boot
109 # tried using graphical.target, but it made my display manager restart before rebooting.
110 # generally, I don't think targets order shutdown like they do startup.
111 # So, I did systemd-analyze plot > something.svg, and picked a reliably started
112 # service that happens late in the game.
113 After=ntp.service
114 DefaultDependencies=no
115 # not sure if needed, makes sure we shut down before reboot.target
116 Conflicts=reboot.target
117
118 [Service]
119 Type=oneshot
120 RemainAfterExit=yes
121 ExecStart=/bin/true
122 ExecStop=/a/exe/keyscript-on
123
124 [Install]
125 WantedBy=keyscriptoff.service
126 EOF
127 sudo systemctl daemon-reload # needed if the file was already there
128 sudo systemctl stop keyscripton.service
129 # sudo systemctl start keyscripton.service
130 sudo systemctl enable keyscripton.service
131
132 sudo dd of=/etc/systemd/system/keyscriptoff.service <<'EOF'
133 [Unit]
134 Description=Turn off automatic decryption of drives on boot
135
136 [Service]
137 Type=oneshot
138 ExecStart=/a/exe/keyscript-off
139
140 [Install]
141 WantedBy=multi-user.target
142 EOF
143 sudo systemctl daemon-reload # needed if the file was already there
144 sudo systemctl enable keyscriptoff.service
145 sudo systemctl start keyscriptoff.service
146 fi
147 ##### end setup encryption scripts ######
148
149
150 # disabled until its fixed up
151 # install-myqueue
152
153 # todo, it would be nice to cut down on some of the output
154
155 ##### fedora prereq/fundamental settings
156 if isfedora; then
157 # comment out line disallowing calling sudo in scripts
158 sudo $sed -i 's/^Defaults *requiretty/#\0 # ian commented/' /etc/sudoers
159 # turn on magic sysrq commands
160 echo 1 > sudo dd of=/proc/sys/kernel/sysrq
161 echo "kernel.sysrq = 1" > /etc/sysctl.d/90-sysrq.conf
162 # selinux is not user friendly. Like, you enable samba, but you haven't run the magic selinux commands so it doesn't work
163 # and you have no idea why.
164 sudo $sed -i 's/^\(SELINUX=\).*/\1disabled/' /etc/selinux/config
165 selinuxenabled && sudo setenforce 0
166 fi
167
168
169 #### rerun my fai-time scripts
170 # already ran for pxe installs, but used for vps & updates
171 distro=$(distro-name)
172 case $distro in
173 ubuntu|debian|trisquel)
174 sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/GRUB_PC/11-iank"
175 ;;
176 *)
177 sudo bash -c ". /a/bin/fai/fai-wrapper &&
178 /a/bin/fai/fai/config/distro-install-common/end"
179 ;;
180 esac
181
182 ###### setup hostname
183 sudo $sed -i '/^127\.0\.1\.1/d' /etc/hosts
184 echo "127.0.1.1 $HOSTNAME.b8.nz $HOSTNAME" | sudo tee -a /etc/hosts
185
186
187 ##### exit first stage if running as root
188 if [[ $EUID == 0 ]]; then
189 echo "$0: running as root. exiting now that users are setup"
190 exit 0
191 fi
192
193
194 #### setup bash for root
195 for x in /a/c/{.bashrc,brc,.bash_profile,.profile,.inputrc,path_add_function}; do
196 sudo -i <<EOF
197 PATH="/a/exe:$PATH"
198 lnf $x /root
199 EOF
200 done
201
202 ###### do conflink
203 # li needs the bind group before conflink
204 if [[ $HOSTNAME == li ]]; then
205 getent group bind &>/dev/null || sudo groupadd -r bind
206 fi
207 # this needs to be before installing pacserve so we have gpg conf.
208 conflink
209
210 ###### bash environment setup
211 set +x
212 errallow
213 source /etc/profile.d/environment.sh
214 source ~/.bashrc
215 $interactive || errcatch
216 $interactive || set -x
217
218
219 #### setup passwordless sudo
220 tu /etc/sudoers <<EOF
221 $USER ALL=(ALL) NOPASSWD: ALL
222 Defaults env_keep += SUDOD
223 # makes ubuntu be like debian
224 # https://unix.stackexchange.com/a/91572
225 Defaults always_set_home
226 EOF
227
228
229 #### setup firefox backport
230 ## ian: disabled. backports are not being published atm due to rust packaging issue
231 # if isdeb; then
232 # codename=$(debian-codename)
233 # if isdebian-stable && has_x; then
234 # s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
235 # deb http://mozilla.debian.net/ $codename-backports firefox-release
236 # deb-src http://mozilla.debian.net/ $codename-backports firefox-release
237 # EOF
238 # p update
239 # # take care of mozilla signing errors in previous command
240 # pi pkg-mozilla-archive-keyring
241 # fi
242 # p update
243 # fi
244
245
246 ###### arch aur wrapper setup
247 if isarch; then
248 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
249 sudo pacman -S --noconfirm --needed base-devel jq
250 # pacaur seems to be the best, although it + cower has a few minor bugs,
251 # its design goals seem good, so, going for it.
252
253 aurpi() {
254 for p in "$@"; do
255 tempdir=$(mktemp -d)
256 pushd $tempdir
257 aurex "$p"
258 makepkg -sri --skippgpcheck --noconfirm
259 popd
260 rm -rf $tempdir
261 done
262 }
263 aurpi cower pacaur
264
265 pi pacserve
266
267 x=$(mktemp); /usr/bin/pacman.conf-insert_pacserve >$x
268 sudo dd of=/etc/pacman.conf if=$x; rm $x
269 sudo systemctl enable pacserve.service
270 sudo systemctl start pacserve.service
271
272 fi
273
274 #### update all packages
275 pup
276
277
278 ###### p1 packages install ######
279 if isarch; then
280 # requirement for trash-cli.
281 # background: strange error if just installing trash-cli: "pyalpm requires python",
282 # so I see that it requires python2, and installing that manually fixes it.
283 # I didn\'t see this on earlier installation, main thing which changed was
284 # pacserve, so not sure if it\'s related.
285 pi python2
286 fi
287 pi ${p1[@]}
288
289
290 ######## fix evbug bug ######
291 case $distro in
292 trisquel|ubuntu)
293 # noticed in flidas.
294 #https://bugs.launchpad.net/ubuntu/+source/module-init-tools/+bug/240553
295 #https://wiki.debian.org/KernelModuleBlacklisting
296 #common advice when searching is to use /etc/modprobe.d/blacklist.conf,
297 #but that file won't work and will get automatically reverted
298 sudo rmmod evbug ||: # might not be loaded yet
299 file=/etc/modprobe.d/evbug.conf
300 line="blacklist evbug"
301 if ! grep -xFq "$line" $file; then
302 sudo dd of=$file 2>/dev/null <<<"$line"
303 sudo depmod -a
304 sudo update-initramfs -u
305 fi
306 ;;
307 esac
308
309
310 ###### link files
311 # convenient to just do all file linking in one place
312 s lnf -T /a/bin /b
313 s lnf -T /nocow/t /t
314 if has_p; then
315 lnf -T /p/News ~/News
316 fi
317 s lnf /q/root/.editor-backups /q/root/.undo-tree-history \
318 /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root
319 rootsshsync
320 s lnf /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
321 if has_p; then
322 # for dovecot
323 lnf -T /i/k/mboxes ~/mail
324 fi
325
326
327 ##### basic needed packages
328
329 ### begin setup for keyboard and redshift ###
330 case $(distro-name) in
331
332 trisquel|ubuntu|debian)
333 if has_x; then
334 if isdebian-testing; then
335 pi xmacro/unstable # has no unstable deps
336 else
337 pi xmacro
338 fi
339 pi xinput
340 # recommends gets us geoclue (for darkening automatically at night i assume),
341 # which recommends modemmanager, which is annoying to fix for the model01 keyboard.
342 pi --no-install-recommends gtk-redshift
343 fi
344 ;;&
345 fedora)
346 p -y groupinstall development-tools c-development books admin-tools
347 pi wget man-pages
348 if has_x; then
349 pi redshift-gtk
350 # debian has this package patched to work, upstream is dead
351 # tried using alien, pi alien, alien -r *.deb, rpm -Uhv *.rpm, got this error, so fuck it
352 # file /usr/bin from install of xmacro-0.3pre_20000911-7.x86_64 conflicts with file from package filesystem-3.2-19.fc20.x86_64
353 # http://packages.debian.org/source/sid/xmacro
354 pi patch libXtst-devel
355 cd $(mktemp -d)
356 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911.orig.tar.gz
357 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911-6.diff.gz
358 ex *.gz
359 patch -p0 < xmacro_0.3pre-20000911-6.diff
360 cd xmacro-0.3pre-20000911.orig
361 make
362 sleep 1 # not sure why the following command couldn\'t find, so trying this
363 # no make install target
364 s cp -f xmacroplay xmacrorec xmacrorec2 /usr/local/bin
365 fi
366 ;;&
367 arch)
368 # like apt-cache
369 pi pkgfile
370 s pkgfile --update
371 if has_x; then
372 # libxtst is missing dep https://aur.archlinux.org/packages/xmacro/#news
373 pi xorg-server redshift xorg-xinput libxtst xmacro
374
375 # background:
376 # https://aur.archlinux.org/packages/xkbset/#comment-545419
377 cert=$(mktemp)
378 cat >$cert <<'EOF'
379 -----BEGIN CERTIFICATE-----
380 MIIJADCCB+igAwIBAgIRAIVAhZ0TMbQ5jTm0koI8X6YwDQYJKoZIhvcNAQELBQAw
381 djELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1JMRIwEAYDVQQHEwlBbm4gQXJib3Ix
382 EjAQBgNVBAoTCUludGVybmV0MjERMA8GA1UECxMISW5Db21tb24xHzAdBgNVBAMT
383 FkluQ29tbW9uIFJTQSBTZXJ2ZXIgQ0EwHhcNMTUxMjA4MDAwMDAwWhcNMTgxMjA3
384 MjM1OTU5WjCBsTELMAkGA1UEBhMCVVMxDjAMBgNVBBETBTY1MjExMREwDwYDVQQI
385 EwhNaXNzb3VyaTERMA8GA1UEBxMIQ29sdW1iaWExHzAdBgNVBAkTFjExMDAgQ2Fy
386 cmllIEZyYW5ja2UgRHIxHzAdBgNVBAoTFlVuaXZlcnNpdHkgb2YgTWlzc291cmkx
387 CzAJBgNVBAsTAk1VMR0wGwYDVQQDExRmYWN1bHR5Lm1pc3NvdXJpLmVkdTCCASIw
388 DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN8Kap8hASpxQeqjHibGsCR1PBkh
389 nW9p5FkuhG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QdnNmLm1pc3NvdXJpLmVkdYIid2hpdGVwYXBlci5ncmFkc2No
422 b29sLm1pc3NvdXJpLmVkdTANBgkqhkiG9w0BAQsFAAOCAQEAQutYVAqG7MpmG2Nu
423 Z/UypjYkN4JvwRbKBpTrce2IT/Sy29x6chBbyD+0WE6QORBtaUHuzE1KoXqpnF4M
424 QrkKw0oBAC6x9dISoomq0DkIndtoBYYLaxSoII6F4OGWgF7pQ/7MiCBYzsKQpn9t
425 aofMcTfvnCjq+MCIaeYnUKBVww0lOJlUxZGKxFJvRpf78HfbBauojjRO2zXLZD/u
426 KMspbTfDaj5etIgWGShY2eml3N/SjAENmZYkcgDBYFyi8CckcEBAVzpH1+D+7Anz
427 txHSYDNHAYLv83MwbegApa1FwPqlG/4SdEU8G6e6Xf5GLC/6GPGVTUpr7o348OOO
428 lzGQzw==
429 -----END CERTIFICATE-----
430 -----BEGIN CERTIFICATE-----
431 MIIF+TCCA+GgAwIBAgIQRyDQ+oVGGn4XoWQCkYRjdDANBgkqhkiG9w0BAQwFADCB
432 iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
433 cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
434 BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQx
435 MDA2MDAwMDAwWhcNMjQxMDA1MjM1OTU5WjB2MQswCQYDVQQGEwJVUzELMAkGA1UE
436 CBMCTUkxEjAQBgNVBAcTCUFubiBBcmJvcjESMBAGA1UEChMJSW50ZXJuZXQyMREw
437 DwYDVQQLEwhJbkNvbW1vbjEfMB0GA1UEAxMWSW5Db21tb24gUlNBIFNlcnZlciBD
438 QTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJwb8bsvf2MYFVFRVA+e
439 xU5NEFj6MJsXKZDmMwysE1N8VJG06thum4ltuzM+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fBjRidj26h1oFBHZ7heDH1Bjzw72
456 hipu47Gkyfr2NEx3KoCGMLCj3Btx7ASn5Ji8FoU+hCazwOU1VX55mKPU1I2250Lo
457 RCASN18JyfsD5PVldJbtyrmz9gn/TKbRXTr80U2q5JhyvjhLf4lOJo/UzL5WCXED
458 Smyj4jWG3R7Z8TED9xNNCxGBMXnMete+3PvzdhssvbORDwBZByogQ9xL2LUZFI/i
459 eoQp0UM/L8zfP527vWjEzuDN5xwxMnhi+vCToh7J159o5ah29mP+aJnvujbXEnGa
460 nrNxHzu+AGOePV8hwrGGG7hOIcPDQwkuYwzN/xT29iLp/cqf9ZhEtkGcQcIImH3b
461 oJ8ifsCnSbu0GB9L06Yqh7lcyvKDTEADslIaeSEINxhO2Y1fmcYFX/Fqrrp1WnhH
462 OjplXuXE0OPa0utaKC25Aplgom88L2Z8mEWcyfoB7zKOfD759AN7JKZWCYwk
463 -----END CERTIFICATE-----
464 -----BEGIN CERTIFICATE-----
465 MIIF3jCCA8agAwIBAgIQAf1tMPyjylGoG7xkDjUDLTANBgkqhkiG9w0BAQwFADCB
466 iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
467 cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
468 BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTAw
469 MjAxMDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBiDELMAkGA1UEBhMCVVMxEzARBgNV
470 BAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQKExVU
471 aGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBSU0EgQ2Vy
472 dGlmaWNhdGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK
473 AoIC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489 8PRF/iKz6y+O0tlFYQXBl2+odnKPi4w2r78NBc5xjeambx9spnFixdjQg3IM8WcR
490 iQycE0xyNN+81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYze
491 Sf7dNXGiFSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZ
492 XHlKYC6SQK5MNyosycdiyA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/
493 qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
494 VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
495 L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
496 jjxDah2nGN59PRbxYvnKkKj9
497 -----END CERTIFICATE-----
498 EOF
499 cat /etc/ssl/certs/ca-certificates.crt >> $cert
500 CURL_CA_BUNDLE=$cert pi xkbset
501 fi
502
503 ;;&
504 ubuntu|trisquel|debian|fedora)
505 if has_x; then
506 if isdebian-testing; then
507 # xkbset was in testing for quite a while, dunno
508 # why it\'s not anymore. Sometime I should check and
509 # see if it\'s back in testing, but the unstable package
510 # doesn\'t upgrade anything form testing, and it\'s tiny
511 # so I\'m not bothering to automate it.
512 pi xkbset/unstable
513 else
514 pi xkbset
515 fi
516 fi
517 ;;&
518 esac
519 if has_x; then
520 pi xbindkeys
521 fi
522 ### end setup for keyboard and redshift ###
523
524 # enables trim for volume delete, other rare commands.
525 sudo $sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
526
527 if encrypted; then
528 if isdeb; then
529 sudo cp /usr/share/doc/util-linux/examples/fstrim.{service,timer} /etc/systemd/system
530 fi
531 # does weekly trim
532 sudo systemctl enable fstrim.timer
533 fi
534
535 dirs=(/mnt/{1,2,3,4,5,6,7,8,9} /nocow/t)
536 s mkdir -p "${dirs[@]}"
537 s chown $USER:$USER "${dirs[@]}"
538
539
540 tu /etc/fstab <<'EOF'
541 /i/w /w none bind,noauto 0 0
542 /i/k /k none bind,noauto 0 0
543 EOF
544
545
546 if ! mountpoint /kr; then
547 s mkdir -p /kr
548 s chown $USER:traci /kr
549 fi
550
551 if home_network; then
552 if [[ $HOSTNAME == frodo ]]; then
553 tu /etc/fstab <<'EOF'
554 /k /kr none bind,noauto 0 0
555 EOF
556 else
557 tu /etc/fstab <<'EOF'
558 frodo:/k /kr nfs noauto 0 0
559 EOF
560 fi
561 fi
562
563 s mkdir -p /q /i/{w,k}
564 for dir in /{i,w,k}; do
565 if mountpoint $dir; then continue; fi # already mounted
566 s mkdir -p $dir
567 s chown $USER:$USER $dir
568 done
569
570 # not needed for all hosts, but rather just keep it uniform
571 s mkdir -p /mnt/iroot
572
573 # debian auto mounting of multi-disk encrypted btrfs is busted. It is
574 # in jessie, and in stretch as of 11/26/2016 I have 4 disks in cryptab,
575 # based on 3 of those, it creates .device units for /dev/mapper/dev...
576 # then waits endlessly for them on bootup, after the /dev/mapper disks
577 # have already been created and exist. todo: create a simple repro
578 # for this in a vm and report it upstream.
579 if has_btrfs || home_network; then
580 pi nfs-common
581 s dd of=/root/imount <<'EOF'
582 #!/bin/bash
583 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
584 set -eE -o pipefail
585 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
586 for dir in /i /mnt/iroot /k /kr /w; do
587 if ! mountpoint $dir &>/dev/null && \
588 awk '{print $2}' /etc/fstab | grep -xF $dir &>/dev/null; then
589 if awk '{print $3}' /etc/fstab | grep -xF nfs &>/dev/null; then
590 mount $dir || echo "warning: failed to mount nfs on $dir"
591 else
592 mount $dir
593 fi
594 fi
595 done
596 EOF
597 s chmod +x /root/imount
598
599 s dd of=/etc/systemd/system/imount.service <<EOF
600 [Unit]
601 Description=Mount /i and related mountpoints
602 Before=syncthing@$USER.service
603
604 [Service]
605 Type=oneshot
606 ExecStart=/root/imount
607
608 [Install]
609 RequiredBy=syncthing@$USER.service
610 # note /kr needs networking, this target is the simplest way to
611 # time it when the network should be up, but not do something
612 # dumb like delay startup until the network is up. It happens
613 # at some time after network.target
614 WantedBy=multi-user.target
615 EOF
616 sudo systemctl daemon-reload # needed if the file was already there
617 sudo systemctl enable imount.service
618 sudo systemctl start imount.service
619 fi
620
621 dir=/nocow
622 if has_btrfs; then
623 if ! mountpoint $dir; then
624 subvol=/mnt/root/nocow
625 if [[ ! -e $subvol ]]; then
626 s btrfs subvolume create $subvol
627 s chown root:1000 $subvol
628 s chattr +C $subvol
629 fi
630
631 first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab)
632 tu /etc/fstab <<EOF
633 $first_root_crypt /nocow btrfs noatime,subvol=nocow 0 0
634 EOF
635 s mkdir -p $dir
636 s chown $USER:$USER $dir
637 s mount $dir
638 fi
639 else
640 sudo mkdir -p $dir
641 fi
642
643 # ssh and probably some other things care about parent directory
644 # ownership, and ssh doesn\'t allow any group writable parent
645 # directories, so we are forced to use a directory structure similar
646 # to home directories
647 s chown root:$USER /q
648 s chmod 755 /q
649
650
651 # it comes with stretch and arch, but not jessie.
652 # propogate /etc/udev/hwdb.d
653 if which systemd-hwdb; then
654 s systemd-hwdb update
655 ser restart systemd-udev-trigger
656 fi
657
658
659 if isdeb; then
660 # I\'ve had problems with postfix on debian:
661 # on stretch, a startup ordering issue caused all mail to fail.
662 # postfix changed defaults to only use ipv6 dns, causing all my mail to fail.
663 # exim4 is default on debian, so I assume it would
664 # be packaged better to avoid these types of things.
665 # I haven\'t gotten around to getting a non-debian exim
666 # setup.
667 mail-setup exim4
668 else
669 mail-setup postfix
670 fi
671
672 if isubuntu; then
673 # disable crash report annoying dialogs.
674 s dd of=/etc/default/apport <<<'enabled=0'
675 fi
676
677 # fai sets this an old way that doesn't work for stretch.
678 # no harm in setting it universally here.
679 # using debconf-set-selection, the area gets reset to ETC
680 # on my linode test machine after doing a dpkg-reconfigure, or a reinstall,
681 # so we are using expect :(
682 # I got a random error when running this, so I added a sleep
683 # rather than trying to write a whole detect and wait loop.
684 # E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
685 # E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
686 sleep 1
687 # todo: this is not idempotent, it fails when running twice, due to prepopulated values.
688 # check into unsetting them using debconf-set-selection.
689 s apt-get -y install --no-install-recommends expect
690 s expect <<EOF ||:
691 set force_conservative 0
692 spawn dpkg-reconfigure tzdata -freadline
693 expect -nocase timeout {exit 1} "Geographic area:"
694 send "\02512\r"
695 expect -nocase timeout {exit 1} "Time zone:"
696 send "\0255\r"
697 expect eof
698 exit
699 EOF
700
701
702 if has_x; then
703 if isarch; then
704 # install so it's build dependencies don't get removed.
705
706 # emacs git build is currently broken
707 if false; then
708 x=$(mktemp -d)
709 pushd $x
710 aurex emacs-git
711 makepkg -si --noconfirm
712 popd
713 rm -rf $x
714 else
715 pi emacs
716 fi
717 pi hunspell hunspell-en
718 else
719 if $recompile; then
720 /a/bin/buildscripts/emacs
721 else
722 /a/bin/buildscripts/emacs --no-r || /a/bin/buildscripts/emacs
723 fi
724 fi
725
726 # todo, figure this out for arch if we ever try out gnome.
727 if ! isarch; then
728 # install for multiple display managers in case we use one
729 if isdeb; then
730 dir=/etc/gdm3
731 elif isfedora; then
732 # fedora didn\'t have the 3.
733 dir=/etc/gdm
734 fi
735 s mkdir -p $dir/PostLogin
736 s command cp /a/bin/distro-setup/desktop-20-autostart.sh $dir/PostLogin/Default
737 s mkdir /etc/lightdm/lightdm.conf.d
738 s dd of=/etc/lightdm/lightdm.conf.d/12-iank.conf <<'EOF'
739 [SeatDefaults]
740 session-setup-script=/a/bin/distro-setup/desktop-20-autostart.sh
741 EOF
742 fi
743
744
745 pi ${p2[@]}
746 # todo, also note for work comp, scp opt/org-mode bin/build-scripts
747
748 # use the package manger version to install the cabal version
749 cabal update
750 PATH="$PATH:$HOME/.cabal/bin"
751
752 # todo, on older ubuntu I used cabal xmonad + xfce,
753 # see /a/bin/old-unused/xmonad-cabal.sh
754
755 if isarch; then
756 # for displaying error messages.
757 # optional dependency in arch, standard elsewhere.
758 pi xorg-xmessage xmonad-contrib xorg-xsetroot xorg-xinit
759
760 # https://wiki.archlinux.org/index.php/Xinitrc
761 for homedir in /home/*; do
762 cp /etc/X11/xinit/xinitrc $homedir/.xinitrc
763 $sed -ri '/^ *twm\b/,$d' $homedir/.xinitrc
764 tee -a $homedir/.xinitrc <<'EOF'
765 /a/bin/desktop-20-autostart.sh
766 xsetroot -cursor_name left_ptr
767 exec xmonad
768 EOF
769 done
770 else
771 pi suckless-tools
772 fi
773 pi dmenu
774
775 if tp || x2; then
776 case $distro in
777 debian)
778 pi task-laptop
779 ;;
780 ubuntu|trisquel)
781 # the exact packages that task-laptop would install, since ubuntu
782 # doesn\'t have this virtual in practice package.
783 pi avahi-autoipd bluetooth powertop iw wireless-tools wpasupplicant
784 ;;
785 # todo: other distros unknown
786 esac
787 fi
788 fi
789
790 # the first pup command can kill off our /etc/ mod, so rerun this
791 /a/exe/ssh-emacs-setup
792 echo "$0: $(date): ending now"
793 exit 0