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
|
#!/bin/bash
##
## makedistro.sh
##
## Made by David Farning
## Login <dfarning@acer>
##
## Started on Sat Jan 9 03:45:30 2010 David Farning
## Last update Thu Jan 14 06:04:12 2010 David Farning
##
set -eu
function usage()
{
echo "The script needs 2 parameters:
* Action to do: debootstrap|iso|squash|all
* Architecture to build: i386|amd64
Usage: $0 debootstrap|iso|squash|source|all|torrent i386|amd64"
}
function failure()
{
unmount_directories
echo "$@"
exit 2
}
function unmount_directory()
{
DIR_TO_UNMOUNT="$1"
if mountpoint -q ${DIR_TO_UNMOUNT}; then #FIXME should be able to detect in tmp is mounted
echo "Unmounting directory ${DIR_TO_UNMOUNT}..."
umount -l ${DIR_TO_UNMOUNT} || failure "Cannot unmount directory ${DIR_TO_UNMOUNT}, error=$?"
fi
}
function unmount_directories()
{
# check for runs of the script
if [ -d ${CHROOT} ] ; then
echo "Cleaning up old build tree"
for MOUNT in /tmp /lib/modules/*/volatile /proc /sys /dev/pts /var/run ; do
unmount_directory ${CHROOT}${MOUNT}
done
fi
}
function replace_ssd()
{
# replace the start-stop-daemon, to make /etc/init.d/ scripts do nothing for a while
mv ${CHROOT}/sbin/start-stop-daemon ${CHROOT}/sbin/start-stop-daemon.REAL
cat <<EOF > "$CHROOT/sbin/start-stop-daemon"
#!/bin/sh
echo
echo "Warning: Fake start-stop-daemon called, doing nothing"
EOF
chmod 755 ${CHROOT}/sbin/start-stop-daemon
}
function restore_ssd()
{
# enable /etc/init.d/ scripts
mv ${CHROOT}/sbin/start-stop-daemon.REAL ${CHROOT}/sbin/start-stop-daemon
}
function prepare_chroot()
{
export LANG=C
export LANGUAGE=C
mount -t proc proc ${CHROOT}/proc || failure "Failed to mount ${CHROOT}/proc, error=$?"
mount -t sysfs sysfs ${CHROOT}/sys || failure "Failed to mount ${CHROOT}/sys, error=$?"
mount -t devpts none ${CHROOT}/dev/pts || failure "Failed to mount ${CHROOT}/dev/pts, error=$?"
mount -o bind /var/run ${CHROOT}/var/run
#mount -o bind /tmp ${CHROOT}/tmp FIXME do we need temp
echo "Copying resolv.conf..."
cp -f /etc/resolv.conf ${CHROOT}/etc/resolv.conf || failure "Failed to copy resolv.conf to image directory, error=$?"
echo "Creating DBUS uuid"
#${CCMD} dbus-uuidgen --ensure
echo "done"
}
function in_chroot()
{
cp usr-chroot.sh ${CHROOT}
${CCMD} /usr-chroot.sh
}
function clean_chroot()
{
unmount_directories
echo "Cleaning up apt"
${CCMD} apt-get clean || failure "Failed to run apt-get clean, error=$?"
${CCMD} apt-get autoclean || failure "Failed to run apt-get autoclean, error=$?"
echo "Cleaning up temporary directories..."
${CCMD} rm -rf '/tmp/*' '/tmp/.*' '/var/tmp/*' '/var/tmp/.*' #2>/dev/null
${CCMD} rm -rf /var/lib/dbus/machine-id # 2>/dev/null
echo "Restoring hosts..."
${CCMD} rm -f ${CHROOT}/etc/hosts || failure "Failed to hosts, error=$?"
echo "Restoring resolv.conf..."
${CCMD} rm -f ${CHROOT}/etc/resolv.conf || failure "Failed to remove resolv.conf, error=$?"
}
function do_debootstrap() {
date
echo "DIST=${DIST}
ARCH=${ARCH}
CHROOT=${CHROOT}"
unmount_directories
rm -rf $CHROOT || exit 1
# debootstrab the base system
mkdir ${CHROOT}
debootstrap --arch=${ARCH} lucid ${CHROOT} ${MIRROR}
# replace_ssd
prepare_chroot
in_chroot
cp casper $CHROOT/etc/init.d/casper
# ${CCMD} update-usbids.sh
# ${CCMD} update-pciids
${CCMD} update-initramfs -uv
clean_chroot
# restore_ssd
}
function prepare_image_directory()
{
echo "Preparing directory for image"
if [ -e ${IMAGE} ]; then
rm -rf ${IMAGE} || failure "Failed to remove directory ${IMAGE}"
fi
mkdir -p ${IMAGE}
}
pack_squashfs()
{
prepare_image_directory
cp -a USR-master/* ${IMAGE}/
echo "Updating files lists..."
${CCMD} dpkg-query -W --showformat='${Package} ${Version}\n' > ${IMAGE}/casper/filesystem.manifest || failure "Cannot update filesystem.manifest, error=$?"
cp ${IMAGE}/casper/filesystem.manifest ${IMAGE}/casper/filesystem.manifest-desktop
sed -i '/ubiquity/d' ${IMAGE}/casper/filesystem.manifest-desktop
sed -i '/casper/d' ${IMAGE}/casper/filesystem.manifest-desktop
echo "Packing SquashFS image..."
if [ -e ${IMAGE}/casper/filesystem.squashfs ]; then
rm -f ${IMAGE}/casper/filesystem.squashfs || failure "Cannot remove ${IMAGE}/casper/filesystem.squashfs to make room for created squashfs image, error=$?"
fi
mksquashfs ${CHROOT} ${IMAGE}/casper/filesystem.squashfs || failure "Failed to create squashfs image to ${IMAGE}/casper/filesystem.squashfs, error=$?"
chmod 644 ${IMAGE}/casper/filesystem.squashfs
}
pack_iso(){
#update the kernel image in the master dir
cp -v ${CHROOT}/boot/initrd.img* ${IMAGE}/casper/initrd
cp -v ${CHROOT}/boot/vmlinuz* ${IMAGE}/casper/vmlinuz
echo "Updating md5sums..."
pushd ${CHROOT}
#rm md5sum.txt
# find . -type f | grep -v boot.cat | grep -v md5sum.txt | grep -v isolinux.bin | grep -v pdf$ | grep -v md5sum | xargs md5sum >> md5sum.txt
popd
LIVECD_ISO_DESCRIPTION="Ubuntu Sugar Remix LiveCD"
echo "ISO description set to: ${LIVECD_ISO_DESCRIPTION}"
if [ ${ARCH} = "x86_64" ]; then
echo "#FIXME this has not been tested"
# mkisofs -o "$NEW_FILES_DIR/$NEW_ISO_FILE_NAME" \
# -b "isolinux/isolinux.bin" -c "isolinux/boot.cat" \
# -p "Ubuntu Customization Kit - http://uck.sf.net" \
# -no-emul-boot -V "$LIVECD_ISO_DESCRIPTION" -r -J -l \
# -x "$ISO_REMASTER_DIR"/casper/manifest.diff \
# $MKISOFS_EXTRA_OPTIONS \
# "$ISO_REMASTER_DIR"
else
mkisofs -o ${ISO} \
-b "isolinux/isolinux.bin" -c "isolinux/boot.cat" \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-cache-inodes -r -J -l \
${IMAGE}
fi
RESULT=$?
if [ $RESULT -ne 0 ]; then
failure "Failed to pack ISO image, error=${RESULT}"
fi
#NAME=${DIST}_${VERSION}_$ARCH
#[ $ARCH = "i386" ] && NAME=${DIST}_${VERSION}_i686
#mkisofs -D -r -V "${NAME}" -cache-inodes -J -l -b isolinux/isolinux.bin \
# -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
# -o iso/${NAME}.iso $DIST-master
}
case $1 in
debootstrap|iso|squash|source|all|torrent) ACTION=$1
;;
*) usage
exit 1
;;
esac
case $2 in
i386|amd64) ARCH=$2
;;
*) usage
exit 1
;;
esac
export DEBIAN_FRONTEND=noninteractive
MIRROR="http://10.0.02:3142/archive.ubuntu.com/ubuntu"
DIST="USR"
CHROOT=${DIST}-${ARCH}-FS
IMAGE=${DIST}-${ARCH}-IMAGE
ISO=${DIST}-${ARCH}.iso
LOG=${CHROOT}.log
CCMD="chroot ${CHROOT}"
echo ${CCMD}
do_debootstrap
pack_squashfs
pack_iso
###################################################################################
#case $ACTION in
#debootstrap) COLUMNS=500 do_debootstrap 2>&1 3>&1 0>&1 | COLUMNS=500 tee $LOG
# ;;
#iso) COLUMNS=500 pack_iso 2>&1 3>&1 0>&1 | COLUMNS=500 tee $LOG
# ;;
#torrent) COLUMNS=500 DO_TORRENT 2>&1 3>&1 0>&1 | COLUMNS=500 tee $LOG
# ;;
#squash) COLUMNS=500 pack_squashfs 2>&1 3>&1 0>&1 | COLUMNS=500 tee $LOG
# ;;
#source) COLUMNS=500 DO_SOURCE 2>&1 3>&1 0>&1 | COLUMNS=500 tee $LOG
# ;;
#all) COLUMNS=500 do_debootstrap 2>&1 3>&1 0>&1 | COLUMNS=500 tee $LOG
# COLUMNS=500 pack_squashfs 2>&1 3>&1 0>&1 | COLUMNS=500 tee -a $LOG
# COLUMNS=500 pack_iso 2>&1 3>&1 0>&1 | COLUMNS=500 tee -a $LOG
# ;;
#esac
|