home · contact · privacy
postinstall script: Only grab first IP from "hostname -I".
[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     cp config/systemfiles/aliases /etc/aliases
186     newaliases
187     service postfix restart
188
189     # Set up regular system update reminder.
190     apt-get -y install cron
191     su plom -c "echo '0 18 * * 0 ~/config/bin/simplemail.sh '\
192         '~/config/mails/update_reminder' | crontab -"
193
194     # Set up screen/weechat/OTR/bitlbee. Make bitlbee listen only locally.
195     apt-get -y install screen weechat-plugins python-potr bitlbee
196     sed -i 's/^# DaemonInterface/DaemonInterface = 127.0.0.1 '\
197 '# DaemonInterface/' /etc/bitlbee/bitlbee.conf
198     sedtest=`grep -E '^DaemonInterface = 127.0.0.1 #' \
199         /etc/bitlbee/bitlbee.conf | wc -l | cut -d ' ' -f 1`
200     if [ 0 -eq $sedtest ]; then
201         false
202     fi
203     cp config/systemfiles/weechat.service  /etc/systemd/system/weechat.service
204     systemctl enable /etc/systemd/system/weechat.service
205
206     # Send instructions mail.
207     config/bin/simplemail.sh config/mails/server_postinstall_finished
208
209 elif [ "$1" = "thinkpad" ]; then
210     # Set up networking (wifi!).
211     apt-get -y install firmware-iwlwifi
212     DEBIAN_FRONTEND=noninteractive apt-get -y install wicd-curses
213     sed -i 's/^wired_interface = .*$/wired_interface = eth0/g' \
214         /etc/wicd/manager-settings.conf
215     sed -i 's/^wireless_interface = .*$/wireless_interface = wlan0/g' \
216         /etc/wicd/manager-settings.conf
217     systemctl restart wicd
218
219     # Set up hibernation on lid close.
220     echo 'HandleLidSwitch=hibernate' >> /etc/systemd/logind.conf
221
222     # Set up sound.
223     usermod -aG audio plom
224     apt-get -y install alsa-utils
225     if [ "$2" = "X200s" ]; then
226         amixer -c 0 sset Master playback 100% unmute
227     elif [ "$2" = "T450s" ]; then
228         amixer -c 1 sset Master playback 100% unmute
229         # Re-order souncards so the commonly used one is the first one.
230         echo 'options snd_hda_intel index=1,0' >> /etc/modprobe.d/sound.conf
231     fi
232
233     # Set up window system, i3, redshift.
234     apt-get -y install xserver-xorg xinit xterm i3 i3status dmenu redshift
235
236     # Set up OpenGL and hardware acceleration.
237     if [ "$2" = "X200s" ]; then
238         apt-get -y install i965-va-driver
239     elif [ "$2" = "T450s" ]; then
240         apt-get -y -t jessie-backports install xserver-xorg-video-intel
241     fi
242     apt-get -y install libgl1-mesa-dri
243     usermod -aG video plom
244
245     # Install xrandr.
246     apt-get -y install x11-xserver-utils
247
248     # Set up pentadactyl. 
249     apt-get -y install iceweasel
250     apt-get -y -t jessie-backports install xul-ext-pentadactyl
251     apt-get -y install vim-gtk
252     su plom -c 'mkdir -p /home/plom/downloads/'
253
254     # Set up openssh-client.
255     apt-get -y install openssh-client
256 fi
257
258 # Set password for user.
259 passwd plom
260
261 # Clean up.
262 rm jessie_postinstall.sh
263
264 # Finalize everything with a reboot.
265 reboot