Rework the commands, create and iso

Initial changes to get 'create' working as intended.

Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
This commit is contained in:
Aaron Griffin 2008-12-06 19:46:50 -08:00
parent 901526970e
commit f918440da1

View File

@ -1,4 +1,4 @@
#!/bin/bash #! /bin/bash
PKGLIST="" PKGLIST=""
QUIET="y" QUIET="y"
@ -15,20 +15,22 @@ usage ()
echo " general options:" echo " general options:"
echo " -f Force overwrite of working files/squashfs image/bootable image" echo " -f Force overwrite of working files/squashfs image/bootable image"
echo " -p PACKAGE(S) Additional package(s) to install, can be used multiple times" echo " -p PACKAGE(S) Additional package(s) to install, can be used multiple times"
echo " -t <iso,disk> Type of image to create. Defaults to iso."
echo " -v Enable verbose output." echo " -v Enable verbose output."
echo " -h This message." echo " -h This message."
echo " commands:" echo " commands:"
echo " install <dir> : install packages to the working dir" echo " create <dir>"
echo " squash <dir> <sqfs name> : generate a squashfs image of the working dir" echo " create a base directory layout to work with"
echo " image -p <bootloader> <dir> <image name> : build an image from the working dir" echo " includes all specified packages"
echo " iso -p <bootloader> <dir> <image name>"
echo " build an iso image from the working dir"
echo " usb -p <bootloader> <dir> <image name>"
echo " build an iso image from the working dir"
exit $1 exit $1
} }
while getopts 'i:P:p:a:t:fvh' arg; do while getopts 'i:P:p:a:t:fvh' arg; do
case "${arg}" in case "${arg}" in
p) PKGLIST="${PKGLIST} ${OPTARG}" ;; p) PKGLIST="${PKGLIST} ${OPTARG}" ;;
t) IMG_TYPE="${OPTARG}" ;;
f) FORCE="y" ;; f) FORCE="y" ;;
v) QUIET="n" ;; v) QUIET="n" ;;
h|?) usage 0 ;; h|?) usage 0 ;;
@ -53,16 +55,15 @@ work_dir=""
imgname="" imgname=""
case "${command_name}" in case "${command_name}" in
install) work_dir="${2}"; imgname="none" ;; create) work_dir="${2}"; imgname="none" ;;
squash) work_dir="${2}"; imgname="${3}" ;; iso) work_dir="${2}"; imgname="${3}" ;;
image) work_dir="${2}"; imgname="${3}" ;; usb) work_dir="${2}"; imgname="${3}" ;;
*) echo "invalid command name '${command_name}'"; usage 1 ;; *) echo "invalid command name '${command_name}'"; usage 1 ;;
esac esac
[ "x${imgname}" = "x" ] && (echo "Image name must be specified" && 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) [ "x${work_dir}" = "x" ] && (echo "Please specify a working directory" && usage 1)
echo "${APPNAME} : Configuration Settings" echo "${APPNAME} : Configuration Settings"
echo " working directory: ${work_dir}" echo " working directory: ${work_dir}"
echo " image name: ${imgname}" echo " image name: ${imgname}"
@ -88,51 +89,54 @@ _pacman ()
fi fi
} }
command_install () { command_create () {
echo "====> Installing packages to '${work_dir}'" echo "====> Creating working directory: ${work_dir}"
if [ -e "${work_dir}" -a "${FORCE}" = "n" ]; then mkdir -p "${work_dir}/iso/"
echo "error: Working dir '${work_dir}' already exists, aborting." mkdir -p "${work_dir}/root-image/"
exit 1 echo "# archiso isomounts file
fi # img - location of image/directory to mount relative to addons directory
# arch - architecture of this image
# mount point - absolute location on the post-initrd root
# type - either 'bind' or 'squashfs' for now
mkdir -p "${work_dir}" # syntax: <img> <arch> <mount point> <type>
if [ "${PKGLIST}" = "" ]; then root-image.sqfs i686 / squashfs
echo "error: no packages to install" #root-image-x86_64.sqfs x86_64 / squashfs" > "${work_dir}/isomounts"
exit 1
fi
echo "Installing packages..." echo "README for this archiso created directory
_pacman "${PKGLIST}"
if [ -d "${work_dir}/lib/modules/" ]; then All directories in this dir, except for 'iso' will be squashed
echo "Updating kernel module dependencies" with squashfs and put into the iso dir as iso/<dirname>.sqfs
kernelver=$(_kversion) This should be reflected in the isomounts file
depmod -a -b "${work_dir}" "${kernelver}"
fi
echo "Cleaning up what we can" The iso dir is later used to build the actual bootable iso.
if [ -d "${work_dir}/boot/" ]; then ...TODO..." > "${work_dir}/README"
# remove the initcpio images that were generated for the host system
find "${work_dir}/boot" -name *.img -delete
fi
#TODO is this needed? do it at the Makefile level? if [ "${PKGLIST}" != "" ]; then
if [ -d "${work_dir}/home/" ]; then echo "====> Installing packages to '${work_dir}/root-image/'"
echo "Creating default home directory" _pacman "${PKGLIST}"
install -d -o1000 -g100 -m0755 "${work_dir}/home/arch"
fi
# delete a lot of unnecessary cache/log files echo "Cleaning up what we can"
kill_dirs="var/abs var/cache/man var/cache/pacman var/log/* var/mail tmp/* initrd" if [ -d "${work_dir}/root-image/boot/" ]; then
for x in ${kill_dirs}; do # remove the initcpio images that were generated for the host system
if [ -e "${work_dir}/${x}" ]; then find "${work_dir}/root-image/boot" -name *.img -delete
rm -rf "${work_dir}/${x}"
fi fi
done
# pacman DBs are big, delete all sync dbs #TODO is this needed? do it at the Makefile level?
rm -rf "${work_dir}/var/lib/pacman/sync" if [ -d "${work_dir}/root-image/home/" ]; then
echo "Creating default home directory"
install -d -o1000 -g100 -m0755 "${work_dir}/root-image/home/arch"
fi
# delete a lot of unnecessary cache/log files
kill_dirs="var/abs var/cache/man var/cache/pacman var/lib/pacman/sync var/log/* var/mail tmp/* initrd"
for x in ${kill_dirs}; do
if [ -e "${work_dir}/root-image/${x}" ]; then
rm -rf "${work_dir}/root-image/${x}"
fi
done
fi
} }
# command_squash path image # command_squash path image
@ -218,25 +222,6 @@ command_image () {
exit 1 exit 1
fi fi
if [ "$IMG_TYPE" = "disk" ]; then
echo "Creating DISK image..."
mkusbimg "${work_dir}" "${imgname}"
elif [ "$IMG_TYPE" = "iso" ]; then
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}"
else
echo "Invalid image type '$IMG_TYPE' specified"
exit 1
fi
}
# Go through the main commands in order. If 'all' was specified, then we want # Go through the main commands in order. If 'all' was specified, then we want
# to do everything. Start with 'install'. # to do everything. Start with 'install'.
if [ "${command_name}" = "install" ]; then if [ "${command_name}" = "install" ]; then