2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
6 # for bootstrapping a new machine
8 # to make ssh run better, first run this:
9 sudo bash
-c 'source /a/c/repos/bash/.bashrc && source /a/bin/ssh-emacs-setup'
12 # see t.org for OS installer notes
14 # usage: $0 [OPTIONS] HOSTNAME
17 # run any sudo command first so your pass is cached
18 # set the scrollback to unlimited in case something goes wrong
20 if [[ $EUID == 0 ]]; then
21 echo "error: do not run as root"
25 interactive
=true
# set this to true if running by hand in emacs
26 [[ $
- == *i
* ]] || interactive
=false
30 if ! $interactive; then
35 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
37 # headless=false # unused atm
39 # for copying to a new data fs
40 bootstrapfs
=false
# old flag, needs new look before using.
41 while [[ $1 == -* ]]; do
43 # avoid some of the longer compilation steps,
44 # when we need to rerun because we had an error
45 -n) recompile
=false
; shift ;;
55 for f
in iank-dev htpc treetowl x2 frodo tp
; do
56 eval "$f() { [[ $host == $f ]]; }"
58 has_p
() { iank-dev || x2 || frodo
; }
59 encrypted
() { has_p || tp
; }
62 export GLOBIGNORE
=*/.
:*/..
66 ####### end command line parsing
70 # I tried making a service which was dependent on reboot.target,
71 # but it happened too late in the shutdown process.
72 sudo
dd of
=/etc
/systemd
/system
/keyscripton.service
<<'EOF'
74 Description=Turn on automatic decryption of drives on boot
75 After=multi-user.target
81 ExecStop=/a/bin/keyscript-on
84 WantedBy=multi-user.target
86 sudo systemctl start keyscripton.service
87 sudo systemctl
enable keyscripton.service
89 sudo
dd of
=/etc
/systemd
/system
/keyscriptoff.service
<<'EOF'
91 Description=Turn off automatic decryption of drives on boot
95 ExecStart=/a/bin/keyscript-off
98 WantedBy=multi-user.target
100 sudo systemctl
enable keyscriptoff.service
101 sudo systemctl start keyscriptoff.service
105 desktop
=$
(ssh root@iankelling.org
grep desktop
/etc
/hosts |
grep -o "^.* ")
106 if $bootstrapfs; then
107 # for bootstrapping at a new job:
109 # for moving to a new hd, change $cp to move between filesystems
113 $cp/a
/c
/bin
/{bash-programs-by-ian
,distro-begin
,distro-functions
,input-setup.sh
} /a
/bin
114 echo -e \\n
\\n
\\n | ssh-keygen
-t rsa
118 # this script has been designed to be idempotent
119 # todo, it would be nice to cut down on some of the output
122 # output is below so shellcheck can verify sources
123 for x
in /a
/bin
/bash-programs-by-ian
/repos
/{errhandle
,tee-unique
,lnf
}/*-function; do
124 echo "# shellcheck source=$x";
125 # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/bash-trace-function
126 # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errallow-function
127 # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errcatch-function
128 # shellcheck source=/a/bin/bash-programs-by-ian/repos/errhandle/errexit-function
129 # shellcheck source=/a/bin/bash-programs-by-ian/repos/tee-unique/teeu-function
130 # shellcheck source=/a/bin/bash-programs-by-ian/repos/lnf/lnf-function
136 $interactive || errcatch
137 source /a
/bin
/distro-functions
/src
/identify-distros
143 # comment out line disallowing calling sudo in scripts
144 sudo
sed -i 's/^Defaults *requiretty/#\0 # ian commented/' /etc
/sudoers
145 # turn on magic sysrq commands for this boot cycle
146 echo 1 > sudo
dd of
=/proc
/sys
/kernel
/sysrq
147 # selinux is not user friendly. Like, you enable samba, but you haven't run the magic selinux commands so it doesn't work
148 # and you have no idea why.
149 sudo
sed -i 's/^\(SELINUX=\).*/\1disabled/' /etc
/selinux
/config
150 selinuxenabled
&& sudo setenforce
0
161 for x
in /a
/c
/repos
/bash
/!(.git
); do
164 source /a/bin/bash-programs-by-ian/repos/lnf/lnf-function
175 $interactive || errcatch
176 $interactive ||
set -x
180 tu
/etc
/sudoers
<<'EOF'
181 ian ALL=(ALL) NOPASSWD: ALL
182 Defaults env_keep += SUDOD
186 # enable magic sysrq keys. debian docs say it is already enabled by default
187 isfedora
&& tu
/etc
/sysctl.conf
'kernel.sysrq = 1'
192 # add contrib non-free to sources for main
193 s
sed -i 's/^\(deb.* main\).*/\1 contrib non-free/' /etc
/apt
/sources.list.d
/*
195 # non-existent var, as Im not planning to use stable right now
196 if isdebian-stable
; then
197 code
=$
(debian-codename
)
198 s
dd of
=/etc
/apt
/sources.list.d
/mozilla-iceweasel.list
<<EOF
199 deb http://mozilla.debian.net/ $code-backports firefox-release
200 deb-src http://mozilla.debian.net/ $code-backports firefox-release
203 # we change the mirror from the default, so we cant use tu
204 s
dd of
=/etc
/apt
/sources.list.d
/main-backports.list
<<EOF
205 deb http://http.debian.net/debian $code-backports main contrib non-free
206 deb-src http://http.debian.net/debian $code-backports main contrib non-free
210 # take care of mozilla signing errors in previous command
211 pi pkg-mozilla-archive-keyring
214 # this would change stable to testing, but I set that up already.
215 # It\'s just a no-op if its already testing.
216 # sudo sed -ri 's!^( *[^ #]+ +[^ ]+ +)[[:alpha:]]+(.*)!\1testing\2!' /etc/apt/sources.list
222 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
223 sudo pacman
-S --noconfirm --needed base-devel jq
224 # pacaur seems to be the best, although it + cower has a few minor bugs,
225 # its design goals seem good, so, going for it.
232 makepkg
-sri --skippgpcheck --noconfirm
239 # this creates ~/.gnupg. addgnupghome is broken on arch.
241 # for aur, automatically dl & add gpg keys.
242 # Just the keyserver-options line goes in dirmngr.conf once
243 # this bug is fixed: https://bugs.gnupg.org/gnupg/issue2147
244 teeu ~
/.gnupg
/gpg.conf
<<EOF
245 $(grep -o '^ *keyserver .*' ~/.gnupg/dirmngr.conf)
246 keyserver-options auto-key-retrieve
249 x
=$
(mktemp
); pacman.conf-insert_pacserve
>$x
250 sudo
dd of
=/etc
/pacman.conf
if=$x; rm $x
251 sudo systemctl
enable pacserve.service
252 sudo systemctl start pacserve.service
254 # strange error if just installing trash-cli: "pyalpm requires python",
255 # so I see that it requires python2, and installing that manually fixes it.
256 # I didn't see this on earlier installation, main thing which changed was
257 # pacserve, so not sure if it's related.
265 ###### link files ###########
266 # convenient to just do all file linking in one place
271 # if it wasn't set already, we could set hostname here
272 #echo treetowl | s dd of=/etc/hostname
273 #s hostname -F /etc/hostname
274 #HOSTNAME=$(hostname)
276 #########################################
277 # NOTE: only /a needs to be mounted for creating links!
278 ###########################################
280 # todo: reconcile ~/.ssh/config work/home
283 lnf
-T /p
/offlineimap ~
/Maildir
284 lnf
-T /p
/News ~
/News
285 # don't use /* because I don't want to require it to be mounted
286 s lnf
/q
/root
/.editor-backups
/q
/root
/.undo-tree-history \
287 /q
/root
/.
ssh /a
/opt \
288 /a
/c
/.emacs.d ~
/.unison
/root
292 s lnf
/a
/c
/.inputrc
/a
/c
/.vim
/a
/c
/.vimrc
/a
/c
/.gvimrc
/root
294 if [[ $HOSTNAME == htpc
]]; then
295 lnf
-T /i
/Videos ~
/Downloads
300 lnf
-T /i
/mboxes ~
/mail
304 # basic needed packages
305 case $
(distro-name
) in
307 pi firefox$
( isdebian-stable
&& e
/$code-backports )
308 # for hosts which require nonfree drivers
311 *) pi linux-image-amd64 firmware-linux-nonfree \
312 firmware-linux-free linux-headers-amd64
317 pi xmacro gtk-redshift xinput
320 p
-y groupinstall development-tools c-development books admin-tools
322 # debian has this package patched to work, upstream is dead
323 # tried using alien, pi alien, alien -r *.deb, rpm -Uhv *.rpm, got this error, so fuck it
324 # 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
325 # http://packages.debian.org/source/sid/xmacro
326 pi
patch libXtst-devel wget man-pages
# what is the ubuntu equivalent to man-pages?
328 wget http
://ftp.de.debian.org
/debian
/pool
/main
/x
/xmacro
/xmacro_0.3pre-20000911.orig.
tar.gz
329 wget http
://ftp.de.debian.org
/debian
/pool
/main
/x
/xmacro
/xmacro_0.3pre-20000911-6.
diff.gz
331 patch -p0 < xmacro_0.3pre-20000911-6.
diff
332 cd xmacro-0.3pre-20000911.orig
334 sleep 1 # not sure why the following command couldn\'t find, so trying this
335 # no make install target
336 s
cp -f xmacroplay xmacrorec xmacrorec2
/usr
/local
/bin
339 # libxtst is missing dep https://aur.archlinux.org/packages/xmacro/#news
340 pi xorg-server redshift xorg-xinput pkgfile libxtst xmacro
346 pi xbindkeys xkbset cryptsetup
349 # enables trim for volume delete, other rare commands.
350 sudo
sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc
/lvm
/lvm.conf
354 sudo
cp /usr
/share
/doc
/util-linux
/examples
/fstrim.
{service
,timer
} /etc
/systemd
/system
357 sudo systemctl
enable fstrim.timer
361 # relatime is default, but it still significantly increases writes
362 # in comparison because it writes on the first read after each
365 dirs=(/i
/mnt
/{1,2,3,4,5,6,7,8,9})
369 s mkdir
-p "${dirs[@]}"
370 s chown ian
:ian
"${dirs[@]}"
371 # ssh and probably some other things care about parent directory
372 # ownership, and ssh doesn\'t allow any group writable parent
373 # directories, so we are forced to use a directory structure similar
374 # to home directories
385 # work desktop doesnt need gpg stuff, but it doesnt hurt
386 s
dd of
=/etc
/profile.d
/environment.sh
<<'EOF'
387 # IAN: EDIT THIS FROM /a/bin/distro-begin
389 if [ -f $HOME/path_add-function ]; then
390 . $HOME/path_add-function
391 path_add /usr/sbin /usr/local/sbin /sbin
392 path_add /a/bin /a/opt/bin $HOME/.cabal/bin
394 if [ -r /etc/alternatives/java_sdk ]; then
395 export JAVA_HOME=/etc/alternatives/java_sdk
396 path_add /etc/alternatives/java_sdk
400 export EDITOR="emacsclient"
401 # this makes emacsclient file/-c start a server instance if none is running,
402 # instead of some alternate editor logic
403 export ALTERNATE_EDITOR=""
405 # ubuntu starts gpg agent automatically with /etc/X11/Xsession.d/90gpg-agent.
406 # fedora doesn't, which left me to figure this out, and google was no help.
407 # fedora documentation is often quite bad :(
408 # This is mostly copied from that file.
409 # Main difference is that we eval the result of starting gpg-agent,
410 # while that file executes it through xsession specific var.
411 # Also make sourcing the pidfile make more sense.
412 # End result should be the same afaik.
413 # for gpg-agent to work when calling gpg from the command line,
414 # we need an environment variable that is setup via the eval.
415 # which is why we do this upon login, so it can propogate
416 # It is also written to the file $HOME/.gnupg/gpg-agent-info-$(hostname)
417 # I'm not aware if that is ever used, but just fyi.
418 # I also added the bit about xmessaging the stderr,
419 # because I'd like to know if the command fails
420 if [ -f /etc/fedora-release ]; then
421 : ${GNUPGHOME=$HOME/.gnupg}
423 GPGAGENT=/usr/bin/gpg-agent
424 PID_FILE="$GNUPGHOME/gpg-agent-info-$(hostname)"
426 if ! $GPGAGENT 2>/dev/null; then
428 eval "$($GPGAGENT --homedir /p/do-not-delete --daemon --sh --write-env-file=$PID_FILE 2>$temp)"
429 temperr="$(<"$temp")"
430 [ -n "$temperr" ] && xmessage "gpg-agent stderr: $temperr"
431 elif [ -r "$PID_FILE" ]; then
433 export GPG_AGENT_INFO
437 # ubuntu has 002, debian has 022.
438 # from what I've read, benefit of 002 makes shared groups read/write.
439 # Security concern is where some unixes put everyone in a same group,
440 # so if you copy files there with exact perms, that is probably not
441 # what you want. I don't use a system like that, and I don't really care
442 # either way, but I'd prefer
443 # being able to sync file perms with ubuntu systems at work,
444 # and it's easier to change the debian one.
452 # dunno why debian installed postfix with yum-builddep emacs
453 # but I will just explicitly install it here since
454 # I use it for sending mail in emacs.
455 if private-host
; then
456 relayhost
="[mail.messagingengine.com]:587"
458 # ses initially suggests port 25, but I had problems connecting to that.
459 relayhost
="[email-smtp.us-west-2.amazonaws.com]:587"
462 s debconf-set-selections
<<EOF
463 postfix postfix/main_mailer_type select Satellite system
464 postfix postfix/mailname string $host
465 postfix postfix/relayhost string $relayhost
471 # Settings from reading the output when installing on debian,
472 # then seeing which were different in a default install on arch.
473 # I assume the same works for fedora.
475 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
476 mailbox_size_limit = 0
477 relayhost = $relayhost
478 inet_interfaces = loopback-only
481 s systemctl
enable postfix
482 s systemctl start postfix
487 # install so it's build dependencies don't get removed.
491 makepkg
-si --noconfirm
494 pi hunspell hunspell-en
496 # to disable emacs git build,
497 # s apt-get install emacs
499 /a
/bin
/buildscripts
/emacs
501 /a
/bin
/buildscripts
/emacs
-r
505 # todo, figure this out for arch if we ever try out gnome.
507 # install for multiple display managers in case we use one
511 # fedora didn\'t have the 3.
514 s mkdir
-p $dir/PostLogin
515 s
command cp /a
/bin
/desktop-20-autostart.sh
$dir/PostLogin
/Default
516 s mkdir
/etc
/lightdm
/lightdm.conf.d
517 s
dd of
=/etc
/lightdm
/lightdm.conf.d
/12-ian.conf
<<'EOF'
519 session-setup-script=/a/bin/desktop-20-autostart.sh
524 # disable crash report annoying crap
525 s
dd of
=/etc
/default
/apport
<<<'enabled=0'
530 # todo, also note for work comp, scp opt/org-mode bin/build-scripts
532 # use the package manger version to install the cabal version
535 PATH="$PATH:$HOME/.cabal/bin"
537 # todo, on older ubuntu I used cabal xmonad + xfce,
538 # see /a/bin/old-unused/xmonad-cabal.sh
540 # trying out the distro's versions newer distros
543 # for displaying error messages.
544 # optional dependency in arch, standard elsewhere.
545 pi xorg-xmessage xmonad-contrib xorg-xsetroot xorg-xinit
547 # https://wiki.archlinux.org/index.php/Xinitrc
548 cp /etc/X11/xinit/xinitrc ~/.xinitrc
549 sed -ri '/^ *twm\b/,$d' ~/.xinitrc
550 echo "source /a/bin/xinitrc" >> ~/.xinitrc
556 if isdeb && (tp || x2); then