-
Notifications
You must be signed in to change notification settings - Fork 11
/
chroot_tasks.sh
234 lines (193 loc) · 5.75 KB
/
chroot_tasks.sh
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
#!/bin/sh -e
# set up variables so that config prompts are not displayed
export LC_ALL="C"
export LANGUAGE="C"
export LANG="C"
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
case `dpkg --print-architecture` in
i386)
KERNEL=linux-image-686-pae
;;
amd64)
KERNEL=linux-image-amd64
;;
*)
echo "we don't support this architecture"
exit 1
;;
esac
# install packages we need (build-essential is temporary)
apt-get -y install xserver-xorg xserver-xorg-video-all \
chromium unclutter ifplugd xinit blackbox \
ruby1.9.1-full build-essential \
vim screen git-core ntpdate openssh-server \
firmware-linux-nonfree
# and rubygems we need
#gem install bandshell
cat > /tmp/install_bandshell.sh <<EOF
#!/bin/sh -e
cd /tmp
git clone git://github.com/concerto/bandshell.git
cd bandshell
gem build bandshell.gemspec
gem install *.gem
cd /
rm -rf /tmp/bandshell
EOF
chmod +x /tmp/install_bandshell.sh
/tmp/install_bandshell.sh
# once rubygems have been installed, build-essential isn't needed
apt-get -y purge build-essential
apt-get -y autoremove
# let's get our kernel from backports... wheezy's 3.2.0 kernels don't
# seem to support (U)EFI booting very well.
cat >> /etc/apt/sources.list << 'EOF'
deb http://http.debian.net/debian wheezy-backports main
EOF
apt-get update
apt-get -y -t wheezy-backports install ${KERNEL}
# install live-boot so we get an initrd built for us
apt-get -y install live-boot live-boot-initramfs-tools
# clean up apt caches
apt-get -y clean
# set up hostname
echo concerto-player > /etc/hostname
# create a user account that, when logged in,
# will start the X server and the player
useradd -m -s `which xinit` concerto
# create a .xinitrc that will start fullscreen chromium
cat > /home/concerto/.xinitrc << "EOF"
#!/bin/sh
URL=`cat /proc/cmdline | perl -ne 'print "$1\n" if /concerto.url=(\S+)/'`
if [ -z $URL ]; then
URL=http://localhost:4567/screen
fi
# add custom xrandr commands to this file
if [ -x /lib/live/mount/medium/xrandr.sh ]; then
/lib/live/mount/medium/xrandr.sh
fi
ROTATE=`cat /proc/cmdline | perl -ne 'print "$1\n" if /concerto.rotate=(\S+)/'`
if [ -n $ROTATE ]; then
xrandr -o $ROTATE
fi
MAC_DETECT=`cat /proc/cmdline | perl -ne 'print "1\n" if /concerto.mac_detect/'`
if [ -n $MAC_DETECT ]; then
MAC=`/sbin/ifconfig eth0 | perl -ne 'print "$1\n" if /(([0-9a-f]{2}:){5}[0-9a-f]{2})/'`
URL=${URL}?mac=$MAC
fi
# start window manager
blackbox &
# hide the mouse pointer
unclutter &
# disable power-management and screen blanking
xset -dpms
xset s off
# wait until the local http server is available
until wget -q http://localhost:4567
do
sleep 2
done
# run the browser (if it crashes or dies, the X session should end)
chromium --disable-translate --disable-infobars --no-first-run --kiosk $URL
EOF
# modify inittab so we auto-login at boot as concerto
sed -i -e 's/getty 38400 tty2/getty -a concerto tty2/' /etc/inittab
# create rc.local file to start bandshell
cat > /etc/rc.local << EOF
#!/bin/sh -e
/usr/local/bin/bandshelld start
EOF
# create init script to preload bandshell network config
cat > /etc/init.d/concerto-live << "EOF"
#!/bin/sh
### BEGIN INIT INFO
# Provides: concerto-live
# Required-Start: $local_fs
# Required-Stop: $local_fs
# X-Start-Before: $network
# Default-Start: S
# Default-Stop: 0 6
# Short-Description: Live system configuration for Concerto
# Description: Live system configuration for Concerto
### END INIT INFO
. /lib/lsb/init-functions
MOUNTPOINT=/lib/live/mount/medium
MEDIUM_PATH_DIR=/etc/concerto
MEDIUM_PATH_FILE=medium_path
case "$1" in
start)
log_action_begin_msg "Configuring Concerto Player"
# try to remount boot medium as read-write
# we don't care if this fails, the bandshell code will figure it out
mount -o remount,rw,sync $MOUNTPOINT || true
# create file indicating where mountpoint is
mkdir -p $MEDIUM_PATH_DIR
echo -n $MOUNTPOINT > $MEDIUM_PATH_DIR/$MEDIUM_PATH_FILE
# generate /etc/network/interfaces from our configs
if [ -x /usr/local/bin/concerto_netsetup ]; then
/usr/local/bin/concerto_netsetup
elif [ -x /usr/local/bin/bandshelld_boot ]; then
/usr/local/bin/bandshelld_boot
else
echo "neither concerto_netsetup nor bandshelld_boot found!"
echo "something is wrong with your build process"
fi
log_action_end_msg $?
;;
stop)
;;
esac
EOF
chmod +x /etc/init.d/concerto-live
update-rc.d concerto-live defaults
# create init script to load ssh keys from boot medium
cat > /etc/init.d/ssh-keys << "EOF"
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: ssh-keys
# Required-Start: $local_fs
# Required-Stop: $local_fs
# X-Start-Before: sshd
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Load SSH keys from boot medium
### END INIT INFO
. /lib/lsb/init-functions
MOUNTPOINT=`cat /etc/concerto/medium_path`
case "$1" in
start)
log_action_begin_msg "Configuring SSH host keys"
# make sure any keys that were part of the live image are gone
rm -f /etc/ssh/ssh_host_*
if [ -f $MOUNTPOINT/ssh_keys.tar ]; then
# if keys are found stored on the boot medium, load them
# IMPORTANT NOTE: unless you are really sure you know what
# you are doing, you should NOT put an ssh_keys.tar file on
# the boot medium. Instead, let this script generate it on
# first boot. This way, a unique set of keys will be generated
# for each box.
tar -xvf $MOUNTPOINT/ssh_keys.tar -C /etc/ssh
else
# generate the necessary keys
ssh-keygen -A
# try to save keys to boot medium
# ignore errors from this in case medium isn't writable
(
cd /etc/ssh;
tar -cvf $MOUNTPOINT/ssh_keys.tar ssh_host_*
) || true
fi
log_action_end_msg $?
;;
stop)
;;
esac
EOF
chmod +x /etc/init.d/ssh-keys
insserv ssh-keys
# clean up apt package cache
apt-get clean
# set passwords for the 'root' and 'concerto' accounts.
# passwords are stored in passwords.txt
chpasswd < passwords.txt