2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
5 # todo. dunno why, but original bootstrap of timezone is not sticking.
7 # s dpkg-reconfigure tzdata
10 # for bootstrapping a new machine
12 # to make ssh run better, first run this:
13 sudo bash
-c 'source /a/c/repos/bash/.bashrc && source /a/bin/ssh-emacs-setup'
16 # see t.org for OS installer notes
18 # usage: $0 [OPTIONS] HOSTNAME
21 # run any sudo command first so your pass is cached
22 # set the scrollback to unlimited in case something goes wrong
24 if [[ $EUID == 0 ]]; then
25 echo "error: do not run as root"
29 interactive
=true
# set this to true if running by hand in emacs
30 [[ $
- == *i
* ]] || interactive
=false
34 if ! $interactive; then
39 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
41 # headless=false # unused atm
43 # for copying to a new data fs
44 bootstrapfs
=false
# old flag, needs new look before using.
45 while [[ $1 == -* ]]; do
47 # avoid some of the longer compilation steps,
48 # when we need to rerun because we had an error
49 -n) recompile
=false
; shift ;;
59 for f
in iank-dev htpc treetowl x2 frodo tp
; do
60 eval "$f() { [[ $host == $f ]]; }"
62 has_p
() { iank-dev || x2 || frodo
; }
63 encrypted
() { has_p || tp
; }
66 export GLOBIGNORE
=*/.
:*/..
70 ####### end command line parsing
73 # I tried making a service which was dependent on reboot.target,
74 # but it happened too late in the shutdown process.
75 sudo
dd of
=/etc
/systemd
/system
/keyscripton.service
<<'EOF'
77 Description=Turn on automatic decryption of drives on boot
78 # tried using graphical.target, but it made my display manager restart before rebooting.
79 # generally, I don't think targets order shutdown like they do startup.
80 # So, I did systemd-analyze plot > something.svg, and picked a reliably started
81 # service that happens late in the game.
83 DefaultDependencies=no
84 Conflicts=reboot.target
90 ExecStop=/a/bin/keyscript-on
93 WantedBy=keyscriptoff.service
95 sudo systemctl daemon-reload
# needed if the file was already there
96 sudo systemctl stop keyscripton.service
97 # sudo systemctl start keyscripton.service
98 sudo systemctl
enable keyscripton.service
100 sudo
dd of
=/etc
/systemd
/system
/keyscriptoff.service
<<'EOF'
102 Description=Turn off automatic decryption of drives on boot
106 ExecStart=/a/bin/keyscript-off
109 WantedBy=multi-user.target
111 sudo systemctl daemon-reload
# needed if the file was already there
112 sudo systemctl
enable keyscriptoff.service
113 sudo systemctl start keyscriptoff.service
117 desktop
=$
(ssh root@iankelling.org
grep desktop
/etc
/hosts |
grep -o "^.* ")
118 if $bootstrapfs; then
119 # for bootstrapping at a new job:
121 # for moving to a new hd, change $cp to move between filesystems
125 $cp/a
/c
/bin
/{bash-programs-by-ian
,distro-begin
,distro-functions
,input-setup.sh
} /a
/bin
126 echo -e \\n
\\n
\\n | ssh-keygen
-t rsa
130 # this script has been designed to be idempotent
131 # todo, it would be nice to cut down on some of the output
134 # output is below so shellcheck can verify sources
135 for x
in /a
/bin
/bash-programs-by-ian
/repos
/{errhandle
,tee-unique
,lnf
}/*-function; do
136 echo "# shellcheck source=$x";
137 # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/bash-trace-function
138 # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errallow-function
139 # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errcatch-function
140 # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errexit-function
141 # shellcheck source=/a/bin/bash-programs-by-ian/repos/tee-unique/teeu-function
142 # shellcheck source=/a/bin/bash-programs-by-ian/repos/lnf/lnf-function
148 $interactive || errcatch
149 source /a
/bin
/distro-functions
/src
/identify-distros
155 # comment out line disallowing calling sudo in scripts
156 sudo
sed -i 's/^Defaults *requiretty/#\0 # ian commented/' /etc
/sudoers
157 # turn on magic sysrq commands for this boot cycle
158 echo 1 > sudo
dd of
=/proc
/sys
/kernel
/sysrq
159 # selinux is not user friendly. Like, you enable samba, but you haven't run the magic selinux commands so it doesn't work
160 # and you have no idea why.
161 sudo
sed -i 's/^\(SELINUX=\).*/\1disabled/' /etc
/selinux
/config
162 selinuxenabled
&& sudo setenforce
0
171 for x
in /a
/c
/repos
/bash
/!(.git
); do
172 for homedir
in /home
/*; do
173 sudo chown
-R ian
:ian
$homedir
177 source /a/bin/bash-programs-by-ian/repos/lnf/lnf-function
188 $interactive || errcatch
189 $interactive ||
set -x
193 tu
/etc
/sudoers
<<'EOF'
194 ian ALL=(ALL) NOPASSWD: ALL
195 Defaults env_keep += SUDOD
199 # enable magic sysrq keys. debian docs say it is already enabled by default
200 isfedora
&& tu
/etc
/sysctl.conf
'kernel.sysrq = 1'
205 # add contrib non-free to sources for main
206 s
sed -i 's/^\(deb.* main\).*/\1 contrib non-free/' /etc
/apt
/sources.list.d
/*
208 # non-existent var, as Im not planning to use stable right now
209 if isdebian-stable
; then
210 code
=$
(debian-codename
)
211 s
dd of
=/etc
/apt
/sources.list.d
/mozilla-iceweasel.list
<<EOF
212 deb http://mozilla.debian.net/ $code-backports firefox-release
213 deb-src http://mozilla.debian.net/ $code-backports firefox-release
216 # we change the mirror from the default, so we cant use tu
217 s
dd of
=/etc
/apt
/sources.list.d
/main-backports.list
<<EOF
218 deb http://http.debian.net/debian $code-backports main contrib non-free
219 deb-src http://http.debian.net/debian $code-backports main contrib non-free
223 # take care of mozilla signing errors in previous command
224 pi pkg-mozilla-archive-keyring
228 # this would change stable to testing, but I set that up already.
229 # It\'s just a no-op if its already testing.
230 # sudo sed -ri 's!^( *[^ #]+ +[^ ]+ +)[[:alpha:]]+(.*)!\1testing\2!' /etc/apt/sources.list
236 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
237 sudo pacman
-S --noconfirm --needed base-devel jq
238 # pacaur seems to be the best, although it + cower has a few minor bugs,
239 # its design goals seem good, so, going for it.
246 makepkg
-sri --skippgpcheck --noconfirm
253 # this creates ~/.gnupg. addgnupghome is broken on arch.
255 # for aur, automatically dl & add gpg keys.
256 # Just the keyserver-options line goes in dirmngr.conf once
257 # this bug is fixed: https://bugs.gnupg.org/gnupg/issue2147
258 for homedir
in /home
/*; do
259 teeu
$homedir/.gnupg
/gpg.conf
<<EOF
260 $(grep -o '^ *keyserver .*' $homedir/.gnupg/dirmngr.conf)
261 keyserver-options auto-key-retrieve
265 x
=$
(mktemp
); 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
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.
281 ###### link files ###########
282 # convenient to just do all file linking in one place
286 # if it wasn't set already, we could set hostname here
287 #echo treetowl | s dd of=/etc/hostname
288 #s hostname -F /etc/hostname
289 #HOSTNAME=$(hostname)
291 #########################################
292 # NOTE: only /a needs to be mounted for creating links!
293 ###########################################
295 # todo: reconcile ~/.ssh/config work/home
298 lnf
-T /p
/offlineimap ~
/Maildir
299 lnf
-T /p
/News ~
/News
300 # don't use /* because I don't want to require it to be mounted
301 s lnf
/q
/root
/.editor-backups
/q
/root
/.undo-tree-history \
302 /q
/root
/.
ssh /a
/opt \
303 /a
/c
/.emacs.d ~
/.unison
/root
307 s lnf
/a
/c
/.inputrc
/a
/c
/.vim
/a
/c
/.vimrc
/a
/c
/.gvimrc
/root
309 # machine is going away
310 # if [[ $HOSTNAME == htpc ]]; then
311 # lnf -T /i/Videos ~/Downloads
316 lnf
-T /i
/k
/mboxes ~
/mail
320 # basic needed packages
321 case $
(distro-name
) in
323 pi firefox$
( isdebian-stable
&& e
/$code-backports )
324 # for hosts which require nonfree drivers
327 *) pi linux-image-amd64 firmware-linux-nonfree \
328 firmware-linux-free linux-headers-amd64
333 pi xmacro gtk-redshift xinput
336 p
-y groupinstall development-tools c-development books admin-tools
338 # debian has this package patched to work, upstream is dead
339 # tried using alien, pi alien, alien -r *.deb, rpm -Uhv *.rpm, got this error, so fuck it
340 # 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
341 # http://packages.debian.org/source/sid/xmacro
342 pi
patch libXtst-devel wget man-pages
# what is the ubuntu equivalent to man-pages?
344 wget http
://ftp.de.debian.org
/debian
/pool
/main
/x
/xmacro
/xmacro_0.3pre-20000911.orig.
tar.gz
345 wget http
://ftp.de.debian.org
/debian
/pool
/main
/x
/xmacro
/xmacro_0.3pre-20000911-6.
diff.gz
347 patch -p0 < xmacro_0.3pre-20000911-6.
diff
348 cd xmacro-0.3pre-20000911.orig
350 sleep 1 # not sure why the following command couldn\'t find, so trying this
351 # no make install target
352 s
cp -f xmacroplay xmacrorec xmacrorec2
/usr
/local
/bin
355 # libxtst is missing dep https://aur.archlinux.org/packages/xmacro/#news
356 pi xorg-server redshift xorg-xinput pkgfile libxtst xmacro
362 pi xbindkeys xkbset cryptsetup
365 # enables trim for volume delete, other rare commands.
366 sudo
sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc
/lvm
/lvm.conf
370 sudo
cp /usr
/share
/doc
/util-linux
/examples
/fstrim.
{service
,timer
} /etc
/systemd
/system
373 sudo systemctl
enable fstrim.timer
376 dirs=(/mnt
/{1,2,3,4,5,6,7,8,9})
377 s mkdir
-p "${dirs[@]}"
378 s chown ian
:ian
"${dirs[@]}"
380 if [[ $HOSTNAME == treetowl
]]; then
381 tu
/etc
/fstab
<<'EOF'
382 UUID=3f7b31cd-f299-40b4-a86b-7604282e2715 /i btrfs noatime 0 2
385 tu
/etc
/fstab
<<'EOF'
386 /q/i /i none bind 0 0
390 tu
/etc
/fstab
<<'EOF'
391 /i/w /w none bind 0 0
392 /i/k /k none bind 0 0
395 if ! mountpoint
/kfrodo
; then
397 s chown ian
:traci
/kfrodo
399 if [[ $HOSTNAME == frodo
]]; then
400 tu
/etc
/fstab
<<'EOF'
401 /k /kfrodo none bind 0 0
404 tu
/etc
/fstab
<<'EOF'
405 frodo:/k /kfrodo nfs defaults 0 0
410 s mount
/$i ||
[[ $?
== 32 ]] # 32 = already mounted
414 # ssh and probably some other things care about parent directory
415 # ownership, and ssh doesn\'t allow any group writable parent
416 # directories, so we are forced to use a directory structure similar
417 # to home directories
424 # propogate /etc/udev/hwdb.d
425 s systemd-hwdb update
426 ser restart systemd-udev-trigger
428 # work desktop doesnt need gpg stuff, but it doesnt hurt
429 s
dd of
=/etc
/profile.d
/environment.sh
<<'EOF'
430 # IAN: EDIT THIS FROM /a/bin/distro-begin
432 if [ -f $HOME/path_add-function ]; then
433 . $HOME/path_add-function
434 path_add /usr/sbin /usr/local/sbin /sbin
435 path_add /a/bin /a/opt/bin $HOME/.cabal/bin
437 if [ -r /etc/alternatives/java_sdk ]; then
438 export JAVA_HOME=/etc/alternatives/java_sdk
439 path_add /etc/alternatives/java_sdk
443 export EDITOR="emacsclient"
444 # this makes emacsclient file/-c start a server instance if none is running,
445 # instead of some alternate editor logic
446 export ALTERNATE_EDITOR=""
448 # ubuntu starts gpg agent automatically with /etc/X11/Xsession.d/90gpg-agent.
449 # fedora doesn't, which left me to figure this out, and google was no help.
450 # fedora documentation is often quite bad :(
451 # This is mostly copied from that file.
452 # Main difference is that we eval the result of starting gpg-agent,
453 # while that file executes it through xsession specific var.
454 # Also make sourcing the pidfile make more sense.
455 # End result should be the same afaik.
456 # for gpg-agent to work when calling gpg from the command line,
457 # we need an environment variable that is setup via the eval.
458 # which is why we do this upon login, so it can propogate
459 # It is also written to the file $HOME/.gnupg/gpg-agent-info-$(hostname)
460 # I'm not aware if that is ever used, but just fyi.
461 # I also added the bit about xmessaging the stderr,
462 # because I'd like to know if the command fails
463 if [ -f /etc/fedora-release ]; then
464 : ${GNUPGHOME=$HOME/.gnupg}
466 GPGAGENT=/usr/bin/gpg-agent
467 PID_FILE="$GNUPGHOME/gpg-agent-info-$(hostname)"
469 if ! $GPGAGENT 2>/dev/null; then
471 eval "$($GPGAGENT --homedir /p/do-not-delete --daemon --sh --write-env-file=$PID_FILE 2>$temp)"
472 temperr="$(<"$temp")"
473 [ -n "$temperr" ] && xmessage "gpg-agent stderr: $temperr"
474 elif [ -r "$PID_FILE" ]; then
476 export GPG_AGENT_INFO
480 # ubuntu has 002, debian has 022.
481 # from what I've read, benefit of 002 makes shared groups read/write.
482 # Security concern is where some unixes put everyone in a same group,
483 # so if you copy files there with exact perms, that is probably not
484 # what you want. I don't use a system like that, and I don't really care
485 # either way, but I'd prefer
486 # being able to sync file perms with ubuntu systems at work,
487 # and it's easier to change the debian one.
495 # dunno why debian installed postfix with yum-builddep emacs
496 # but I will just explicitly install it here since
497 # I use it for sending mail in emacs.
498 if private-host
; then
499 relayhost
="[mail.messagingengine.com]:587"
501 # ses initially suggests port 25, but I had problems connecting to that.
502 relayhost
="[email-smtp.us-west-2.amazonaws.com]:587"
505 s debconf-set-selections
<<EOF
506 postfix postfix/main_mailer_type select Satellite system
507 postfix postfix/mailname string $host
508 postfix postfix/relayhost string $relayhost
514 # Settings from reading the output when installing on debian,
515 # then seeing which were different in a default install on arch.
516 # I assume the same works for fedora.
518 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
519 mailbox_size_limit = 0
520 relayhost = $relayhost
521 inet_interfaces = loopback-only
524 s systemctl
enable postfix
525 s systemctl start postfix
530 # install so it's build dependencies don't get removed.
534 makepkg
-si --noconfirm
537 pi hunspell hunspell-en
539 # to disable emacs git build,
540 # s apt-get install emacs
542 /a
/bin
/buildscripts
/emacs
544 /a
/bin
/buildscripts
/emacs
-r
548 # todo, figure this out for arch if we ever try out gnome.
550 # install for multiple display managers in case we use one
554 # fedora didn\'t have the 3.
557 s mkdir
-p $dir/PostLogin
558 s
command cp /a
/bin
/desktop-20-autostart.sh
$dir/PostLogin
/Default
559 s mkdir
/etc
/lightdm
/lightdm.conf.d
560 s
dd of
=/etc
/lightdm
/lightdm.conf.d
/12-ian.conf
<<'EOF'
562 session-setup-script=/a/bin/desktop-20-autostart.sh
567 # disable crash report annoying crap
568 s
dd of
=/etc
/default
/apport
<<<'enabled=0'
573 # todo, also note for work comp, scp opt/org-mode bin/build-scripts
575 # use the package manger version to install the cabal version
578 PATH="$PATH:$HOME/.cabal/bin"
580 # todo, on older ubuntu I used cabal xmonad + xfce,
581 # see /a/bin/old-unused/xmonad-cabal.sh
583 # trying out the distro's versions newer distros
586 # for displaying error messages.
587 # optional dependency in arch, standard elsewhere.
588 pi xorg-xmessage xmonad-contrib xorg-xsetroot xorg-xinit
590 # https://wiki.archlinux.org/index.php/Xinitrc
591 for homedir in /homme/*; do
592 cp /etc/X11/xinit/xinitrc $homedir/.xinitrc
593 sed -ri '/^ *twm\b/,$d' $homedir/.xinitrc
594 echo "source /a/bin/xinitrc" | tee -a $homedir/.xinitrc
601 if isdeb && (tp || x2); then
605 sudo chown -R traci:traci /home/traci