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