summaryrefslogtreecommitdiff
path: root/archiso/mkarchiso
diff options
context:
space:
mode:
authorAaron Griffin <aaronmgriffin@gmail.com>2008-12-18 22:08:38 -0600
committerAaron Griffin <aaronmgriffin@gmail.com>2008-12-18 22:09:19 -0600
commit4e638eaf2430d4036df536cad6fdda219aabf114 (patch)
tree9b21ffc6c55ee6876ff6b78ae0ad496eb0886e9c /archiso/mkarchiso
parent30ff7ea7a61dc1c6b0d46fab69c8d149ec4586f5 (diff)
downloadarchiso32-4e638eaf2430d4036df536cad6fdda219aabf114.tar.xz
Final changes for new nextgen scripts
Too much to list. Just look at the diff 8) Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
Diffstat (limited to 'archiso/mkarchiso')
-rwxr-xr-xarchiso/mkarchiso149
1 files changed, 115 insertions, 34 deletions
diff --git a/archiso/mkarchiso b/archiso/mkarchiso
index 7cb4cb9..5e330f6 100755
--- a/archiso/mkarchiso
+++ b/archiso/mkarchiso
@@ -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: