live-build/helpers/lh_binary_usb-hdd

159 lines
3.7 KiB
Plaintext
Raw Normal View History

2007-09-23 08:04:46 +00:00
#!/bin/sh
2007-09-23 08:04:52 +00:00
# lh_binary_usb-hdd(1) - build binary 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 binary 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
2007-09-23 08:04:52 +00:00
Read_conffile config/common
2007-09-23 08:04:46 +00:00
Read_conffile config/bootstrap
2007-09-23 08:04:49 +00:00
Read_conffile config/chroot
2007-09-23 08:04:52 +00:00
Read_conffile config/binary
Read_conffile config/source
2007-09-23 08:04:46 +00:00
Set_defaults
2007-09-23 08:04:52 +00:00
Breakpoint "binary_usb-hdd: Init"
2007-09-23 08:04:49 +00:00
2007-09-23 08:04:46 +00:00
for IMAGE in ${LIVE_BINARY_IMAGE}
do
2007-09-23 08:04:52 +00:00
if [ "${IMAGE}" = "usb-hdd" ]
2007-09-23 08:04:46 +00:00
then
2007-09-23 08:04:48 +00:00
# Requiring stage file
Require_stagefile .stage/bootstrap
Require_stagefile .stage/chroot_proc
2007-09-23 08:04:50 +00:00
# Checking stage file
2007-09-23 08:04:52 +00:00
Check_stagefile .stage/binary_usb-hdd
2007-09-23 08:04:50 +00:00
2007-09-23 08:04:48 +00:00
# Checking lock file
Check_lockfile .lock
# Creating lock file
Create_lockfile .lock
2007-09-23 08:04:51 +00:00
# Checking depends
Check_package chroot/sbin/mkdosfs dosfstools
Check_package chroot/usr/sbin/mtools mtools
Check_package chroot/sbin/parted parted
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:50 +00:00
case "${LIVE_BOOTLOADER}" in
grub)
2007-09-23 08:04:51 +00:00
Check_package chroot/usr/sbin/grub grub
2007-09-23 08:04:50 +00:00
;;
2007-09-23 08:04:49 +00:00
2007-09-23 08:04:50 +00:00
syslinux)
2007-09-23 08:04:51 +00:00
Check_package chroot/usr/bin/syslinux syslinux
2007-09-23 08:04:50 +00:00
;;
esac
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:51 +00:00
# Installing depends
Install_package
2007-09-23 08:04:46 +00:00
# Remove old binary
2007-09-23 08:04:47 +00:00
if [ -f binary.img ]
2007-09-23 08:04:46 +00:00
then
2007-09-23 08:04:47 +00:00
rm -f binary.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 binary | cut -f1`"
2007-09-23 08:04:52 +00:00
REAL_DIM="`expr ${DU_DIM} + ${DU_DIM} / 50`" # Just 2% more to be sure, need something more sophistcated here...
2007-09-23 08:04:47 +00:00
dd if=/dev/zero of=binary.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 binary.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 boot on" || true
Chroot "parted -s ${FREELO} set 1 lba off" || true
2007-09-23 08:04:49 +00:00
case "${LIVE_BOOTLOADER}" in
grub)
2007-09-23 08:04:50 +00:00
#echo "(hd0) ${FREELO}" > binary/boot/grub/device.map
#grub --batch --no-floppy --device-map=binary/boot/grub/device.map << EOF
#setup --stage1=binary/boot/grub/stage1 --stage2=binary/boot/grub/stage2 --prefix=/boot/grub (hd0)
#
#quit
#EOF
#rm -f binary/boot/grub/device.map
#Chroot "grub-install --no-floppy --root-directory=/ (hd0)"
2007-09-23 08:04:49 +00:00
;;
syslinux)
cat chroot/usr/lib/syslinux/mbr.bin > ${FREELO}
;;
esac
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:50 +00:00
FREELO="`${LH_LOSETUP} -f`"
2007-09-23 08:04:47 +00:00
lh_losetup $FREELO binary.img 1
2007-09-23 08:04:52 +00:00
Chroot " mkfs.vfat -F 16 -n DEBIAN_LIVE ${FREELO}"
2007-09-23 08:04:47 +00:00
mkdir -p binary.tmp
2007-09-23 08:04:51 +00:00
${LH_ROOT_COMMAND} mount ${FREELO} binary.tmp
2007-09-23 08:04:47 +00:00
cp -r binary/* binary.tmp
2007-09-23 08:04:51 +00:00
${LH_ROOT_COMMAND} umount binary.tmp
2007-09-23 08:04:47 +00:00
rmdir binary.tmp
2007-09-23 08:04:50 +00:00
if [ "${LIVE_BOOTLOADER}" = "syslinux" ]
then
Chroot "syslinux ${FREELO}"
fi
2007-09-23 08:04:47 +00:00
${LH_LOSETUP} -d ${FREELO}
2007-09-23 08:04:50 +00:00
#if [ "${LIVE_BOOTLOADER}" = "grub" ]
#then
# FREELO="`${LH_LOSETUP} -f`"
# lh_losetup $FREELO binary.img 0
# dd if=binary/boot/grub/stage1 of=${FREELO} bs=512 count=1
# dd if=binary/boot/grub/stage2 of=${FREELO} bs=512 seek=1
# ${LH_LOSETUP} -d ${FREELO}
#fi
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
2007-09-23 08:04:51 +00:00
# Removing depends
Remove_package
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:47 +00:00
# Creating stage file
2007-09-23 08:04:52 +00:00
Create_stagefile .stage/binary_usb-hdd
2007-09-23 08:04:47 +00:00
fi
2007-09-23 08:04:46 +00:00
done