2006-08-30 07:32:35 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
CONFIG="$(pwd)/mkarchiso.conf"
|
2006-09-12 20:14:17 +02:00
|
|
|
CPIOCONFIG="$(pwd)/archiso-mkinitcpio.conf"
|
2006-08-30 07:32:35 +02:00
|
|
|
DEF_CONFIG_DIR="$(pwd)/default-config"
|
|
|
|
QUIET="y"
|
2006-09-12 20:14:17 +02:00
|
|
|
FORCE="n"
|
2006-08-30 07:32:35 +02:00
|
|
|
|
2006-09-12 20:14:17 +02:00
|
|
|
command_name=""
|
|
|
|
work_dir=""
|
|
|
|
isoname=""
|
2006-08-30 07:32:35 +02:00
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
PKGDIR="$(pwd)"
|
2006-08-30 07:32:35 +02:00
|
|
|
|
|
|
|
APPNAME=$(basename "${0}")
|
2007-10-06 11:20:26 +02:00
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# usage: usage <exitvalue>
|
2006-08-30 07:32:35 +02:00
|
|
|
usage ()
|
|
|
|
{
|
2006-09-12 20:14:17 +02:00
|
|
|
echo "usage ${APPNAME} [options] command <command options>"
|
|
|
|
echo " general options:"
|
2007-10-10 06:50:11 +02:00
|
|
|
echo " -c CONFIG Use CONFIG file. default: ${CONFIG}"
|
|
|
|
echo " -i CPIO_CONFIG Use CONFIG file for mkinitcpio. default: ${CPIOCONFIG}"
|
|
|
|
echo " -p PKGFILE_DIR Look for package list files in DIR. default: ${PKGDIR}"
|
|
|
|
echo " -f Force overwrite of working files/squashfs image/iso"
|
2006-09-12 20:14:17 +02:00
|
|
|
echo " -v Verbose output. Default: no"
|
2007-10-10 06:50:11 +02:00
|
|
|
echo " -h This message"
|
2006-09-12 20:14:17 +02:00
|
|
|
echo " commands:"
|
|
|
|
echo " install <working dir> : where to build the ISO root"
|
|
|
|
echo " squash <working dir> : generate a squashfs image of the ISO root"
|
2007-10-10 06:50:11 +02:00
|
|
|
echo " iso <working dir> <iso name> : build an ISO from the working directory"
|
2006-09-12 20:14:17 +02:00
|
|
|
echo " all <working dir> <iso name> : perform all of the above, in order"
|
2007-10-10 06:50:11 +02:00
|
|
|
exit $1
|
2006-08-30 07:32:35 +02:00
|
|
|
}
|
|
|
|
|
2007-10-09 10:39:09 +02:00
|
|
|
while getopts 'c:i:p:fvh' arg; do
|
2006-09-12 20:14:17 +02:00
|
|
|
case "${arg}" in
|
|
|
|
c) CONFIG="${OPTARG}" ;;
|
|
|
|
i) CPIOCONFIG="${OPTARG}" ;;
|
2007-10-09 10:39:09 +02:00
|
|
|
p) PKGDIR="${OPTARG}" ;;
|
2006-09-28 04:15:25 +02:00
|
|
|
f) FORCE="y" ;;
|
2006-08-30 07:32:35 +02:00
|
|
|
v) QUIET="n" ;;
|
2007-10-10 06:50:11 +02:00
|
|
|
h|?) usage 0 ;;
|
|
|
|
*) echo "invalid argument '${arg}'"; usage 1 ;;
|
2006-08-30 07:32:35 +02:00
|
|
|
esac
|
|
|
|
done
|
2007-10-10 06:50:11 +02:00
|
|
|
|
|
|
|
# do UID checking here so someone can at least get usage instructions
|
|
|
|
if [ "$EUID" != "0" ]; then
|
|
|
|
echo "error: This script must be run as root."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-08-30 07:32:35 +02:00
|
|
|
shift $(($OPTIND - 1))
|
2006-09-28 04:15:25 +02:00
|
|
|
echo "ARGS: $@"
|
2006-08-30 07:32:35 +02:00
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
[ $# -le 1 ] && usage 1
|
2006-09-12 20:14:17 +02:00
|
|
|
|
|
|
|
command_name="${1}"
|
|
|
|
case "${command_name}" in
|
|
|
|
install) work_dir="${2}" ;;
|
|
|
|
squash) work_dir="${2}" ;;
|
|
|
|
iso) work_dir="${2}"; isoname="${3}" ;;
|
|
|
|
all) work_dir="${2}"; isoname="${3}" ;;
|
2007-10-10 06:50:11 +02:00
|
|
|
*) echo "invalid command name '${command_name}'"; usage 1 ;;
|
2006-09-12 20:14:17 +02:00
|
|
|
esac
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
[ "x${work_dir}" = "x" ] && (echo "please specify a working directory" && usage 1)
|
2006-08-30 07:32:35 +02:00
|
|
|
|
2006-09-12 20:14:17 +02:00
|
|
|
#TODO - do we even need a config file?
|
2006-08-30 07:32:35 +02:00
|
|
|
if [ -e "${CONFIG}" ]; then
|
|
|
|
source "${CONFIG}"
|
|
|
|
else
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "error: Config '${CONFIG}' does not exist, aborting."
|
2006-08-30 07:32:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-09-12 20:14:17 +02:00
|
|
|
# {{{ Build
|
2006-08-30 07:32:35 +02:00
|
|
|
isoroot="${work_dir}/iso"
|
|
|
|
instroot="${work_dir}/install"
|
|
|
|
|
|
|
|
_kversion ()
|
|
|
|
{
|
2007-10-05 21:27:52 +02:00
|
|
|
source ${instroot}/etc/mkinitcpio.d/kernel26.kver
|
|
|
|
echo ${ALL_kver}
|
2006-08-30 07:32:35 +02:00
|
|
|
}
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# usage: _pacman <packages>...
|
2006-08-30 07:32:35 +02:00
|
|
|
_pacman ()
|
|
|
|
{
|
2007-10-06 11:20:26 +02:00
|
|
|
if ! mkarchroot -f ${instroot} $*; then
|
2006-08-30 07:32:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# usage: install_pkgfile <packagesfile>
|
2006-08-30 07:32:35 +02:00
|
|
|
install_pkgfile ()
|
|
|
|
{
|
|
|
|
if [ -e "${1}" ]; then
|
|
|
|
toinstall=""
|
|
|
|
while read pkg; do
|
2006-09-11 10:36:37 +02:00
|
|
|
echo $ignorepkgs | grep "\<$pkg\>" >/dev/null 2>&1 && continue
|
2006-08-30 07:32:35 +02:00
|
|
|
toinstall="${toinstall} ${pkg}"
|
|
|
|
done < ${1}
|
2007-10-06 11:20:26 +02:00
|
|
|
_pacman "${toinstall}"
|
2007-10-09 10:39:09 +02:00
|
|
|
else
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "error: Package file '${1}' does not exist, aborting."
|
2007-10-09 10:39:09 +02:00
|
|
|
exit 1
|
2006-08-30 07:32:35 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# Go through the main commands in order. If 'all' was specified, then we want
|
|
|
|
# to do everything. Start with 'install'.
|
2006-09-12 20:14:17 +02:00
|
|
|
if [ "${command_name}" = "install" -o "${command_name}" = "all" ]; then
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "====> Installing/building ISO root"
|
2006-09-28 04:15:25 +02:00
|
|
|
if [ -e "${work_dir}" -a "${FORCE}" = "n" ]; then
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "error: Working dir '${work_dir}' already exists, aborting."
|
2006-09-28 04:15:25 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-08-30 07:32:35 +02:00
|
|
|
mkdir -p "${isoroot}"
|
|
|
|
mkdir -p "${instroot}"
|
|
|
|
|
2007-10-09 10:40:20 +02:00
|
|
|
echo "Installing packages..."
|
|
|
|
for pkgfile in ${package_files}; do
|
|
|
|
echo " Installing packages from '$pkgfile'"
|
|
|
|
install_pkgfile "${PKGDIR}/$pkgfile.packages"
|
2006-08-30 07:32:35 +02:00
|
|
|
done
|
|
|
|
for pkg in ${additional_packages}; do
|
|
|
|
echo " Installing package '${pkg}'"
|
|
|
|
_pacman "${pkg}"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Installing kernel '${kernelpkg}'"
|
2007-10-06 11:20:26 +02:00
|
|
|
if ! _pacman "${kernelpkg}" ; then
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "error: pacman failed to install '${kernelpkg}', aborting."
|
2006-08-30 07:32:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
kernelver=$(_kversion)
|
|
|
|
kernelsuffix=${kernelver##*-}
|
|
|
|
echo "Kernel Version ${kernelver} (${kernelsuffix}) installed - installing modules..."
|
2007-10-09 10:39:09 +02:00
|
|
|
if [ -e "${PKGDIR}/${kernelsuffix}.modules" ]; then
|
|
|
|
install_pkgfile "${PKGDIR}/${kernelsuffix}.modules"
|
|
|
|
fi
|
2006-08-30 07:32:35 +02:00
|
|
|
|
|
|
|
echo "Updating module dependancies"
|
2006-09-12 20:14:17 +02:00
|
|
|
[ "${kernelsuffix}" = "ARCH" ] && kernelsuffix=""
|
2006-08-30 07:32:35 +02:00
|
|
|
depmod -a -b "${instroot}" -v "${kernelver}" -F "${instroot}/boot/System.map26${kernelsuffix}" >/dev/null
|
2006-09-12 20:14:17 +02:00
|
|
|
find "${instroot}/boot" -name *.img -delete #TODO, will this delete our special stuff?
|
2006-08-30 07:32:35 +02:00
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "Applying default configuration for the Arch ISO"
|
2006-09-28 04:15:25 +02:00
|
|
|
cp -rfa ${DEF_CONFIG_DIR}/* "${instroot}"
|
2006-08-30 07:32:35 +02:00
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "Copyright (C) 2007, Arch Linux (Judd Vinet)" > "${instroot}/etc/copyright"
|
2006-08-30 07:32:35 +02:00
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "Creating initial device nodes"
|
2006-08-30 07:32:35 +02:00
|
|
|
rm -f "${instroot}/dev/console" "${instroot}/dev/null" "${instroot}/dev/zero"
|
|
|
|
mknod -m 644 "${instroot}/dev/console" c 5 1
|
|
|
|
mknod -m 666 "${instroot}/dev/null" c 1 3
|
|
|
|
mknod -m 666 "${instroot}/dev/zero" c 1 5
|
|
|
|
|
|
|
|
echo "Creating default home directory"
|
2007-10-09 10:41:39 +02:00
|
|
|
install -d -o1000 -g100 -m0755 "${instroot}/home/arch"
|
2006-08-30 07:32:35 +02:00
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
echo "Cleaning up ISO root files..."
|
|
|
|
find "${instroot}" -name *.pacnew -name *.pacsave -name *.pacorig -delete
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# delete a lot of unnecessary cache/log files
|
2007-10-09 09:14:12 +02:00
|
|
|
kill_dirs="var/abs var/cache/man var/cache/pacman var/log/* var/mail tmp/* usr/include initrd"
|
2006-08-30 07:32:35 +02:00
|
|
|
for x in ${kill_dirs}; do
|
|
|
|
if [ -e "${instroot}/${x}" ]; then
|
|
|
|
rm -rf "${instroot}/${x}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# delete static libraries
|
2006-08-30 07:32:35 +02:00
|
|
|
find "${instroot}/lib" -name *.a -delete
|
|
|
|
find "${instroot}/usr/lib" -name *.a -delete
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# pacman DBs are big, delete all sync dbs
|
2006-08-30 07:32:35 +02:00
|
|
|
for d in ${instroot}/var/lib/pacman/*; do
|
|
|
|
[ "$(basename ${d})" != "local" ] && rm -rf "${d}"
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -e "${instroot}/boot" ]; then
|
|
|
|
rm -rf "${isoroot}/boot"
|
|
|
|
mv "${instroot}/boot" "${isoroot}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# Squash is the next step.
|
2006-09-12 20:14:17 +02:00
|
|
|
if [ "${command_name}" = "squash" -o "${command_name}" = "all" ]; then
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "====> Generating SquashFS image"
|
|
|
|
imagename="${isoroot}/archlive.sqfs"
|
|
|
|
if [ -e "${imagename}" ]; then
|
|
|
|
if [ "${FORCE}" = "y" ]; then
|
|
|
|
echo -n "Removing old squashfs image..."
|
|
|
|
rm "${imagename}"
|
|
|
|
echo "done."
|
|
|
|
else
|
|
|
|
echo "error: SquashFS image '${imagename}' already exists, aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
2006-08-30 07:32:35 +02:00
|
|
|
fi
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "Creating squashfs image. This may take some time..."
|
2006-08-30 07:32:35 +02:00
|
|
|
start=$(date +%s)
|
2007-10-10 06:50:11 +02:00
|
|
|
mksquashfs "${instroot}" "${imagename}"
|
|
|
|
minutes=$(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }')
|
|
|
|
echo "Image creation done in $minutes minutes."
|
2006-08-30 07:32:35 +02:00
|
|
|
fi
|
|
|
|
|
2007-10-10 06:50:11 +02:00
|
|
|
# Finally, make the iso.
|
2006-09-12 20:14:17 +02:00
|
|
|
if [ "${command_name}" = "iso" -o "${command_name}" = "all" ]; then
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "====> Making ISO image"
|
|
|
|
[ "x${isoname}" = "x" ] && (echo "ISO image name must be specified" && usage 1)
|
2006-09-28 04:15:25 +02:00
|
|
|
if [ -e "${isoname}" ]; then
|
|
|
|
if [ "${FORCE}" = "y" ]; then
|
|
|
|
rm -rf "${isoname}"
|
|
|
|
else
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "error: ISO image '${isoname}' already exists, aborting."
|
2006-09-28 04:15:25 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ ! -e "${CPIOCONFIG}" ]; then
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "error: mkinitcpio config '${CPIOCONFIG}' does not exist, aborting."
|
2006-09-28 04:15:25 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-08-30 07:32:35 +02:00
|
|
|
kernelver=$(_kversion)
|
|
|
|
basedir=${instroot}
|
|
|
|
[ "${instroot:0:1}" != "/" ] && basedir="$(pwd)/${instroot}"
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "Generating initcpio for ISO..."
|
2006-08-30 07:32:35 +02:00
|
|
|
if ! mkinitcpio -c "${CPIOCONFIG}" -b "${basedir}" -k "${kernelver}"\
|
|
|
|
-g "${isoroot}/boot/archlive.img"; then
|
2007-10-10 06:50:11 +02:00
|
|
|
echo "error: initcpio image creation failed..."
|
2006-08-30 07:32:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp ${instroot}/usr/lib/grub/i386-pc/* "${isoroot}/boot/grub"
|
|
|
|
|
|
|
|
echo "Creating ISO image..."
|
2006-09-12 20:14:17 +02:00
|
|
|
q=""
|
2006-09-28 04:15:25 +02:00
|
|
|
#[ "${QUIET}" = "y" ] && q="-q"
|
|
|
|
mkisofs ${q} -r -l -b "boot/grub/stage2_eltorito" -uid 0 -gid 0 -no-emul-boot \
|
2006-08-30 07:32:35 +02:00
|
|
|
-boot-load-size 4 -boot-info-table -publisher "Arch Linux <archlinux.org>" \
|
2006-09-12 20:14:17 +02:00
|
|
|
-input-charset=UTF-8 -p "prepared by $NAME" -A "Arch Linux Live/Rescue CD" \
|
|
|
|
-copyright /etc/copyright -o "${isoname}" "${isoroot}"
|
2006-08-30 07:32:35 +02:00
|
|
|
fi
|
2007-10-10 06:50:11 +02:00
|
|
|
|
|
|
|
# vim:ts=4:sw=4:et:
|