summaryrefslogtreecommitdiff
path: root/internet-kiosk-management/sbin/ik_create
blob: 3546228a59b46303037030cd436173320dfe419c (plain)
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
#!/bin/bash

# Copyright (C) 2012 by Debian Edu project, http://wiki.debian.org/DebianEdu
#       Mike Gabriel <mike.gabriel@das-netzwerkteam.de>

# Internet Kiosk is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Internet Kiosk is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

set -e

if echo $0 | egrep "^./bin/.*$" >/dev/null; then
    ETCDIR="etc/"
    SHAREDIR="share/"
elif echo $0 | egrep "^./ik_.*$" >/dev/null; then
    ETCDIR="../etc"
    SHAREDIR="../share/"
else
    ETCDIR=/etc/internet-kiosk
    SHAREDIR="/usr/share/internet-kiosk/"
fi

source $ETCDIR/ik_settings

IK_BASE="${IK_BASE:-/opt/internet-kiosk}"
IK_CHROOT="${IK_CHROOT:-$IK_BASE/chroot}"
IK_CONFIG="${IK_CONFIG:-$IK_BASE/etc}"
IK_DEBMIRROR_URL="${IK_DEBMIRROR_URL:-'http://ftp.debian.org/debian'}"
IK_EXTRA_DEBURL="${IK_EXTRA_DEBURL:-'deb http://packages.it-zukunft-schule.de squeeze main'}"
IK_MODULE_BLACKLIST="${IK_MODULE_BLACKLIST:-'pcspkr'}"

test -e "$IK_CHROOT" && { 
    echo "ERROR: Internet Kiosk Terminal chroot already exists at $IK_CHROOT."
    echo "Clear $IK_BASE/ and then run $(basename $0) again..."
    exit -1
}

[ "x$USER" == "xroot" ] || { 
    echo "ERROR: Internet Kiosk Diskless Terminal management scripts have to run as super-user root."
    exit -2
}

echo "Hit <RETURN> to continue with the Internet Kiosk Terminal's chroot creation using the above parameters..."
echo "Alternatively, hit STRG-C to cancel the operation now!!!"
read

export LANG=C

mkdir -p $IK_CONFIG
test -f $IK_CONFIG/ik_init || cp $SHAREDIR/ik_init $IK_CONFIG
test -f $IK_CONFIG/ik_start || cp $SHAREDIR/ik_start $IK_CONFIG

apt-get install debootstrap
mkdir -p $IK_CHROOT

# use a proxy server for APT (if any is configured)
export http_proxy="$IK_HTTP_PROXY"
export https_proxy="$IK_HTTPS_PROXY"
export ftp_proxy="$IK_FTP_PROXY"

debootstrap --arch i386 stable $IK_CHROOT/ $IK_DEBMIRROR_URL
cp /etc/resolv.conf $IK_CHROOT/etc/resolv.conf
echo "auto lo" >>   $IK_CHROOT/etc/network/interfaces
echo "iface lo inet loopback" >>   $IK_CHROOT/etc/network/interfaces
echo "localhost" > $IK_CHROOT/etc/hostname
echo "127.0.0.1 localhost" >> $IK_CHROOT/etc/hosts
cat > $IK_CHROOT/etc/fstab <<EOF
#proc	/proc			proc	defaults		0	0
none	/dev/pts		devpts	gid=5,mode=620		0	0
none	/tmp			tmpfs	size=50M,mode=1777	0	0
none	/root			tmpfs	size=100M,mode=700	0	0
none	/etc/udev/rules.d	tmpfs	size=50M		0	0
none	/var/run		tmpfs	size=50M		0	0
none	/var/log		tmpfs	size=50M		0	0
none	/var/lock		tmpfs	size=50M		0	0
none	/home			tmpfs	size=50M		0	0
none	/media			tmpfs	size=50M		0	0
none	/var/lib/nfs		tmpfs	size=50M		0	0
none	/var/lib/xkb		tmpfs	size=50M		0	0
none	/var/lib/dbus		tmpfs	size=50M		0	0
none	/var/lib/alsa		tmpfs	size=50M		0	0
EOF


