Final changes for new nextgen scripts

Too much to list. Just look at the diff 8)

Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
This commit is contained in:
Aaron Griffin 2008-12-18 22:08:38 -06:00
parent 30ff7ea7a6
commit 4e638eaf24
5 changed files with 154 additions and 154 deletions

View file

@ -3,8 +3,6 @@
PKGLIST=""
QUIET="y"
FORCE="n"
MOUNTFILE="$(pwd)/mounts"
IMG_TYPE="iso"
APPNAME=$(basename "${0}")
@ -42,7 +40,6 @@ done
PKGLIST="$(echo $PKGLIST)"
shift $(($OPTIND - 1))
echo "ARGS: $@"
# do UID checking here so someone can at least get usage instructions
if [ "$EUID" != "0" ]; then
@ -61,23 +58,22 @@ case "${command_name}" in
*) echo "invalid command name '${command_name}'"; usage 1 ;;
esac
[ "x${imgname}" = "x" ] && (echo "Image name must be specified" && usage 1)
[ "x${work_dir}" = "x" ] && (echo "Please specify a working directory" && usage 1)
[ "x${imgname}" = "x" ] && echo "Image name must be specified" && usage 1
[ "x${work_dir}" = "x" ] && echo "Please specify a working directory" && usage 1
echo "${APPNAME} : Configuration Settings"
echo " working directory: ${work_dir}"
echo " image name: ${imgname}"
echo " image type: ${IMG_TYPE}"
# usage: _pacman <packages>...
_pacman ()
{
local ret
if [ "${QUIET}" = "y" ]; then
mkarchroot -f ${work_dir} $* 2>&1 >/dev/null
mkarchroot -f "${work_dir}/root-image" $* 2>&1 >/dev/null
ret=$?
else
mkarchroot -f ${work_dir} $*
mkarchroot -f "${work_dir}/root-image" $*
ret=$?
fi
@ -139,16 +135,23 @@ The iso dir is later used to build the actual bootable iso.
fi
}
# command_squash path image
command_squash () {
echo "====> Generating SquashFS image ${imgname}"
if [ -e "${imgname}" ]; then
# _mksquash dirname
_mksquash () {
echo "_mksquash $1"
if [ ! -d "$1" ]; then
echo "Error: '$1' is not a directory"
return 1
fi
sqimg="${work_dir}/iso/$(basename ${1}).sqfs"
echo "====> Generating SquashFS image for '${1}'"
if [ -e "${sqimg}" ]; then
if [ "${FORCE}" = "y" ]; then
echo -n "Removing old SquashFS image..."
rm "${imgname}"
rm "${sqimg}"
echo "done."
else
echo "error: SquashFS image '${imgname}' already exists, aborting."
echo "error: SquashFS image '${sqimg}' already exists, aborting."
exit 1
fi
fi
@ -156,16 +159,37 @@ command_squash () {
echo "Creating SquashFS image. This may take some time..."
start=$(date +%s)
if [ "${QUIET}" = "y" ]; then
mksquashfs "${work_dir}" "${imgname}" -noappend >/dev/null
mksquashfs "${1}" "${sqimg}" -noappend >/dev/null
else
mksquashfs "${work_dir}" "${imgname}" -noappend
mksquashfs "${1}" "${sqimg}" -noappend
fi
minutes=$(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }')
echo "Image creation done in $minutes minutes."
}
command_image () {
_imgcommon () {
for d in $(find "${work_dir}" -maxdepth 1 -type d -name '[^.]*'); do
if [ "$d" != "${work_dir}/iso" -a \
"$(basename "$d")" != "iso" -a \
"$d" != "${work_dir}" ]; then
_mksquash "$d"
fi
done
echo "====> Making bootable image"
# Sanity checks
if [ ! -d "${work_dir}/iso" ]; then
echo "Error: '${work_dir}/iso' doesn't exist. What did you do?!"
exit 1
fi
if [ ! -f "${work_dir}/isomounts" ]; then
echo "Error: the isomounts file doesn't exist. This image won't do anything"
echo " Protecting you from yourself and erroring out here..."
exit 1
fi
if [ -e "${imgname}" ]; then
if [ "${FORCE}" = "y" ]; then
echo "Removing existing bootable image..."
@ -176,11 +200,11 @@ command_image () {
fi
fi
if [ ! -e "${MOUNTFILE}" ]; then
echo "error: mount file '${MOUNTFILE}' does not exist, aborting."
exit 1
fi
cp "${MOUNTFILE}" "${work_dir}/mounts"
cp "${work_dir}/isomounts" "${work_dir}/iso/"
}
command_iso () {
_imgcommon
bootflags=""
if [ "$PKGLIST" = "grub" -o "$PKGLIST" = "grub-gfx" ]; then
@ -195,20 +219,20 @@ command_image () {
exit 1
fi
if [ ! -e "${work_dir}/boot/grub/stage2_eltorito" ]; then
echo "error: grub stage files not found in '${work_dir}/boot/grub"
if [ ! -e "${work_dir}/iso/boot/grub/stage2_eltorito" ]; then
echo "error: grub stage files not found in '${work_dir}/iso/boot/grub'"
exit 1
fi
bootflags="-b boot/grub/stage2_eltorito"
elif [ "$PKGLIST" = "syslinux" ]; then
elif [ "$PKGLIST" = "isolinux" ]; then
if ! pacman -Qi $PKGLIST >/dev/null 2>&1; then
echo "$PKGLIST not found on host system. Cannot install!"
exit 1
fi
if [ ! -e "${work_dir}/boot/isolinux/isolinux.bin" ]; then
echo "error: isolinux bin file not found in '${work_dir}/boot/isolinux"
if [ ! -e "${work_dir}/iso/boot/isolinux/isolinux.bin" ]; then
echo "error: isolinux bin file not found in '${work_dir}/iso/boot/isolinux'"
exit 1
fi
@ -218,20 +242,77 @@ command_image () {
echo " Supported Bootloaders:"
echo " grub"
echo " grub-gfx"
echo " syslinux"
echo " isolinux"
exit 1
fi
echo "Creating ISO image..."
qflag=""
[ "${QUIET}" = "y" ] && qflag="-q"
mkisofs ${qflag} -r -l $bootflags -uid 0 -gid 0 \
-input-charset utf-8 -p "prepared by mkarchiso" \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-publisher "ArchLinux <archlinux.org>" \
-A "ArchLinux Live/Rescue CD" \
-o "${imgname}" "${work_dir}/iso/"
}
command_usb () {
_imgcommon
fsimg="${imgname}.part1"
# ext2 overhead's upper bound is 6%, empirically tested up to 1GB
rootsize=$(du -bs ${IMGROOT}|cut -f1)
imgsz=$(( (${rootsize}*106)/100/512 + 1)) # image size in sectors
# create the filesystem image file
dd if=/dev/zero of="$fsimg" bs=512 count="$imgsz"
# create a filesystem on the image
mke2fs -m 0 -F "$fsimg"
# mount the filesystem and copy data
modprobe loop
TMPDIR=$(mktemp -d archiso-usbXXXXXX)
mount -o loop "$fsimg" "$TMPDIR"
cp -a "${work_dir}"/iso/* "$TMPDIR"
umount "$TMPDIR"
rm -f "$TMPDIR"
# add sectors 0-62, then glue together
dd if=/dev/zero of="${imgname}" bs=512 count=63
cat "$fsimg" >> "${imgname}"
rm "$fsimg"
# create a partition table
# if this looks like voodoo, it's because it is
sfdisk -uS -f "${imgname}" << EOF
63,$imgsz,83,*
0,0,00
0,0,00
0,0,00
EOF
# install grub on the image
grub --no-floppy --batch << EOF
device (hd0) ${imgname}
root (hd0,0)
setup (hd0)
EOF
}
# Go through the main commands in order. If 'all' was specified, then we want
# to do everything. Start with 'install'.
if [ "${command_name}" = "install" ]; then
command_install
if [ "${command_name}" = "create" ]; then
command_create
fi
if [ "${command_name}" = "squash" ]; then
command_squash
if [ "${command_name}" = "iso" ]; then
command_iso
fi
if [ "${command_name}" = "image" ]; then
command_image
if [ "${command_name}" = "usb" ]; then
command_usb
fi
# vim:ts=4:sw=4:et:

View file

@ -1,79 +0,0 @@
#!/bin/bash
#
# mkusbimg - creates a bootable disk image
# Copyright (C) 2008 Simo Leone <simo@archlinux.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# usage(exitvalue)
# outputs a usage message and exits with value
APPNAME=$(basename "${0}")
usage()
{
echo "usage: ${APPNAME} <imageroot> <imagefile>"
exit $1
}
##################################################
if [ $# -ne 2 ]; then
usage 1
fi
DISKIMG="${2}"
IMGROOT="${1}"
TMPDIR=$(mktemp -d)
FSIMG=$(mktemp)
# ext2 overhead's upper bound is 6%
# empirically tested up to 1GB
rootsize=$(du -bs ${IMGROOT}|cut -f1)
IMGSZ=$(( (${rootsize}*106)/100/512 + 1)) # image size in sectors
# create the filesystem image file
dd if=/dev/zero of="$FSIMG" bs=512 count="$IMGSZ"
# create a filesystem on the image
mke2fs -m 0 -F "$FSIMG"
# mount the filesystem and copy data
modprobe loop
mount -o loop "$FSIMG" "$TMPDIR"
cp -a "$IMGROOT"/* "$TMPDIR"
# unmount filesystem
umount "$TMPDIR"
# add sectors 0-62, then glue together
dd if=/dev/zero of="$DISKIMG" bs=512 count=63
cat "$FSIMG" >> "$DISKIMG"
# create a partition table
# if this looks like voodoo, it's because it is
sfdisk -uS -f "$DISKIMG" << EOF
63,$IMGSZ,83,*
0,0,00
0,0,00
0,0,00
EOF
# install grub on the image
grub --no-floppy --batch << EOF
device (hd0) $DISKIMG
root (hd0,0)
setup (hd0)
EOF
# all done :)
rm -fr "$TMPDIR" "$FSIMG"