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