5 if [ ! "$1" = "thinkpad" ] && [ ! "$1" = "server" ]; then
9 if [ "$1" = "thinkpad" ] && [ ! "$2" = "X200s" ] && [ ! "$2" = "T450s" ]; then
10 echo "Need Thinkpad type."
13 if [ "$1" = "server" ] && [ ! "$2" = "personal" ] && [ ! "$2" = "public" ]; then
14 echo "Need server purpose."
17 if [ "$2" = "personal" ] && [ ! "$3" = "test.plomlompom.com" ] && \
18 [ ! "$3" = "plomlompom.com" ]; then
19 echo "Need server domain"
23 # Some important variables
24 if [ "$3" = "plomlompom.com" ]; then
26 elif [ "$3" = "test.plomlompom.com" ]; then
27 hostname="test.plomlompom"
28 elif [ "$2" = "public" ]; then
29 hostname="htwtxt.plomlompom"
30 elif [ "$2" = "X200s" ]; then
32 elif [ "$2" = "T450s" ]; then
36 if [ "$1" = "server" ]; then
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
59 # Set hostname and FQDN.
60 echo $hostname > /etc/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
67 # Call dhclient on startup.
68 cat > /etc/systemd/system/dhclient.service << EOF
70 Description=Ethernet connection
73 ExecStart=/sbin/dhclient eth0
76 WantedBy=multi-user.target
78 systemctl enable /etc/systemd/system/dhclient.service
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
100 if [ "$1" = "thinkpad" ]; then
104 apt-get -y dist-upgrade
107 apt-get -y install man-db manpages less
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
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/^#START_CHARGE_THRESH_BAT1/START_CHARGE_THRESH_BAT0=10 '\
122 '#START_CHARGE_THRESH_BAT1/' /etc/default/tlp
123 sed -i 's/^#STOP_CHARGE_THRESH_BAT1/STOP_CHARGE_THRESH_BAT0=95 '\
124 '#STOP_CHARGE_THRESH_BAT1/' /etc/default/tlp
125 sed -i 's/^#DEVICES_TO_DISABLE_ON_STARTUP/DEVICES_TO_DISABLE_ON_STARTUP='\
126 '"bluetooth wifi wwan" #DEVICES_TO_DISABLE_ON_STARTUP/' /etc/default/tlp
130 # Don't clear boot messages on start up.
131 sed -i 's/^TTYVTDisallocate=yes$/TTYVTDisallocate=no/g' \
132 /etc/systemd/system/getty.target.wants/getty\@tty1.service
135 echo 'Europe/Berlin' > /etc/timezone
136 cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime
139 apt-get -y install locales
140 echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen
143 if [ "$1" = "thinkpad" ]; then
145 DEBIAN_FRONTEND=nointeractive apt-get -y install console-setup
146 echo 'ACTIVE_CONSOLES="/dev/tty[1-6]"' > /etc/default/console-setup
147 echo 'CHARMAP="UTF-8"' >> /etc/default/console-setup
148 echo 'CODESET="Lat15"' >> /etc/default/console-setup
149 echo 'FONTFACE="TerminusBold"' >> /etc/default/console-setup
150 echo 'FONTSIZE="8x16"' >> /etc/default/console-setup
151 echo 'export LC_ALL="en_US.UTF-8"' >> /etc/profile
152 sed -i 's/^XKBLAYOUT/XKBLAYOUT="de" # XKBLAYOUT/g' /etc/default/keyboard
153 service keyboard-setup restart
156 # Clone git repository.
157 apt-get -y install ca-certificates
158 apt-get -y install git
159 git clone http://github.com/plomlompom/config
160 config/bin/symlink.sh
162 # Add user. Remove old user's config/ if it exists.
163 useradd -m -s /bin/bash plom
164 rm -rf /home/plom/config
165 su - plom -c 'git clone http://github.com/plomlompom/config /home/plom/config'
166 su plom -c '/home/plom/config/bin/symlink.sh '$1' '$2' '$3
168 # Allow user to sudo.
169 if [ "$1" = "thinkpad" ]; then
170 apt-get -y install sudo
176 su plom -c 'mkdir -p /home/plom/.vimbackups/'
177 apt-get -y install vim
179 if [ "$1" = "server" ]; then
181 apt-get -y install sshguard rsyslog
183 # Set up openssh-server.
184 apt-get -y install openssh-server
186 # Set up mail system.
187 su plom -c 'mkdir -p /home/plom/mail/'
188 su plom -c 'mkdir -p /home/plom/mail/inbox/{cur,new,tmp}'
189 su plom -c 'mkdir -p /home/plom/mail/new_inbox/{cur,new,tmp}'
190 sed -i 's/^delete = true$/delete = false/g' \
191 /home/plom/config/dotfiles/user/server/personal/minimal/getmail/getmailrc
192 DEBIAN_FRONTEND=noninteractive apt-get -y install mutt postfix maildrop
193 cp config/systemfiles/main.cf /etc/postfix/main.cf
194 sed -i 's/HOSTNAME/'$hostname.com'/g' /etc/postfix/main.cf
195 cp config/systemfiles/aliases /etc/aliases
197 service postfix restart
198 if [ "$2" = "personal" ]; then
199 apt-get -y install getmail4 procmail
202 # Set up regular system update reminder.
203 apt-get -y install cron
204 su plom -c "echo '0 18 * * 0 ~/config/bin/simplemail.sh '\
205 '~/config/mails/update_reminder' | crontab -"
207 if [ "$2" = "personal" ]; then
208 # Set up screen/weechat/OTR/bitlbee. Make bitlbee listen only locally.
209 apt-get -y install screen weechat-plugins python-potr bitlbee
210 sed -i 's/^# DaemonInterface/DaemonInterface = 127.0.0.1 '\
211 '# DaemonInterface/' /etc/bitlbee/bitlbee.conf
212 sedtest=`grep -E '^DaemonInterface = 127.0.0.1 #' \
213 /etc/bitlbee/bitlbee.conf | wc -l | cut -d ' ' -f 1`
214 if [ 0 -eq $sedtest ]; then
217 cp config/systemfiles/weechat.service \
218 /etc/systemd/system/weechat.service
219 systemctl enable /etc/systemd/system/weechat.service
221 # Send instructions mail.
222 config/bin/simplemail.sh config/mails/server_postinstall_finished
224 elif [ "$2" = "public" ]; then
226 # Set up htwtxt and environment.
227 apt-get -y install screen
228 apt-get -y -t jessie-backports install golang
229 su - plom -c 'git clone https://github.com/plomlompom/htwtxt $GOPATH/src/htwtxt'
230 su - plom -c 'go get htwtxt'
231 path=`su - plom -c 'echo $GOPATH/bin/htwtxt'`
232 su - plom -c 'mkdir -p ~/htwtxt'
233 cp config/systemfiles/htwtxt_restart_reminder.service \
234 /etc/systemd/system/htwtxt_restart_reminder.service
235 systemctl enable /etc/systemd/system/htwtxt_restart_reminder.service
237 # Set up nginx and letsencrypt.
238 apt-get -y install nginx
239 cp config/systemfiles/nginx.conf /etc/nginx/nginx.conf
241 git clone https://github.com/letsencrypt/letsencrypt
242 echo '0 18 * * 0 ~/config/bin/renew_certs.sh' | crontab -
245 apt-get -y install python3 python3-venv python3-pip
246 su - plom -c 'cd && git clone http://github.com/plomlompom/plomlombot-irc'
247 su - plom -c 'mkdir -p ~/plomlombot_db'
248 cp config/systemfiles/plomlombot.service \
249 /etc/systemd/system/plomlombot.service
250 systemctl enable /etc/systemd/system/plomlombot.service
252 # Set up plomlombot logging infrastructure.
253 mkdir -p /var/www/html/irclogs/
254 ln -s /home/plom/plomlombot_db/6f322d574618816aa2d6d1ceb4fd2551/3c0248e76a1de3a6ee5bf3421f7379b0/logs/ /var/www/html/irclogs/zrolaps
255 touch /var/www/password_irclogs_zrolaps
256 ln -s /home/plom/plomlombot_db/6f322d574618816aa2d6d1ceb4fd2551/657eea42f86866f2954d39f92a6c71ff/logs/ /var/www/html/irclogs/nodrama.de
257 touch /var/www/password_irclogs_nodrama_de
258 ln -s /home/plom/plomlombot_db/6f322d574618816aa2d6d1ceb4fd2551/a083c5d5efca3734294fa656692990b6/logs/ /var/www/html/irclogs/freakazoid
259 touch /var/www/password_irclogs_freakazoid
261 # Set up other web-served directories.
262 su - plom -c 'mkdir -p /home/plom/dump'
263 ln -s /home/plom/dump/ /var/www/html/dump
264 su - plom -c 'mkdir -p /home/plom/geheim'
265 ln -s /home/plom/geheim/ /var/www/html/geheim
266 su - plom -c 'mkdir -p /home/plom/lesekreis'
267 ln -s /home/plom/geheim/ /var/www/html/lesekreis
268 su - plom -c 'mkdir -p /home/plom/zettel'
269 ln -s /home/plom/zettel/ /var/www/html/zettel
270 su - plom -c 'git init --bare /home/plom/zettel.git'
271 su - plom -c 'cp ~/config/systemfiles/post-update ~/zettel.git/hooks/'
272 su - plom -c 'chmod a+x /home/plom/zettel.git/hooks/post-update'
274 # Install website generator tools
275 apt-get -y install pandoc wget
276 wget http://news.dieweltistgarnichtso.net/bin/archives/redo-sh.tar.gz
277 tar -oxzf redo-sh.tar.gz -C /usr/local
279 apt-get --purge autoremove wget
282 elif [ "$1" = "thinkpad" ]; then
283 # Set up networking (wifi!).
284 apt-get -y install firmware-iwlwifi
285 DEBIAN_FRONTEND=noninteractive apt-get -y install wicd-curses
286 sed -i 's/^wired_interface = .*$/wired_interface = eth0/g' \
287 /etc/wicd/manager-settings.conf
288 sed -i 's/^wireless_interface = .*$/wireless_interface = wlan0/g' \
289 /etc/wicd/manager-settings.conf
290 systemctl restart wicd
292 # Set up hibernation on lid close.
293 echo 'HandleLidSwitch=hibernate' >> /etc/systemd/logind.conf
296 usermod -aG audio plom
297 apt-get -y install alsa-utils
298 if [ "$2" = "X200s" ]; then
299 amixer -c 0 sset Master playback 100% unmute
300 elif [ "$2" = "T450s" ]; then
301 amixer -c 1 sset Master playback 100% unmute
302 # Re-order souncards so the commonly used one is the first one.
303 echo 'options snd_hda_intel index=1,0' >> /etc/modprobe.d/sound.conf
306 # Set up window system, i3, redshift.
307 apt-get -y install xserver-xorg xinit xterm i3 i3status dmenu redshift
309 # Set up OpenGL and hardware acceleration.
310 if [ "$2" = "X200s" ]; then
311 apt-get -y install i965-va-driver
312 elif [ "$2" = "T450s" ]; then
313 apt-get -y -t jessie-backports install xserver-xorg-video-intel
315 apt-get -y install libgl1-mesa-dri
316 usermod -aG video plom
319 apt-get -y install x11-xserver-utils
321 # Set up pentadactyl.
322 apt-get -y install iceweasel
323 apt-get -y -t jessie-backports install xul-ext-pentadactyl
324 apt-get -y install vim-gtk
325 su plom -c 'mkdir -p /home/plom/downloads/'
327 # Set up openssh-client.
328 apt-get -y install openssh-client
331 # Set password for user.
335 rm jessie_postinstall.sh
337 # Finalize everything with a reboot.
338 echo "You may reboot now with the 'reboot' command unless there's more to do."