home · contact · privacy
Use $GOPATH/bin/ as path for htwtxt executable.
[config] / jessie_postinstall.sh
1 #!/bin/sh
2 set -x
3 set -e
4
5 if [ ! "$1" = "thinkpad" ] && [ ! "$1" = "server" ]; then
6     echo "Need argument."
7     false
8 fi
9 if [ "$1" = "thinkpad" ] && [ ! "$2" = "X200s" ] && [ ! "$2" = "T450s" ]; then
10     echo "Need Thinkpad type."
11     false
12 fi
13 if [ "$1" = "server" ] && [ ! "$2" = "personal" ] && [ ! "$2" = "public" ]; then
14     echo "Need server purpose."
15     false
16 fi
17 if [ "$2" = "personal" ] && [ ! "$3" = "test.plomlompom.com" ] && \
18     [ ! "$3" = "plomlompom.com" ]; then
19     echo "Need server domain"
20     false
21 fi
22
23 # Some important variables
24 if [ "$3" = "plomlompom.com" ]; then
25     hostname="plomlompom"
26 elif [ "$3" = "test.plomlompom.com" ]; then
27     hostname="test.plomlompom"
28 elif [ "$2" = "public" ]; then
29     hostname="twtxt.plomlompom"
30 elif [ "$2" = "X200s" ]; then
31     hostname="X220s"
32 elif [ "$2" = "T450s" ]; then
33     hostname="T450s"
34 fi
35
36 if [ "$1" = "server" ]; then
37     # Set root pw.
38     passwd
39 fi
40
41 # Post-installation reduction.
42 dpkg-query -Wf '${Package} ${Priority}\n' | grep ' required' | sed \
43     's/ required//' > list_white_unsorted 
44 echo 'ifupdown' >> list_white_unsorted 
45 echo 'isc-dhcp-client' >> list_white_unsorted
46 sort list_white_unsorted > list_white
47 dpkg-query -Wf '${Package}\n' > list_all_packages
48 sort list_all_packages > foo
49 mv foo list_all_packages
50 comm -3 list_all_packages list_white > list_black
51 apt-mark auto `cat list_black`
52 echo 'APT::AutoRemove::RecommendsImportant "false";' > /etc/apt/apt.conf.d/99mindeps
53 echo 'APT::AutoRemove::SuggestsImportant "false";' >> /etc/apt/apt.conf.d/99mindeps 
54 DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove
55 rm list_all_packages list_white_unsorted list_white list_black 
56 echo 'APT::Install-Recommends "false";' >> /etc/apt/apt.conf.d/99mindeps
57 echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf.d/99mindeps
58
59 # Set hostname and FQDN.
60 echo $hostname > /etc/hostname
61 hostname $hostname
62 if [ "$1" = "server" ]; then
63     echo '127.0.0.1 localhost' > /etc/hosts
64     ip=`hostname -I | cut -d " " -f 1`
65     echo "$ip $hostname.com $hostname" >> /etc/hosts
66
67     # Call dhclient on startup.
68     cat > /etc/systemd/system/dhclient.service << EOF
69 [Unit]
70 Description=Ethernet connection
71
72 [Service]
73 ExecStart=/sbin/dhclient eth0
74
75 [Install]
76 WantedBy=multi-user.target
77 EOF
78     systemctl enable /etc/systemd/system/dhclient.service
79 fi
80
81 # Package management config, system upgrade.
82 echo 'deb http://ftp.debian.org/debian/ jessie main contrib non-free' \
83     > /etc/apt/sources.list
84 echo 'deb http://security.debian.org/ jessie/updates main contrib non-free' \
85     >> /etc/apt/sources.list
86 echo 'deb http://ftp.debian.org/debian/ jessie-updates main contrib non-free' \
87     >> /etc/apt/sources.list
88 if [ "$1" = "thinkpad" ] || [ "$2" = "public" ]; then
89     echo 'deb http://ftp.debian.org/debian/ jessie-backports main contrib' \
90 ' non-free' >> /etc/apt/sources.list
91     echo 'deb http://ftp.debian.org/debian/ testing main contrib non-free' \
92         >> /etc/apt/sources.list
93     echo 'deb http://security.debian.org/ testing/updates main contrib' \
94 ' non-free' >> /etc/apt/sources.list
95     echo 'deb http://ftp.debian.org/debian/ testing-updates main contrib' \
96 ' non-free' >> /etc/apt/sources.list
97     echo 'APT::Default-Release "stable";' \
98         >> /etc/apt/apt.conf.d/99defaultrelease
99 fi
100 if [ "$1" = "thinkpad" ]; then
101     dhclient eth0
102 fi
103 apt-get update
104 apt-get -y dist-upgrade
105
106 # Set up manuals.
107 apt-get -y install man-db manpages less
108
109 if [ "$1" = "thinkpad" ]; then
110     # Power management as per <http://thinkwiki.de/TLP_-_Linux_Stromsparen>.
111     echo '' >> /etc/apt/sources.list
112     echo 'deb http://repo.linrunner.de/debian jessie main' \
113         >> /etc/apt/sources.list
114     apt-key adv --keyserver pool.sks-keyservers.net --recv-keys CD4E8809
115     apt-get update
116     apt-get -y install linux-headers-amd64 tlp tp-smapi-dkms
117     sed -i 's/^#START_CHARGE_THRESH_BAT0/START_CHARGE_THRESH_BAT0=10 '\
118 '#START_CHARGE_THRESH_BAT0/' /etc/default/tlp
119     sed -i 's/^#STOP_CHARGE_THRESH_BAT0/STOP_CHARGE_THRESH_BAT0=95 '\
120 '#STOP_CHARGE_THRESH_BAT0/' /etc/default/tlp
121     sed -i 's/^#DEVICES_TO_DISABLE_ON_STARTUP/DEVICES_TO_DISABLE_ON_STARTUP='\
122 '"bluetooth wifi wwan" #DEVICES_TO_DISABLE_ON_STARTUP/' /etc/default/tlp
123     tlp start
124 fi
125
126 # Don't clear boot messages on start up.
127 sed -i 's/^TTYVTDisallocate=yes$/TTYVTDisallocate=no/g' \
128     /etc/systemd/system/getty.target.wants/getty\@tty1.service
129
130 # Set up timezone.
131 echo 'Europe/Berlin' > /etc/timezone
132 cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime
133
134 # Locale config.
135 apt-get -y install locales
136 echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen
137 locale-gen
138
139 if [ "$1" = "thinkpad" ]; then
140     # Console config.
141     DEBIAN_FRONTEND=nointeractive apt-get -y install console-setup
142     echo 'ACTIVE_CONSOLES="/dev/tty[1-6]"' > /etc/default/console-setup
143     echo 'CHARMAP="UTF-8"' >> /etc/default/console-setup
144     echo 'CODESET="Lat15"' >> /etc/default/console-setup
145     echo 'FONTFACE="TerminusBold"' >> /etc/default/console-setup
146     echo 'FONTSIZE="8x16"' >> /etc/default/console-setup
147     echo 'export LC_ALL="en_US.UTF-8"' >> /etc/profile
148     sed -i 's/^XKBLAYOUT/XKBLAYOUT="de" # XKBLAYOUT/g' /etc/default/keyboard
149     service keyboard-setup restart
150 fi
151
152 # Clone git repository.
153 apt-get -y install ca-certificates
154 apt-get -y install git
155 git clone http://github.com/plomlompom/config
156 config/bin/symlink.sh
157
158 # Add user. Remove old user's config/ if it exists.
159 useradd -m -s /bin/bash plom
160 rm -rf /home/plom/config
161 su - plom -c 'git clone http://github.com/plomlompom/config /home/plom/config'
162 su plom -c '/home/plom/config/bin/symlink.sh '$1' '$2' '$3
163
164 # Allow user to sudo.
165 if [ "$1" = "thinkpad" ]; then
166     apt-get -y install sudo
167     adduser plom sudo
168 fi
169
170 # Set up editor.
171 mkdir -p .vimbackups
172 su plom -c 'mkdir -p /home/plom/.vimbackups/'
173 apt-get -y install vim
174
175 if [ "$1" = "server" ]; then
176     # Set up ssh-guard.
177     apt-get -y install sshguard rsyslog
178
179     # Set up openssh-server.
180     apt-get -y install openssh-server
181
182     # Set up mail system.
183     su plom -c 'mkdir -p /home/plom/mail/'
184     su plom -c 'mkdir -p /home/plom/mail/inbox/{cur,new,tmp}'
185     su plom -c 'mkdir -p /home/plom/mail/new_inbox/{cur,new,tmp}'
186     sed -i 's/^delete = true$/delete = false/g' \
187         /home/plom/config/dotfiles/user/server/personal/minimal/getmail/getmailrc
188     DEBIAN_FRONTEND=noninteractive apt-get -y install mutt postfix maildrop
189     cp config/systemfiles/main.cf /etc/postfix/main.cf
190     sed -i 's/HOSTNAME/'$hostname.com'/g' /etc/postfix/main.cf
191     cp config/systemfiles/aliases /etc/aliases
192     newaliases
193     service postfix restart
194     if [ "$2" = "personal" ]; then
195     apt-get -y install getmail4 procmail
196     fi
197
198     # Set up regular system update reminder.
199     apt-get -y install cron
200     su plom -c "echo '0 18 * * 0 ~/config/bin/simplemail.sh '\
201         '~/config/mails/update_reminder' | crontab -"
202
203     if [ "$2" = "personal" ]; then
204         # Set up screen/weechat/OTR/bitlbee. Make bitlbee listen only locally.
205         apt-get -y install screen weechat-plugins python-potr bitlbee
206         sed -i 's/^# DaemonInterface/DaemonInterface = 127.0.0.1 '\
207 '# DaemonInterface/' /etc/bitlbee/bitlbee.conf
208         sedtest=`grep -E '^DaemonInterface = 127.0.0.1 #' \
209             /etc/bitlbee/bitlbee.conf | wc -l | cut -d ' ' -f 1`
210         if [ 0 -eq $sedtest ]; then
211             false
212         fi
213         cp config/systemfiles/weechat.service \
214             /etc/systemd/system/weechat.service
215         systemctl enable /etc/systemd/system/weechat.service
216
217         # Send instructions mail.
218         config/bin/simplemail.sh config/mails/server_postinstall_finished
219
220     elif [ "$2" = "public" ]; then
221         # Set up twtxt environment.
222         apt-get -y install screen
223         apt-get -y -t jessie-backports install golang
224         su - plom -c 'git clone '\
225 'https://github.com/plomlompom/htwtxt $GOPATH/src/htwtxt'
226         su - plom -c 'go get htwtxt'
227         path=`su - plom -c 'echo $GOPATH/bin/htwtxt'`
228         setcap 'cap_net_bind_service=+ep' $path
229         su - plom -c 'mkdir -p ~/htwtxt'
230         cp config/systemfiles/htwtxt_restart_reminder.service \
231             /etc/systemd/system/htwtxt_restart_reminder.service
232         systemctl enable /etc/systemd/system/htwtxt_restart_reminder.service
233     fi
234
235 elif [ "$1" = "thinkpad" ]; then
236     # Set up networking (wifi!).
237     apt-get -y install firmware-iwlwifi
238     DEBIAN_FRONTEND=noninteractive apt-get -y install wicd-curses
239     sed -i 's/^wired_interface = .*$/wired_interface = eth0/g' \
240         /etc/wicd/manager-settings.conf
241     sed -i 's/^wireless_interface = .*$/wireless_interface = wlan0/g' \
242         /etc/wicd/manager-settings.conf
243     systemctl restart wicd
244
245     # Set up hibernation on lid close.
246     echo 'HandleLidSwitch=hibernate' >> /etc/systemd/logind.conf
247
248     # Set up sound.
249     usermod -aG audio plom
250     apt-get -y install alsa-utils
251     if [ "$2" = "X200s" ]; then
252         amixer -c 0 sset Master playback 100% unmute
253     elif [ "$2" = "T450s" ]; then
254         amixer -c 1 sset Master playback 100% unmute
255         # Re-order souncards so the commonly used one is the first one.
256         echo 'options snd_hda_intel index=1,0' >> /etc/modprobe.d/sound.conf
257     fi
258
259     # Set up window system, i3, redshift.
260     apt-get -y install xserver-xorg xinit xterm i3 i3status dmenu redshift
261
262     # Set up OpenGL and hardware acceleration.
263     if [ "$2" = "X200s" ]; then
264         apt-get -y install i965-va-driver
265     elif [ "$2" = "T450s" ]; then
266         apt-get -y -t jessie-backports install xserver-xorg-video-intel
267     fi
268     apt-get -y install libgl1-mesa-dri
269     usermod -aG video plom
270
271     # Install xrandr.
272     apt-get -y install x11-xserver-utils
273
274     # Set up pentadactyl. 
275     apt-get -y install iceweasel
276     apt-get -y -t jessie-backports install xul-ext-pentadactyl
277     apt-get -y install vim-gtk
278     su plom -c 'mkdir -p /home/plom/downloads/'
279
280     # Set up openssh-client.
281     apt-get -y install openssh-client
282 fi
283
284 # Set password for user.
285 passwd plom
286
287 # Clean up.
288 rm jessie_postinstall.sh
289
290 # Finalize everything with a reboot.
291 reboot