forked from asb/spindle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wheezy-stage3
executable file
·331 lines (299 loc) · 11.9 KB
/
wheezy-stage3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/sh
# Part of spindle http://asbradbury.org/projects/spindle
#
# See LICENSE file for copyright and license details
set -ex
WORKDIR=work
OUTDIR=out
CURIMG=stage3.qed
. ./common
set_debconf_selections() {
ssh_in_to_qemu chroot /mnt sh -l -ex - <<EOF
debconf-set-selections <<SELEOF
# System's default wordlist:
# Choices: english (Webster's Second International English wordlist), Manual symlinks setting
dictionaries-common dictionaries-common/default-wordlist select english (Webster's Second International English wordlist)
# Use Control+Alt+Backspace to terminate the X server?
keyboard-configuration keyboard-configuration/ctrl_alt_bksp boolean true
# Backend to use for TrueType handling on X:
# Choices: freetype, xtt
x-ttcidfont-conf x-ttcidfont-conf/tt_backend select freetype
# Character set to support:
# Choices: . Arabic, # Armenian, # Cyrillic - KOI8-R and KOI8-U, # Cyrillic - non-Slavic languages, # Cyrillic - Slavic languages (also Bosnian and Serbian Latin), . Ethiopic, # Georgian, # Greek, # Hebrew, # Lao, # Latin1 and Latin5 - western Europe and Turkic languages, # Latin2 - central Europe and Romanian, # Latin3 and Latin8 - Chichewa; Esperanto; Irish; Maltese and Welsh, # Latin7 - Lithuanian; Latvian; Maori and Marshallese, . Latin - Vietnamese, # Thai, . Combined - Latin; Slavic Cyrillic; Hebrew; basic Arabic, . Combined - Latin; Slavic Cyrillic; Greek, . Combined - Latin; Slavic and non-Slavic Cyrillic
console-setup console-setup/codeset47 select . Combined - Latin; Slavic Cyrillic; Greek
# Time zone:
# Choices: GMT, GMT+0, GMT+1, GMT+10, GMT+11, GMT+12, GMT+2, GMT+3, GMT+4, GMT+5, GMT+6, GMT+7, GMT+8, GMT+9, GMT-0, GMT-1, GMT-10, GMT-11, GMT-12, GMT-13, GMT-14, GMT-2, GMT-3, GMT-4, GMT-5, GMT-6, GMT-7, GMT-8, GMT-9, GMT0, Greenwich, UCT, UTC, Universal, Zulu
tzdata tzdata/Zones/Etc select UTC
# for internal use
console-setup console-setup/store_defaults_in_debconf_db boolean true
# Font for the console:
# Choices: Fixed, Terminus, TerminusBold, TerminusBoldVGA, VGA, Do not change the boot/kernel font
console-setup console-setup/fontface47 select Do not change the boot/kernel font
# Enable subpixel rendering for screen:
# Choices: Automatic, Always, Never
fontconfig-config fontconfig/subpixel_rendering select Automatic
# Method for toggling between national and Latin mode:
# Choices: Caps Lock, Right Alt (AltGr), Right Control, Right Shift, Right Logo key, Menu key, Alt+Shift, Control+Shift, Control+Alt, Alt+Caps Lock, Left Control+Left Shift, Left Alt, Left Control, Left Shift, Left Logo key, Scroll Lock key, No toggling
keyboard-configuration keyboard-configuration/toggle select No toggling
# Font size:
# Choices: 13, 14, 15, 16, 18
console-setup console-setup/fontsize-text47 select 16
# Locales to be generated:
# Choices: <SNIP>
locales locales/locales_to_be_generated multiselect en_GB.UTF-8 UTF-8
# Keyboard model:
# Choices: <SNIP>
keyboard-configuration keyboard-configuration/model select Generic 105-key (Intl) PC
# Users allowed to start the X server:
# Choices: Root Only, Console Users Only, Anybody
x11-common x11-common/xwrapper/allowed_users select Anybody
# Compose key:
# Choices: No compose key, Right Alt (AltGr), Right Control, Right Logo key, Menu key, Left Logo key, Caps Lock
keyboard-configuration keyboard-configuration/compose select No compose key
# Country of origin for the keyboard:
# Choices: <SNIP>
keyboard-configuration keyboard-configuration/layout select English (UK)
# for internal use
keyboard-configuration keyboard-configuration/layoutcode string gb
# Keymap to use:
# Choices: <SNIP>
keyboard-configuration keyboard-configuration/xkb-keymap select British English
# Choices: English (UK), English (UK) - English (UK\, Colemak), English (UK) - English (UK\, Dvorak), English (UK) - English (UK\, Dvorak with UK punctuation), English (UK) - English (UK\, extended WinKeys), English (UK) - English (UK\, international with dead keys), English (UK) - English (UK\, Macintosh), English (UK) - English (UK\, Macintosh international), Other
keyboard-configuration keyboard-configuration/variant select English (UK)
# Geographic area:
# Choices: Africa, America, Antarctica, Australia, Arctic, Asia, Atlantic, Europe, Indian, Pacific, SystemV, US, Etc
tzdata tzdata/Areas select Etc
# Method for temporarily toggling between national and Latin input:
# Choices: No temporary switch, Both Logo keys, Right Alt (AltGr), Right Logo key, Left Alt, Left Logo key
keyboard-configuration keyboard-configuration/switch select No temporary switch
# Encoding to use on the console:
# Choices: ARMSCII-8, CP1251, CP1255, CP1256, GEORGIAN-ACADEMY, GEORGIAN-PS, IBM1133, ISIRI-3342, ISO-8859-1, ISO-8859-10, ISO-8859-11, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, KOI8-R, KOI8-U, TIS-620, UTF-8, VISCII
console-setup console-setup/charmap47 select UTF-8
# Font tuning method for screen:
# Choices: Native, Autohinter, None
fontconfig-config fontconfig/hinting_type select Native
# Font size:
# Choices:
console-setup console-setup/fontsize-fb47 select 16
# The desktop environment to install when the desktop task is selected
# Choices: gnome, kde, xfce
tasksel tasksel/desktop multiselect xfce
# Key to function as AltGr:
# Choices: The default for the keyboard layout, No AltGr key, Right Alt (AltGr), Right Control, Right Logo key, Menu key, Left Alt, Left Logo key, Keypad Enter key, Both Logo keys, Both Alt keys
keyboard-configuration keyboard-configuration/altgr select The default for the keyboard layout
# Default locale for the system environment:
# Choices: None, en_GB.UTF-8
locales locales/default_environment_locale select en_GB.UTF-8
SELEOF
EOF
}
install_packages() {
# we may want to break out DEBIAN_FRONTEND=noninteractive
ssh_in_to_qemu chroot /mnt sh -l -ex - <<EOF
apt-get update
# install some utils
apt-get install -y ssh locales less fbset sudo psmisc strace module-init-tools ifplugd ed
apt-get install -y console-setup keyboard-configuration debconf-utils parted unzip
apt-get install -y build-essential python bash-completion gdb pkg-config
# For now, we can include the dev packages qt5 wants
apt-get install -y --no-install-recommends libfontconfig1-dev libicu-dev libdbus-1-dev libfreetype6-dev \
libgstreamer-plugins-base0.10-dev libudev-dev
apt-get install -y luajit lua5.1
apt-get install -y hardlink ca-certificates curl
apt-get install -y fake-hwclock ntp nfs-common usbutils
apt-get install -y --no-install-recommends cifs-utils
apt-get install -y libraspberrypi-dev libraspberrypi-doc
# Install stuff for wireless
apt-get install -y wpasupplicant wireless-tools firmware-atheros firmware-brcm80211 \
firmware-libertas firmware-ralink firmware-realtek
/etc/init.d/fake-hwclock stop # save current time
update-rc.d hwclock.sh disable
# Don't need to start these by default, wastes boot time
update-rc.d nfs-common disable
update-rc.d rpcbind disable
EOF
}
cache_keymap() {
onvm_chroot sh -l -e - <<\EOF
setupcon --force --save-only -v
/etc/init.d/fake-hwclock stop # save current time
EOF
}
add_pi_user_to_groups() {
onvm_chroot sh -l -ex - <<\EOF
groupadd -f input
for GRP in adm dialout cdrom audio users sudo video games plugdev input; do
adduser pi $GRP
done
EOF
}
make_udev_input_rule() {
onvm_chroot sh -l -e - <<EOF
printf 'SUBSYSTEM=="input", GROUP="input", MODE="0660"\n' > /etc/udev/rules.d/99-input.rules
EOF
}
remove_ssh_host_keys() {
onvm_chroot sh -l -ex - <<\EOF
rm -f /etc/ssh/ssh_host_*_key*
cat <<\RCL | tee /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
exit 0
RCL
update-rc.d ssh disable # to be re-enabled at first boot when we regenerate ssh host keys
cat <<\EOF1 > /etc/init.d/regenerate_ssh_host_keys
#!/bin/sh
### BEGIN INIT INFO
# Provides: regenerate_ssh_host_keys
# Required-Start:
# Required-Stop:
# Default-Start: 2
# Default-Stop:
# Short-Description: Regenerate ssh host keys
# Description:
### END INIT INFO
. /lib/lsb/init-functions
set -e
case "$1" in
start)
log_daemon_msg "Regenerating ssh host keys (in background)"
nohup sh -c "dpkg-reconfigure openssh-server && update-rc.d ssh enable && \
rm /etc/init.d/regenerate_ssh_host_keys && \
update-rc.d regenerate_ssh_host_keys remove && \
printf '\nfinished\n' && invoke-rc.d ssh start" > /var/log/regen_ssh_keys.log 2>&1 &
log_end_msg $?
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac
EOF1
chmod +x /etc/init.d/regenerate_ssh_host_keys
update-rc.d regenerate_ssh_host_keys start 2
EOF
}
configure_ifplugd() {
onvm_chroot sh -l -ex - <<\EOF
sed /etc/default/ifplugd -i -e 's/^INTERFACES.*/INTERFACES="auto"/'
sed /etc/default/ifplugd -i -e 's/^HOTPLUG_INTERFACES.*/HOTPLUG_INTERFACES="all"/'
EOF
}
add_opt_vc_lib_to_ld_so() {
onvm_chroot sh -l -ex - <<EOF
echo "/opt/vc/lib" > /etc/ld.so.conf.d/vmcs.conf
ldconfig
EOF
}
setup_sudoers() {
onvm_chroot sh -l -ex - <<EOF
chmod +w /etc/sudoers
echo "pi ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
chmod -w /etc/sudoers
EOF
}
# We use a swap file rather than a swap partition for greater flexibility
setup_swap() {
onvm_chroot sh -l -e - <<EOF
apt-get -y install dphys-swapfile
echo "CONF_SWAPSIZE=100" > /etc/dphys-swapfile
EOF
}
setup_console_setup() {
onvm_chroot sh -l -e - <<\EOF1
cat <<\EOF2 > /etc/default/console-setup
# CONFIGURATION FILE FOR SETUPCON
# Consult the console-setup(5) manual page.
ACTIVE_CONSOLES="/dev/tty[1-6]"
CHARMAP="UTF-8"
CODESET="guess"
FONTFACE=""
FONTSIZE=""
VIDEOMODE=
# The following is an example how to use a braille font
# FONT='lat9w-08.psf.gz brl-8x8.psf'
EOF2
EOF1
}
# Spread the word about my favourite inputrc tweak
tweak_inputrc() {
onvm_chroot sh -l -e - <<\EOF1
cat <<\EOF2 >> /etc/inputrc
# mappings for up and down arrows search history
# "\e[B": history-search-forward
# "\e[A": history-search-backward
EOF2
EOF1
}
# It's not to have the sbin dirs in $PATH as that gives us ifconfig
fiddle_default_PATH() {
# This sed match is clearly brittle and specific to the current debian
# /etc/profile
onvm_chroot sh -l -ex - <<EOF
sed /etc/profile -i -e \
's|PATH="/usr/.*games.*$|PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"|'
# need to fix ENV_PATH in /etc/login.defs
sed -i /etc/login.defs -e "s|^ENV_PATH.*|ENV_PATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games|"
EOF
}
add_qt5_apt_source() {
onvm_chroot sh -l -e <<\EOF
echo "deb http://archive.qmh-project.org/rpi-wheezy/debian/ unstable main" >> /etc/apt/sources.list.d/qt5pi.list
apt-get update
EOF
}
adjust_sysctl() {
onvm_chroot sh -l -e <<\EOF
printf "\n# rpi tweaks\nvm.swappiness=1\n" >> /etc/sysctl.conf
printf "vm.min_free_kbytes = 8192\n" >> /etc/sysctl.conf
# Only print important messages to console
sed /etc/sysctl.conf -i -e "s/\#kernel\.printk/kernel.printk/"
EOF
}
set_default_kernel_modules() {
onvm_chroot sh -e - <<EOF
printf 'snd-bcm2835\n' >> /etc/modules
EOF
}
cd $WORKDIR
dotask branch_image ../$OUTDIR/stage2.qed $CURIMG
dotask run_qemu $CURIMG
dotask mount_apt_cache
dotask disable_starting_services
dotask set_debconf_selections
dotask install_packages
dotask cache_keymap
dotask configure_ifplugd
dotask add_pi_user_to_groups
dotask make_udev_input_rule
#dotask add_opt_vc_lib_to_ld_so
dotask setup_sudoers
dotask setup_swap
dotask setup_console_setup
dotask tweak_inputrc
dotask fiddle_default_PATH
dotask save_space_using_hardlink
dotask add_qt5_apt_source
dotask adjust_sysctl
dotask allow_starting_services
dotask remove_ssh_host_keys
dotask set_default_kernel_modules
dotask update_issue
dotask fingerprint_debian
dotask shutdown_qemu
dotask finish_image