live-build/helpers/lh_source_usb

141 lines
3.0 KiB
Plaintext
Raw Normal View History

2007-09-23 08:04:46 +00:00
#!/bin/sh
# lh_source_usb(1) - build source image
2007-09-23 08:04:48 +00:00
# Copyright (C) 2006-2007 Daniel Baumann <daniel@debian.org>
#
# live-helper comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
# This is free software, and you are welcome to redistribute it
# under certain conditions; see COPYING for details.
2007-09-23 08:04:46 +00:00
set -e
# Source common functions
for FUNCTION in /usr/share/live-helper/functions/*.sh
do
. ${FUNCTION}
done
2007-09-23 08:04:48 +00:00
# Set static variables
DESCRIPTION="build source image"
HELP=""
USAGE="${PROGRAM} [--force]"
Arguments "${@}"
2007-09-23 08:04:49 +00:00
Echo_debug "Init ${PROGRAM}"
2007-09-23 08:04:46 +00:00
# Reading configuration files
Read_conffile config/bootstrap
2007-09-23 08:04:49 +00:00
Read_conffile config/chroot
Read_conffile config/common
2007-09-23 08:04:46 +00:00
Read_conffile config/image
Set_defaults
2007-09-23 08:04:49 +00:00
Breakpoint "source_usb: Init"
2007-09-23 08:04:50 +00:00
if [ "${LIVE_SOURCE}" != "enabled" ]
2007-09-23 08:04:46 +00:00
then
exit 0
fi
for IMAGE in ${LIVE_SOURCE_IMAGE}
do
if [ "${IMAGE}" = "usb" ]
then
# Requiring stage file
2007-09-23 08:04:47 +00:00
Require_stagefile .stage/source_download
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:50 +00:00
# Checking stage file
Check_stagefile .stage/source_usb
2007-09-23 08:04:46 +00:00
# Checking lock file
2007-09-23 08:04:47 +00:00
Check_lockfile .lock
2007-09-23 08:04:46 +00:00
# Creating lock file
2007-09-23 08:04:47 +00:00
Create_lockfile .lock
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:47 +00:00
if [ ! -f chroot/sbin/mkdosfs ]
2007-09-23 08:04:46 +00:00
then
PACKAGES="${PACKAGES} dosfstools"
fi
2007-09-23 08:04:47 +00:00
if [ ! -f chroot/sbin/parted ]
2007-09-23 08:04:46 +00:00
then
PACKAGES="${PACKAGES} parted"
fi
if [ -n "${PACKAGES}" ]
then
# Installing packages
case "${LH_APT}" in
2007-09-23 08:04:47 +00:00
apt|apt-get)
2007-09-23 08:04:46 +00:00
Chroot "apt-get install --yes ${PACKAGES}"
;;
aptitude)
Chroot "aptitude install --assume-yes ${PACKAGES}"
;;
esac
fi
# Remove old source
2007-09-23 08:04:47 +00:00
if [ -f source.img ]
2007-09-23 08:04:46 +00:00
then
2007-09-23 08:04:47 +00:00
rm -f source.img
2007-09-23 08:04:46 +00:00
fi
# Everything which comes here needs to be cleaned up,
2007-09-23 08:04:47 +00:00
DU_DIM="`du -ms source | cut -f1`"
2007-09-23 08:04:46 +00:00
REAL_DIM="`expr ${DU_DIM} + ${DU_DIM} / 20`" # Just 5% more to be sure, need something more sophistcated here...
2007-09-23 08:04:47 +00:00
dd if=/dev/zero of=source.img bs=1024k count=${REAL_DIM}
FREELO="`${LH_LOSETUP} -f`"
if [ ! -b chroot/${FREELO} ]
2007-09-23 08:04:46 +00:00
then
MAKEDEV="true"
2007-09-23 08:04:47 +00:00
mv chroot/dev chroot/dev.tmp
find /dev | cpio -dmpu chroot
2007-09-23 08:04:46 +00:00
fi
echo "!!! The following error/warning messages can be ignored !!!"
2007-09-23 08:04:47 +00:00
lh_losetup $FREELO source.img 0
2007-09-23 08:04:46 +00:00
Chroot "parted -s ${FREELO} mklabel msdos" || true
Chroot "parted -s ${FREELO} mkpartfs primary fat16 0.0 100%" || true
Chroot "parted -s ${FREELO} set 1 lba off" || true
2007-09-23 08:04:47 +00:00
${LH_LOSETUP} -d ${FREELO}
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:47 +00:00
lh_losetup $FREELO source.img 1
2007-09-23 08:04:46 +00:00
Chroot "mkfs.msdos -n DEBIAN_LIVE ${FREELO}"
2007-09-23 08:04:47 +00:00
mkdir -p source.tmp
mount ${FREELO} source.tmp
cp -r source/* source.tmp
umount source.tmp
rmdir source.tmp
${LH_LOSETUP} -d ${FREELO}
2007-09-23 08:04:46 +00:00
echo "!!! The above error/warning messages can be ignored !!!"
if [ -n "${MAKEDEV}" ]
then
2007-09-23 08:04:47 +00:00
rm -f chroot/dev
mv chroot/dev.tmp chroot/dev
2007-09-23 08:04:46 +00:00
fi
if [ -n "${PACKAGES}" ]
then
# Removing packages
case "${LH_APT}" in
2007-09-23 08:04:47 +00:00
apt|apt-get)
2007-09-23 08:04:46 +00:00
Chroot "apt-get remove --purge --yes ${PACKAGES}"
;;
aptitude)
Chroot "aptitude purge --assume-yes ${PACKAGES}"
;;
esac
fi
# Creating stage file
2007-09-23 08:04:47 +00:00
Create_stagefile .stage/source_usb
2007-09-23 08:04:46 +00:00
fi
done