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