-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.sh
More file actions
executable file
·383 lines (319 loc) · 14.1 KB
/
Copy pathimage.sh
File metadata and controls
executable file
·383 lines (319 loc) · 14.1 KB
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/bash
#
# Create an image which can be dd'ed onto
# a harddisk, and, after adding a boot loader
# using grub, be ready for consumption.
#
set -e
#PROXY=http://10.10.42.99:3142/
#http_proxy=http://10.10.42.99:3142/
OLDDIR=$(pwd)
DISTRONO=1604
DISTRO=xenial
ARCH=i386
MIRROR=http://archive.ubuntu.com/ubuntu/
#MIRROR=http://ca.archive.ubuntu.com/ubuntu/
if [ "$2" == "" ] ; then
ARCH=i386
else
case "$2" in
32|386|i386)
ARCH=i386 ;;
64|amd64)
ARCH=amd64 ;;
esac
fi
if [ "$ARCH" == "" ] ; then
echo "Architecture $2 unknown"
exit 254
else
echo "Building for architecture $ARCH"
fi
if [ "$1" != "" ]; then
DISTRO=$1
fi
if [ "$DISTRO" = "precise" ] ; then
DISTRONO=1204
TARGET_LTS_HES="-lts-trusty"
fi
if [ "$DISTRO" = "trusty" ] ; then
DISTRONO=1404
TARGET_LTS_HES="-lts-xenial"
fi
if [ "$DISTRO" = "xenial" ] ; then
DISTRONO=1604
TARGET_LTS_HES=""
fi
echo "Installing required packages"
apt-get -y install debootstrap dpkg-dev
echo "Creating an image for $DISTRO"
IMAGEFILE=$(tempfile -p $DISTRONO)
dd if=/dev/zero of=$IMAGEFILE count=110 bs=100MB
mkfs.ext2 -F $IMAGEFILE
TEMPDIR=$(mktemp -d $DISTRONO-dir.XXXXXXXXXX)
mount -o loop $IMAGEFILE ${TEMPDIR}
echo "Running debootstrap in the image"
#debootstrap --arch=$ARCH --include=mysql-server,rsync $DISTRO ${TEMPDIR}
http_proxy=$http_proxy debootstrap --no-check-gpg --arch=$ARCH $DISTRO ${TEMPDIR} $MIRROR
echo "Mount required directories"
# mount required directories
mount -o bind /dev ${TEMPDIR}/dev
mount -t proc none ${TEMPDIR}/proc
mount -t devpts none ${TEMPDIR}/dev/pts
mount -t sysfs none ${TEMPDIR}/sys
echo "Creating config files"
# create pluto.conf with mysqlhost set to localhost
cat <<-EOF > ${TEMPDIR}/etc/pluto.conf
MySqlHost = localhost
LTS_HES = "${TARGET_LTS_HES}"
EOF
echo "Setting hostname"
# set the hostname to dcerouter
echo dcerouter > ${TEMPDIR}/etc/hostname
echo "Setting nameserver"
# set the nameserver to Google's server, which
# should always be reachable.
echo nameserver 8.8.8.8 > ${TEMPDIR}/etc/resolv.conf
echo nameserver 8.8.8.8 > ${TEMPDIR}/etc/resolvconf/resolv.conf.d/tail
echo nameserver 8.8.8.8 > ${TEMPDIR}/etc/resolvconf/resolv.conf.d/original
LC_ALL=C chroot ${TEMPDIR} mkdir -p /var/run/network /lib/plymouth/themes
echo "Setting up sources.list"
# setup permanent apt sources
cat <<-EOF >${TEMPDIR}/etc/apt/sources.list
deb http://deb.linuxmce.org/ubuntu/ $DISTRO main
#deb http://deb.linuxmce.org/ $DISTRO main
EOF
# LOCAL MIRROR
# These sources will be added to sources.list at the end of this script
# The installation process will also wipe out these entries
cat <<-EOF >${TEMPDIR}/etc/apt/sources.list.d/ubuntu.list
deb $MIRROR $DISTRO main restricted universe multiverse
deb $MIRROR $DISTRO-updates main restricted universe multiverse
deb $MIRROR $DISTRO-backports main restricted universe multiverse
EOF
# These sources will be removed at the end of this script
cat <<-EOF >${TEMPDIR}/etc/apt/sources.list.d/fluffy.list
#deb http://10.10.42.99/${DISTRO}-${ARCH} ./
deb http://www.fluffybitch.org/builder-${DISTRO}-${ARCH}/ ./
deb http://deb.linuxmce.org/ $DISTRO main
EOF
# Copy proxy file, if it exists. This will be removed at the end of this script
echo "Enable proxy if configured on host"
if [ -f /etc/apt/apt.conf.d/02proxy ]; then
cp /etc/apt/apt.conf.d/02proxy ${TEMPDIR}/etc/apt/apt.conf.d/XXproxy
fi
echo "force-unsafe-io" > ${TEMPDIR}/etc/dpkg/dpkg.cfg.d/02apt-speedup
echo "Create preseed file"
# create preseed file
cat <<-EOF | LC_ALL=C chroot ${TEMPDIR} debconf-set-selections
debconf debconf/frontend select Noninteractive
# Choices: critical, high, medium, low
debconf debconf/priority select critical
msttcorefonts msttcorefonts/http_proxy string
msttcorefonts msttcorefonts/defoma note
msttcorefonts msttcorefonts/dlurl string
msttcorefonts msttcorefonts/savedir string
msttcorefonts msttcorefonts/baddldir note
msttcorefonts msttcorefonts/dldir string
msttcorefonts msttcorefonts/blurb note
msttcorefonts msttcorefonts/accepted-mscorefonts-eula boolean true
msttcorefonts msttcorefonts/present-mscorefonts-eula boolean false
sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true
sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true
sun-java6-jre sun-java6-jre/jcepolicy note
sun-java6-jre sun-java6-jre/stopthread boolean true
man-db man-db/install-setuid boolean false
EOF
echo "Update sources"
# Update sources and ignore error messages at apt-get for now.
LC_ALL=C chroot ${TEMPDIR} apt-get update || :
echo "Install service invocation packages sysv-rc and upstart"
# Install service invocation utilities
LC_ALL=C chroot ${TEMPDIR} apt-get -y install sysv-rc upstart screen sysvinit-utils
echo "Disable all service invocation"
# TODO: FIXME: Fix this with a couple of dpkg-diverts
# disable service invocation and tools
echo exit 101 > ${TEMPDIR}/usr/sbin/policy-rc.d
chmod +x ${TEMPDIR}/usr/sbin/policy-rc.d
chroot ${TEMPDIR} mv /usr/sbin/invoke-rc.d /usr/sbin/invoke-rc.d.orig
chroot ${TEMPDIR} mv /sbin/start /sbin/start.orig
chroot ${TEMPDIR} mv /sbin/restart /sbin/restart.orig
chroot ${TEMPDIR} mv /sbin/initctl /sbin/initctl.orig
chroot ${TEMPDIR} mv /sbin/service /sbin/service.orig || :
chroot ${TEMPDIR} mv /usr/sbin/service /usr/sbin/service.orig || :
cat <<-EOF > ${TEMPDIR}/usr/sbin/invoke-rc.d
#!/bin/bash
exit 0
EOF
chroot ${TEMPDIR} chmod +x /usr/sbin/invoke-rc.d
cat <<-EOF > ${TEMPDIR}/sbin/start
#!/bin/bash
exit 0
EOF
chroot ${TEMPDIR} chmod +x /sbin/start
chroot ${TEMPDIR} cp /sbin/start /sbin/restart
chroot ${TEMPDIR} cp /sbin/start /sbin/initctl
chroot ${TEMPDIR} cp /sbin/start /sbin/service
chroot ${TEMPDIR} cp /sbin/start /usr/sbin/service
chroot ${TEMPDIR} mv /usr/bin/screen /usr/bin/screen.orig
cat <<-EOF > ${TEMPDIR}/usr/bin/screen
#!/bin/bash
exit 0
EOF
chroot ${TEMPDIR} chmod +x /usr/bin/screen
echo "Install packages"
# install packages
LTS_HES="$TARGET_LTS_HES"
case "$DISTRONO" in
"1204") # 1204
XPKGS="xserver-xorg${LTS_HES} xserver-xorg-video-all${LTS_HES} libgl1-mesa-glx${LTS_HES}" ;;
"1404") # 1404
XPKGS="xserver-xorg-core${LTS_HES} xserver-xorg${LTS_HES} xserver-xorg-video-all${LTS_HES} xserver-xorg-input-all${LTS_HES} libwayland-egl1-mesa${LTS_HES} ubuntu-drivers-common" ;;
*) # *
XPKGS="xserver-xorg xserver-xorg-video-all ubuntu-drivers-common" ;;
esac
KPKGS="linux-generic${LTS_HES} linux-image-generic${LTS_HES} linux-headers-generic${LTS_HES}"
LC_ALL=C chroot ${TEMPDIR} apt-get install ${KPKGS} ${XPKGS} -y --allow-unauthenticated
LC_ALL=C chroot ${TEMPDIR} apt-get install mysql-server joe nano -y --allow-unauthenticated
# We make sure that the chroot knows about the current kernel version
export KVERS="`LC_ALL=C chroot ${TEMPDIR} apt-cache policy linux-image-generic${LTS_HES} | grep Installed | cut -d" " -f4-`"
echo "The image is running kernel $KVERS"
echo "Starting MySQL with --skip-networking"
LC_ALL=C chroot ${TEMPDIR} mkdir -p /var/run/mysqld
LC_ALL=C chroot ${TEMPDIR} chown -R mysql: /var/run/mysqld
chmod 755 ${TEMPDIR}/var/lib/mysql
case "$DISTRONO" in
1604)
LC_ALL=C chroot ${TEMPDIR} mysqld --skip-networking --sql-mode="NO_ENGINE_SUBSTITUTION" &
;;
*)
LC_ALL=C chroot ${TEMPDIR} mysqld --skip-networking &
;;
esac
echo "Begining LMCE Hybrid installation."
# Let the first try fail, and try it again. If the 2nd fails as well, the build will fail.
LC_ALL=C chroot ${TEMPDIR} apt-get install lmce-hybrid -y --allow-unauthenticated
LC_ALL=C chroot ${TEMPDIR} apt-get -f install
echo "Remove video-wizard-videos*.deb pkg to save space"
rm -rf ${TEMPDIR}/var/cache/apt/archives/video-wizard-videos*.deb || :
echo "Install KDE"
# Add the minimal KDE meta package, which will also install Xorg.
LC_ALL=C chroot ${TEMPDIR} apt-get install kubuntu-desktop -y --allow-unauthenticated
LC_ALL=C chroot ${TEMPDIR} apt-get install ubiquity-frontend-kde -y --allow-unauthenticated
echo "Perform a dist-upgrade"
# Ensure the image is fully upgraded
LC_ALL=C chroot ${TEMPDIR} apt-get dist-upgrade -y --allow-unauthenticated
case "$DISTRONO" in
1604) # 1604
LC_ALL=C chroot ${TEMPDIR} apt-get install syslinux isolinux -y --allow-unauthenticated ;;
esac
echo "Downgrade python so ubiquity will run"
# Downgrade python for ubiquity to run
if [[ "$DISTRONO" == "1204" ]] ; then
LC_ALL=C chroot ${TEMPDIR} apt-get install python=2.7.3-0ubuntu2 python-minimal=2.7.3-0ubuntu2 -y --force-yes --allow-unauthenticated
fi
# Additional stuff wanted by l3mce
case "$DISTRONO" in
1604) # 1604
LC_ALL=C chroot ${TEMPDIR} apt-get install casper lupin-casper laptop-detect os-prober grub2 initramfs-tools cryptsetup debconf-utils squashfs-tools ubiquity ubiquity-casper ubiquity-ubuntu-artwork ubiquity-frontend-kde user-setup memtest86+ -y --allow-unauthenticated ;;
*)
LC_ALL=C chroot ${TEMPDIR} apt-get install casper lupin-casper laptop-detect os-prober grub2 initramfs-tools cryptsetup debconf-utils squashfs-tools ubiquity ubiquity-casper ubiquity-ubuntu-artwork ubiquity-frontend-kde user-setup xresprobe memtest86+ -y --allow-unauthenticated ;;
esac
echo "Run Diskless_CreateTBZ.sh"
# Create the initial MD diskless image.
#http_proxy="$http_proxy" LC_ALL=C chroot ${TEMPDIR} /usr/pluto/bin/Diskless_CreateTBZ.sh || :
LC_ALL=C chroot ${TEMPDIR} apt-get clean
echo "Download packages to the cache so they are available on disk during install"
LC_ALL=C chroot ${TEMPDIR} apt-get install pluto-chromoflex pluto-cm11a pluto-cm15a pluto-gc100 pluto-generic-serial-device pluto-hdhomerun pluto-hvr-1600 pluto-irtrans-ethernet pluto-irtrans-wrapper pluto-libbd pluto-msiml-disp-butt pluto-plcbus pluto-usb-uirt-0038 -yd --allow-unauthenticated
# download all non-src lmce-* packages to have in deb-cache, not including anything game related cause it's too big.
LC_ALL=C chroot ${TEMPDIR} apt-get install lmce-advanced-ip-camera lmce-agocontrol-bridge lmce-airplay-plugin lmce-airplay-streamer-plugin lmce-datalog-database lmce-datalog-db lmce-datalogger-plugin lmce-dlna lmce-enocean-tcm120 lmce-hai-omni-rs232 lmce-insteon lmce-omx-plugin lmce-onewire lmce-phoenix-solo-usb lmce-rain8 lmce-roku lmce-screen-capture-camera lmce-squeezeslave lmce-transmission-client lmce-update-traversal lmce-vistaicm2 lmce-weather lmce-weather-plugin lmce-zwave-ozw -yd --allow-unauthenticated || :
# download all the video driver .deb packages that may be required for live dvd/install
[[ "$DISTRONO" == "1204" ]] && NVIDIA_DRIVER="nvidia-340"
[[ "$DISTRONO" == "1404" ]] && NVIDIA_DRIVER="nvidia-352 nvidia-340"
[[ "$DISTRONO" == "1604" ]] && NVIDIA_DRIVER="nvidia-361 nvidia-340"
LC_ALL=C chroot ${TEMPDIR} apt-get install $NVIDIA_DRIVER -yd --allow-unauthenticated || :
LC_ALL=C chroot ${TEMPDIR} apt-get install i965-va-driver -yd --allow-unauthenticated || :
LC_ALL=C chroot ${TEMPDIR} apt-get install virtualbox-guest-x11 virtualbox-guest-dkms -yd --allow-unauthenticated || :
LC_ALL=C chroot ${TEMPDIR} apt-get install firmware-linux -yd --allow-unauthenticated || :
case "$ARCH" in
"i386") # 1204
LC_ALL=C chroot ${TEMPDIR} apt-get install intel-microcode -yd --allow-unauthenticated || :
;;
"amd64") # 1404
LC_ALL=C chroot ${TEMPDIR} apt-get install amd64-microcode -yd --allow-unauthenticated || :
;;
*) # *
:
;;
esac
# begin cleanup
echo "Move & update all .debs to the appropriate deb-cache"
LC_ALL=C chroot ${TEMPDIR} /usr/pluto/bin/UpdateDebCache.sh
LC_ALL=C chroot ${TEMPDIR} apt-get clean
echo "Remove fluffy from sources"
# Remove fluffy and our providers Ubuntu mirror from the sources.list
rm -f ${TEMPDIR}/etc/apt/sources.list.d/fluffy.list
echo "Move the ubuntu sources into sources.list"
# Add ubuntu sources to the sources.list file.
cat ${TEMPDIR}/etc/apt/sources.list.d/ubuntu.list >> ${TEMPDIR}/etc/apt/sources.list
rm -f ${TEMPDIR}/etc/apt/sources.list.d/ubuntu.list
# Remove the apt proxy so it is not transferred to the image.
rm -f ${TEMPDIR}/etc/apt/apt.conf.d/XXproxy
rm -f ${TEMPDIR}/etc/dpkg/dpkg.cfg.d/02apt-speedup
echo "Update repository sources and package lists"
# Update the available repository sources
LC_ALL=C chroot ${TEMPDIR} apt-get update || :
echo "Replace all diversions"
# We now have the problem, that Pluto/LinuxMCEs startup scripts get executed WITHOUT the
# use of invoke-rc.d - instead, they use screen.
rm ${TEMPDIR}/usr/sbin/invoke-rc.d
chroot ${TEMPDIR} mv /usr/sbin/invoke-rc.d.orig /usr/sbin/invoke-rc.d
rm ${TEMPDIR}/sbin/start ${TEMPDIR}/sbin/restart ${TEMPDIR}/sbin/initctl || :
#rm ${TEMPDIR}/sbin/service ${TEMPDIR}/usr/sbin/service || :
chroot ${TEMPDIR} mv /sbin/start.orig /sbin/start
chroot ${TEMPDIR} mv /sbin/restart.orig /sbin/restart
chroot ${TEMPDIR} mv /sbin/initctl.orig /sbin/initctl
chroot ${TEMPDIR} mv /sbin/service.orig /sbin/service || :
chroot ${TEMPDIR} mv /usr/sbin/service.orig /usr/sbin/service || :
chroot ${TEMPDIR} rm /usr/sbin/policy-rc.d || :
rm ${TEMPDIR}/usr/bin/screen
chroot ${TEMPDIR} mv /usr/bin/screen.orig /usr/bin/screen
echo "Cleanup some settings and conf files"
# Get rid of existing network assignments
rm -f ${TEMPDIR}/etc/udev/rules.d/70-persistent-net-rules
# Get rid of the machine-id
rm -f ${TEMPDIR}/var/lib/dbus/machine-id
echo "Perform lsof"
PIDS=$(lsof ${TEMPDIR} 2>/dev/null | awk '{print $2}' | tail -n+2 | uniq )
until [[ -z "${PIDS}" ]] ; do
kill ${PIDS} || :
PIDS=$(lsof ${TEMPDIR} 2>/dev/null | awk '{print $2}' | tail -n+2 | uniq )
done
echo "unmount ${TEMPDIR}"
MNTS=$(mount | grep ${TEMPDIR} | awk '{print $3;}' | sort -r)
until [[ -z "${MNTS}" ]] ; do
umount ${MNTS} || :
MNTS=$(mount | grep ${TEMPDIR} | awk '{print $3;}' | sort -r)
done
#echo "Show current usgage"
## Show the current usage
#du -h --max-depth=1 ${TEMPDIR} |& grep -v "du: cannot access"
echo "remove ${TEMPDIR}"
rm -fR ${TEMPDIR}
#fsck.ext2 $IMAGEFILE
# make a backup of the old rz'd image.
#if [ -f /var/www/$DISTRONO.rz ]; then
# mv -f /var/www/$DISTRONO.rz /var/www/$DISTRONO.old.rz
#fi
#rzip -k $IMAGEFILE -o /var/www/$DISTRONO.rz
#chown www-data: /var/www/$DISTRONO.rz
#cp /var/www/$DISTRONO.rz /opt
#cp $IMAGEFILE /opt/$DISTRONO.img
echo "Move into current dir as $DISTRONO"
mv $IMAGEFILE $OLDDIR/$DISTRONO
# All finished
#pushd /var/www
#SIZE=`ls -lh $DISTRONO.rz | cut -d" " -f 5|head -1`
#wget --quiet http://vt100.at/announce.php?text=$DISTRONO.rz\ ready\ for\ l3top-size\ $SIZE -O /dev/null
#popd
exit 0