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