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