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