2007-09-23 08:04:46 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# lh_binary_net(1) - build netboot binary image
|
2009-01-26 15:39:27 -01:00
|
|
|
# Copyright (C) 2006-2009 Daniel Baumann <daniel@debian.org>
|
2007-09-23 08:04:48 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
# Including common functions
|
2009-01-26 15:07:40 -01:00
|
|
|
. "${LH_BASE:-/usr/share/live-helper}"/functions.sh
|
2007-09-23 08:04:46 +00:00
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
# Setting static variables
|
2009-01-15 01:37:42 -01:00
|
|
|
DESCRIPTION="$(Echo 'build netboot binary image')"
|
2007-09-23 08:04:48 +00:00
|
|
|
HELP=""
|
|
|
|
USAGE="${PROGRAM} [--force]"
|
|
|
|
|
|
|
|
Arguments "${@}"
|
|
|
|
|
2007-09-23 08:04:46 +00:00
|
|
|
# Reading configuration files
|
2008-10-28 14:26:17 -01:00
|
|
|
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
|
2007-09-23 08:04:46 +00:00
|
|
|
Set_defaults
|
|
|
|
|
2008-06-20 00:31:21 +00:00
|
|
|
if ! In_list net "${LH_BINARY_IMAGES}"
|
2007-09-23 08:05:11 +00:00
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
2007-09-23 08:04:49 +00:00
|
|
|
|
2008-02-26 17:57:41 -01:00
|
|
|
if [ "${LH_NET_TARBALL}" = "none" ]
|
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
Echo_message "Begin building binary netboot image..."
|
2007-09-23 08:04:48 +00:00
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
# Requiring stage file
|
2008-10-14 19:32:50 +00:00
|
|
|
Require_stagefile .stage/config .stage/bootstrap
|
2007-09-23 08:04:50 +00:00
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
# Checking stage file
|
|
|
|
Check_stagefile .stage/binary_net
|
2007-09-23 08:04:48 +00:00
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
# Checking lock file
|
|
|
|
Check_lockfile .lock
|
2007-09-23 08:04:48 +00:00
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
# Creating lock file
|
|
|
|
Create_lockfile .lock
|
2007-09-23 08:04:46 +00:00
|
|
|
|
2008-06-20 00:38:21 +00:00
|
|
|
if [ "${LH_ARCHITECTURE}" = "sparc" ]
|
|
|
|
then
|
|
|
|
# Checking depends
|
|
|
|
Check_package chroot/usr/bin/elftoaout sparc-utils
|
|
|
|
|
|
|
|
# Restoring cache
|
|
|
|
Restore_cache cache/packages_binary
|
|
|
|
|
|
|
|
# Installing depends
|
|
|
|
Install_package
|
|
|
|
|
|
|
|
# Set target and source directories
|
|
|
|
DESTDIR="tftpboot"
|
|
|
|
case "${LH_INITRAMFS}" in
|
|
|
|
casper)
|
|
|
|
ORIGDIR="binary/casper"
|
|
|
|
;;
|
|
|
|
|
|
|
|
live-initramfs)
|
|
|
|
ORIGDIR="binary/live"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Find defaults
|
|
|
|
DEFAULT_FLAVOUR="$(echo ${LH_LINUX_FLAVOURS} | awk '{ print $1 }')"
|
|
|
|
DEFAULT_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
|
|
|
|
DEFAULT_INITRD="initrd.img-$(echo ${DEFAULT_KERNEL} | sed -e 's|vmlinuz-||')"
|
|
|
|
DEFAULT_MAP="$(echo chroot/boot/System.map-*${DEFAULT_FLAVOUR})"
|
|
|
|
|
|
|
|
gzip -cd ${ORIGDIR}/${DEFAULT_KERNEL} > kernel.tmp
|
|
|
|
|
|
|
|
mkdir -p ${DESTDIR}
|
|
|
|
rm -f ${DESTDIR}/boot.img
|
|
|
|
elftoaout -o ${DESTDIR}/boot.img kernel.tmp
|
|
|
|
|
|
|
|
case "${DEFAULT_FLAVOUR}" in
|
|
|
|
sparc32)
|
|
|
|
piggyback ${DESTDIR}/boot.img ${DEFAULT_MAP} ${ORIGDIR}/${DEFAULT_INITRD}
|
|
|
|
;;
|
|
|
|
sparc64)
|
|
|
|
piggyback64 ${DESTDIR}/boot.img ${DEFAULT_MAP} ${ORIGDIR}/${DEFAULT_INITRD}
|
|
|
|
;;
|
|
|
|
*)
|
2008-08-11 20:28:54 +00:00
|
|
|
Echo_error "Invalid default kernel flavour for sparc \"%s\"" "${DEFAULT_FLAVOUR}"
|
2008-06-20 00:38:21 +00:00
|
|
|
exit 1;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Pad boot.img
|
|
|
|
REMAINDER=$((( 4 - $(stat -c %s ${DESTDIR}/boot.img) % 4 ) % 4))
|
|
|
|
dd if=/dev/zero bs=1 count=${REMAINDER} >> ${DESTDIR}/boot.img
|
|
|
|
|
|
|
|
# No need for kernel and initrd images in the binary
|
|
|
|
rm -f ${ORIGDIR}/vmlinuz-*
|
|
|
|
rm -f ${ORIGDIR}/initrd.img-*
|
|
|
|
|
|
|
|
# Clean temporaries
|
|
|
|
rm -f kernel.tmp
|
|
|
|
|
|
|
|
# Saving cache
|
|
|
|
Save_cache cache/packages_binary
|
|
|
|
|
|
|
|
# Removing depends
|
|
|
|
Remove_package
|
|
|
|
fi
|
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
# Remove old binary
|
2008-02-26 17:57:41 -01:00
|
|
|
rm -f binary-net.tar.bz2
|
|
|
|
rm -f binary-net.tar.gz
|
|
|
|
rm -f binary-net.tar
|
2007-09-23 08:04:49 +00:00
|
|
|
|
2007-09-23 08:05:11 +00:00
|
|
|
# Creating image file
|
2007-10-31 12:59:01 -01:00
|
|
|
ROOT_DIR=$(basename ${LH_NET_ROOT_PATH})
|
|
|
|
if [ "${ROOT_DIR}" = "chroot" ]
|
2007-09-23 08:05:11 +00:00
|
|
|
then
|
|
|
|
mv chroot chroot.tmp
|
|
|
|
fi
|
2007-09-23 08:04:47 +00:00
|
|
|
|
2007-10-31 12:59:01 -01:00
|
|
|
if [ "${ROOT_DIR}" != "binary" ]
|
|
|
|
then
|
|
|
|
mv binary ${ROOT_DIR}
|
|
|
|
fi
|
2007-09-23 08:04:47 +00:00
|
|
|
|
2009-02-14 15:40:43 -01:00
|
|
|
mkdir binary.tmp
|
|
|
|
mv ${ROOT_DIR} tftpboot binary.tmp
|
|
|
|
cd binary.tmp
|
2008-02-26 17:57:41 -01:00
|
|
|
|
|
|
|
case "${LH_NET_TARBALL}" in
|
|
|
|
bzip2)
|
2009-02-14 15:40:43 -01:00
|
|
|
tar cfj ../binary-net-tar.bz2 *
|
2008-02-26 17:57:41 -01:00
|
|
|
;;
|
|
|
|
|
|
|
|
gzip)
|
2008-06-19 18:49:16 +00:00
|
|
|
if gzip --help | grep -qs "\-\-rsyncable"
|
2008-04-22 21:32:30 +00:00
|
|
|
then
|
2009-02-14 15:40:43 -01:00
|
|
|
tar cf ../binary-net.tar *
|
|
|
|
gzip --rsyncable --best ../binary-net.tar
|
2008-04-22 21:32:30 +00:00
|
|
|
else
|
2009-02-14 15:40:43 -01:00
|
|
|
tar cfz ../binary-net.tar.gz *
|
2008-04-22 21:32:30 +00:00
|
|
|
fi
|
2008-02-26 17:57:41 -01:00
|
|
|
;;
|
|
|
|
|
|
|
|
tar)
|
2009-02-14 15:40:43 -01:00
|
|
|
tar cf ../binary-net.tar *
|
2008-02-26 17:57:41 -01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-02-14 15:40:43 -01:00
|
|
|
mv * ../
|
2007-09-23 08:05:11 +00:00
|
|
|
cd "${OLDPWD}"
|
2009-02-14 15:40:43 -01:00
|
|
|
rmdir binary.tmp
|
2007-09-23 08:04:46 +00:00
|
|
|
|
2007-10-31 12:59:01 -01:00
|
|
|
if [ "${ROOT_DIR}" != "binary" ]
|
|
|
|
then
|
|
|
|
mv ${ROOT_DIR} binary
|
|
|
|
fi
|
2007-09-23 08:04:49 +00:00
|
|
|
|
2007-10-31 12:59:01 -01:00
|
|
|
if [ "${ROOT_DIR}" = "chroot" ]
|
2007-09-23 08:05:11 +00:00
|
|
|
then
|
|
|
|
mv chroot.tmp chroot
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Creating stage file
|
|
|
|
Create_stagefile .stage/binary_net
|