A bunch of those first-glance type updates
Some new eyes on the code, and finding some new things to fix up. A lot of documentation type stuff with some code commenting. Make the message and echo stuff a bit more consistant. Move the UID check later so that we can see help as a normal user. Other small fixups. Signed-off-by: Dan McGee <dan@archlinux.org> Signed-off-by: Simo Leone <simo@archlinux.org>
This commit is contained in:
parent
695951bb8f
commit
fccb39dcd8
7
TODO
7
TODO
@ -10,3 +10,10 @@
|
|||||||
* push to projects.archlinux.org
|
* push to projects.archlinux.org
|
||||||
|
|
||||||
* win.
|
* win.
|
||||||
|
|
||||||
|
* (Dan) We should have the ability to add packages in two ways- package lists
|
||||||
|
that pull from the sync DBs (-S), and packages files as well (-U).
|
||||||
|
|
||||||
|
* (Dan) Pacman DBs should not have to be synced multiple times (one for each
|
||||||
|
package list + kernel). They should be synced the first time and that should
|
||||||
|
cover our bases. This may be a pacman bug.
|
||||||
|
98
mkarchiso
98
mkarchiso
@ -10,31 +10,27 @@ command_name=""
|
|||||||
work_dir=""
|
work_dir=""
|
||||||
isoname=""
|
isoname=""
|
||||||
|
|
||||||
PKGDIR="."
|
PKGDIR="$(pwd)"
|
||||||
|
|
||||||
APPNAME=$(basename "${0}")
|
APPNAME=$(basename "${0}")
|
||||||
|
|
||||||
if [ "$EUID" != "0" ]; then
|
# usage: usage <exitvalue>
|
||||||
echo "This script must be run as root."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
usage ()
|
usage ()
|
||||||
{
|
{
|
||||||
echo "usage ${APPNAME} [options] command <command options>"
|
echo "usage ${APPNAME} [options] command <command options>"
|
||||||
echo " general options:"
|
echo " general options:"
|
||||||
echo " -c CONFIG Use CONFIG file. default: /etc/archlive/mkarchiso.conf"
|
echo " -c CONFIG Use CONFIG file. default: ${CONFIG}"
|
||||||
echo " -i CPIO CONFIG Use CONFIG file for mkinitcpio. default: /etc/archlive/mkinitcpio.conf"
|
echo " -i CPIO_CONFIG Use CONFIG file for mkinitcpio. default: ${CPIOCONFIG}"
|
||||||
echo " -p PKGFILE DIR Look for package list files in DIR. default: ."
|
echo " -p PKGFILE_DIR Look for package list files in DIR. default: ${PKGDIR}"
|
||||||
echo " -f Force overwrite of working files / iso"
|
echo " -f Force overwrite of working files/squashfs image/iso"
|
||||||
echo " -v Verbose output. Default: no"
|
echo " -v Verbose output. Default: no"
|
||||||
echo " -h This message."
|
echo " -h This message"
|
||||||
echo " commands:"
|
echo " commands:"
|
||||||
echo " install <working dir> : where to build the ISO root"
|
echo " install <working dir> : where to build the ISO root"
|
||||||
echo " squash <working dir> : generate a squashfs image of the ISO root"
|
echo " squash <working dir> : generate a squashfs image of the ISO root"
|
||||||
echo " iso <working dir> <iso name> : build an iso from the working directory"
|
echo " iso <working dir> <iso name> : build an ISO from the working directory"
|
||||||
echo " all <working dir> <iso name> : perform all of the above, in order"
|
echo " all <working dir> <iso name> : perform all of the above, in order"
|
||||||
exit 1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts 'c:i:p:fvh' arg; do
|
while getopts 'c:i:p:fvh' arg; do
|
||||||
@ -44,14 +40,21 @@ while getopts 'c:i:p:fvh' arg; do
|
|||||||
p) PKGDIR="${OPTARG}" ;;
|
p) PKGDIR="${OPTARG}" ;;
|
||||||
f) FORCE="y" ;;
|
f) FORCE="y" ;;
|
||||||
v) QUIET="n" ;;
|
v) QUIET="n" ;;
|
||||||
h|?) usage ;;
|
h|?) usage 0 ;;
|
||||||
*) echo "invalid argument '${arg}'"; usage ;;
|
*) echo "invalid argument '${arg}'"; usage 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
shift $(($OPTIND - 1))
|
shift $(($OPTIND - 1))
|
||||||
echo "ARGS: $@"
|
echo "ARGS: $@"
|
||||||
|
|
||||||
[ $# -le 1 ] && usage
|
[ $# -le 1 ] && usage 1
|
||||||
|
|
||||||
command_name="${1}"
|
command_name="${1}"
|
||||||
case "${command_name}" in
|
case "${command_name}" in
|
||||||
@ -59,16 +62,16 @@ case "${command_name}" in
|
|||||||
squash) work_dir="${2}" ;;
|
squash) work_dir="${2}" ;;
|
||||||
iso) work_dir="${2}"; isoname="${3}" ;;
|
iso) work_dir="${2}"; isoname="${3}" ;;
|
||||||
all) work_dir="${2}"; isoname="${3}" ;;
|
all) work_dir="${2}"; isoname="${3}" ;;
|
||||||
*) echo "invalid command name '${command_name}'"; usage ;;
|
*) echo "invalid command name '${command_name}'"; usage 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[ "x${work_dir}" = "x" ] && (echo "please specify a working directory" && usage)
|
[ "x${work_dir}" = "x" ] && (echo "please specify a working directory" && usage 1)
|
||||||
|
|
||||||
#TODO - do we even need a config file?
|
#TODO - do we even need a config file?
|
||||||
if [ -e "${CONFIG}" ]; then
|
if [ -e "${CONFIG}" ]; then
|
||||||
source "${CONFIG}"
|
source "${CONFIG}"
|
||||||
else
|
else
|
||||||
echo "Config '${CONFIG}' does not exist, aborting..."
|
echo "error: Config '${CONFIG}' does not exist, aborting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -82,6 +85,7 @@ _kversion ()
|
|||||||
echo ${ALL_kver}
|
echo ${ALL_kver}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# usage: _pacman <packages>...
|
||||||
_pacman ()
|
_pacman ()
|
||||||
{
|
{
|
||||||
if ! mkarchroot -f ${instroot} $*; then
|
if ! mkarchroot -f ${instroot} $*; then
|
||||||
@ -89,6 +93,7 @@ _pacman ()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# usage: install_pkgfile <packagesfile>
|
||||||
install_pkgfile ()
|
install_pkgfile ()
|
||||||
{
|
{
|
||||||
if [ -e "${1}" ]; then
|
if [ -e "${1}" ]; then
|
||||||
@ -99,14 +104,17 @@ install_pkgfile ()
|
|||||||
done < ${1}
|
done < ${1}
|
||||||
_pacman "${toinstall}"
|
_pacman "${toinstall}"
|
||||||
else
|
else
|
||||||
echo "Package file '${1}' does not exist, aborting..."
|
echo "error: Package file '${1}' does not exist, aborting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Go through the main commands in order. If 'all' was specified, then we want
|
||||||
|
# to do everything. Start with 'install'.
|
||||||
if [ "${command_name}" = "install" -o "${command_name}" = "all" ]; then
|
if [ "${command_name}" = "install" -o "${command_name}" = "all" ]; then
|
||||||
|
echo "====> Installing/building ISO root"
|
||||||
if [ -e "${work_dir}" -a "${FORCE}" = "n" ]; then
|
if [ -e "${work_dir}" -a "${FORCE}" = "n" ]; then
|
||||||
echo "Working dir '${work_dir}' already exists, aborting..."
|
echo "error: Working dir '${work_dir}' already exists, aborting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -125,7 +133,7 @@ if [ "${command_name}" = "install" -o "${command_name}" = "all" ]; then
|
|||||||
|
|
||||||
echo "Installing kernel '${kernelpkg}'"
|
echo "Installing kernel '${kernelpkg}'"
|
||||||
if ! _pacman "${kernelpkg}" ; then
|
if ! _pacman "${kernelpkg}" ; then
|
||||||
echo "pacman failed to install '${kernelpkg}', aborting..."
|
echo "error: pacman failed to install '${kernelpkg}', aborting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
kernelver=$(_kversion)
|
kernelver=$(_kversion)
|
||||||
@ -140,12 +148,12 @@ if [ "${command_name}" = "install" -o "${command_name}" = "all" ]; then
|
|||||||
depmod -a -b "${instroot}" -v "${kernelver}" -F "${instroot}/boot/System.map26${kernelsuffix}" >/dev/null
|
depmod -a -b "${instroot}" -v "${kernelver}" -F "${instroot}/boot/System.map26${kernelsuffix}" >/dev/null
|
||||||
find "${instroot}/boot" -name *.img -delete #TODO, will this delete our special stuff?
|
find "${instroot}/boot" -name *.img -delete #TODO, will this delete our special stuff?
|
||||||
|
|
||||||
echo "Applying default configuration for the Arch ISO."
|
echo "Applying default configuration for the Arch ISO"
|
||||||
cp -rfa ${DEF_CONFIG_DIR}/* "${instroot}"
|
cp -rfa ${DEF_CONFIG_DIR}/* "${instroot}"
|
||||||
|
|
||||||
echo "Copyright (C) 2006, Arch Linux (Judd Vinet)" > "${instroot}/etc/copyright"
|
echo "Copyright (C) 2007, Arch Linux (Judd Vinet)" > "${instroot}/etc/copyright"
|
||||||
|
|
||||||
echo "Creating initial device nodes "
|
echo "Creating initial device nodes"
|
||||||
rm -f "${instroot}/dev/console" "${instroot}/dev/null" "${instroot}/dev/zero"
|
rm -f "${instroot}/dev/console" "${instroot}/dev/null" "${instroot}/dev/zero"
|
||||||
mknod -m 644 "${instroot}/dev/console" c 5 1
|
mknod -m 644 "${instroot}/dev/console" c 5 1
|
||||||
mknod -m 666 "${instroot}/dev/null" c 1 3
|
mknod -m 666 "${instroot}/dev/null" c 1 3
|
||||||
@ -158,6 +166,7 @@ if [ "${command_name}" = "install" -o "${command_name}" = "all" ]; then
|
|||||||
echo "Cleaning up ISO root files..."
|
echo "Cleaning up ISO root files..."
|
||||||
find "${instroot}" -name *.pacnew -name *.pacsave -name *.pacorig -delete
|
find "${instroot}" -name *.pacnew -name *.pacsave -name *.pacorig -delete
|
||||||
|
|
||||||
|
# delete a lot of unnecessary cache/log files
|
||||||
kill_dirs="var/abs var/cache/man var/cache/pacman var/log/* var/mail tmp/* usr/include initrd"
|
kill_dirs="var/abs var/cache/man var/cache/pacman var/log/* var/mail tmp/* usr/include initrd"
|
||||||
for x in ${kill_dirs}; do
|
for x in ${kill_dirs}; do
|
||||||
if [ -e "${instroot}/${x}" ]; then
|
if [ -e "${instroot}/${x}" ]; then
|
||||||
@ -165,10 +174,11 @@ if [ "${command_name}" = "install" -o "${command_name}" = "all" ]; then
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# delete static libraries
|
||||||
find "${instroot}/lib" -name *.a -delete
|
find "${instroot}/lib" -name *.a -delete
|
||||||
find "${instroot}/usr/lib" -name *.a -delete
|
find "${instroot}/usr/lib" -name *.a -delete
|
||||||
|
|
||||||
# this actually takes up alot of space...
|
# pacman DBs are big, delete all sync dbs
|
||||||
for d in ${instroot}/var/lib/pacman/*; do
|
for d in ${instroot}/var/lib/pacman/*; do
|
||||||
[ "$(basename ${d})" != "local" ] && rm -rf "${d}"
|
[ "$(basename ${d})" != "local" ] && rm -rf "${d}"
|
||||||
done
|
done
|
||||||
@ -179,40 +189,52 @@ if [ "${command_name}" = "install" -o "${command_name}" = "all" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Squash is the next step.
|
||||||
if [ "${command_name}" = "squash" -o "${command_name}" = "all" ]; then
|
if [ "${command_name}" = "squash" -o "${command_name}" = "all" ]; then
|
||||||
if [ -e "${isoroot}/archlive.sqfs" ]; then
|
echo "====> Generating SquashFS image"
|
||||||
echo -n "Removing old squashfs image..."
|
imagename="${isoroot}/archlive.sqfs"
|
||||||
rm "${isoroot}/archlive.sqfs"
|
if [ -e "${imagename}" ]; then
|
||||||
echo "done."
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "Creating squashfs image. This may take some time..."
|
echo "Creating squashfs image. This may take some time..."
|
||||||
start=$(date +%s)
|
start=$(date +%s)
|
||||||
mksquashfs "${instroot}" "${isoroot}/archlive.sqfs" -root-owned > /dev/null
|
mksquashfs "${instroot}" "${imagename}"
|
||||||
echo "done in $(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }') minutes."
|
minutes=$(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }')
|
||||||
|
echo "Image creation done in $minutes minutes."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Finally, make the iso.
|
||||||
if [ "${command_name}" = "iso" -o "${command_name}" = "all" ]; then
|
if [ "${command_name}" = "iso" -o "${command_name}" = "all" ]; then
|
||||||
[ "x${isoname}" = "x" ] && (echo "please specify an iso name" && usage)
|
echo "====> Making ISO image"
|
||||||
|
[ "x${isoname}" = "x" ] && (echo "ISO image name must be specified" && usage 1)
|
||||||
if [ -e "${isoname}" ]; then
|
if [ -e "${isoname}" ]; then
|
||||||
if [ "${FORCE}" = "y" ]; then
|
if [ "${FORCE}" = "y" ]; then
|
||||||
rm -rf "${isoname}"
|
rm -rf "${isoname}"
|
||||||
else
|
else
|
||||||
echo "ISO Image '${isoname}' already exists, aborting..."
|
echo "error: ISO image '${isoname}' already exists, aborting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ ! -e "${CPIOCONFIG}" ]; then
|
if [ ! -e "${CPIOCONFIG}" ]; then
|
||||||
echo "mkinitcpio config '${CPIOCONFIG}' does not exist, aborting..."
|
echo "error: mkinitcpio config '${CPIOCONFIG}' does not exist, aborting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kernelver=$(_kversion)
|
kernelver=$(_kversion)
|
||||||
basedir=${instroot}
|
basedir=${instroot}
|
||||||
[ "${instroot:0:1}" != "/" ] && basedir="$(pwd)/${instroot}"
|
[ "${instroot:0:1}" != "/" ] && basedir="$(pwd)/${instroot}"
|
||||||
|
echo "Generating initcpio for ISO..."
|
||||||
if ! mkinitcpio -c "${CPIOCONFIG}" -b "${basedir}" -k "${kernelver}"\
|
if ! mkinitcpio -c "${CPIOCONFIG}" -b "${basedir}" -k "${kernelver}"\
|
||||||
-g "${isoroot}/boot/archlive.img"; then
|
-g "${isoroot}/boot/archlive.img"; then
|
||||||
echo "initcpio image creation failed..."
|
echo "error: initcpio image creation failed..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -226,3 +248,5 @@ if [ "${command_name}" = "iso" -o "${command_name}" = "all" ]; then
|
|||||||
-input-charset=UTF-8 -p "prepared by $NAME" -A "Arch Linux Live/Rescue CD" \
|
-input-charset=UTF-8 -p "prepared by $NAME" -A "Arch Linux Live/Rescue CD" \
|
||||||
-copyright /etc/copyright -o "${isoname}" "${isoroot}"
|
-copyright /etc/copyright -o "${isoname}" "${isoroot}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# vim:ts=4:sw=4:et:
|
||||||
|
Loading…
Reference in New Issue
Block a user