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