cat > $IK_CHROOT/ikdt_install.sh <<EOF
#!/bin/bash

export LANG=C
mount /proc
mount /dev/pts
export HOME=/root
export http_proxy=$IK_HTTP_PROXY
export https_proxy=$IK_HTTPS_PROXY
export ftp_proxy=$IK_FTP_PROXY

mkdir -p /tmp/user/0
mkdir -p /var/lib/xkb
mkdir -p /var/lib/nfs
mkdir -p /var/lib/dbus
mkdir -p /etc/network
ln -sf /dev/shm /etc/network/run 

# disable service restarts
test -e /sbin/start-stop-daemon.keep || mv /sbin/start-stop-daemon /sbin/start-stop-daemon.keep
echo '#!/bin/sh' > /sbin/start-stop-daemon
echo 'exit 0' >> /sbin/start-stop-daemon
chmod +x /sbin/start-stop-daemon

[ \$? -eq 0 ] && test -n "$IK_EXTRA_DEBURL" && echo "$IK_EXTRA_DEBURL" > /etc/apt/sources.list.d/itzks.list
[ \$? -eq 0 ] && test -n "$IK_EXTRA_DEBURL" && apt-get update
[ \$? -eq 0 ] && test -n "$IK_EXTRA_DEBURL" && apt-get install itzks-keyring -y --force-yes
[ \$? -eq 0 ] && apt-get update
[ \$? -eq 0 ] && apt-get install $IK_SHELL -y
[ \$? -eq 0 ] && apt-get install syslinux locales -y
[ \$? -eq 0 ] && dpkg-reconfigure locales
[ \$? -eq 0 ] && apt-get install linux-image-486 -y
[ \$? -eq 0 ] && mv /vmlinuz /vmlinuz.486
[ \$? -eq 0 ] && mv /initrd.img /initrd.img.486
[ \$? -eq 0 ] && apt-get install linux-image-686 -y
[ \$? -eq 0 ] && mv /vmlinuz /vmlinuz.686
[ \$? -eq 0 ] && mv /initrd.img /initrd.img.686
[ \$? -eq 0 ] && apt-get install internet-kiosk -y

# blacklist kernel modules
[ \$? -eq 0 ] && echo && echo "# modules blacklisted on Internet Kiosk Diskless Terminals..." >> /etc/modprobe.d/blacklist.conf
[ \$? -eq 0 ] && for mod in $IK_MODULE_BLACKLIST; do echo "blacklist \$mod" >> /etc/modprobe.d/blacklist.conf; done

# Pulsaudio must come afterwards
[ \$? -eq 0 ] && apt-get install alsa-base pulseaudio -y
[ \$? -eq 0 ] && apt-get install patch -y
[ \$? -eq 0 ] && patch /etc/initramfs-tools/initramfs.conf <<PATCH
39c39
< BOOT=local
---
> BOOT=nfs
PATCH
[ \$? -eq 0 ] && rm -f /etc/udev/rules.d/*-persistent-*.rules
[ \$? -eq 0 ] && useradd internet-kiosk
[ \$? -eq 0 ] && adduser internet-kiosk audio
[ \$? -eq 0 ] && adduser internet-kiosk pulse
[ \$? -eq 0 ] && adduser pulse audio
[ \$? -eq 0 ] && update-initramfs -u -v
[ \$? -eq 0 ] && passwd -l root

# tweak mtab diversion
[ \$? -eq 0 ] && rm -f /etc/mtab
[ \$? -eq 0 ] && ln -sf /proc/mounts /etc/mtab

# restore start-stop-daemon
[ \$(stat --format '%s' /sbin/start-stop-daemon) -lt 200 ] && mv /sbin/start-stop-daemon.keep /sbin/start-stop-daemon

umount -l /proc &>/dev/null
umount -l /dev/pts &>/dev/null
EOF
chmod u+x $IK_CHROOT/ikdt_install.sh
chroot $IK_CHROOT /ikdt_install.sh

rm -f $IK_CHROOT/etc/udev/rules.d/*-persistent-*.rules

ik_update

echo "Internet Kiosk Diskless Terminal creation has finished successfully."
echo