From 9739af2600e8cd0cce16efa5bf1734fb25f47ac7 Mon Sep 17 00:00:00 2001 From: David Farning Date: Thu, 21 Jan 2010 21:19:19 +0000 Subject: inital commit --- (limited to 'usr-scratch.sh') diff --git a/usr-scratch.sh b/usr-scratch.sh new file mode 100755 index 0000000..55caa2f --- /dev/null +++ b/usr-scratch.sh @@ -0,0 +1,270 @@ +#!/bin/bash +## +## makedistro.sh +## +## Made by David Farning +## Login +## +## 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 < "$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 \ No newline at end of file -- cgit v0.9.1