From 28b191ea76efc0f8c39bc9159cdc10b72ddf8740 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 6 Jun 2011 18:54:49 -0400 Subject: mkinitcpio: refactor and bashify early path calculations This addresses a few issues with creation of images with a $BASEDIR, the most alarming that images would always be created on the real root filesystem, with no regard for any supplied base directory. This also cleans up some repetitive path declaration wrt BASEDIR and MODULEDIR. Signed-off-by: Dave Reisner --- mkinitcpio | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 95c7923..70c5d5e 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -172,7 +172,7 @@ if [[ $PRESET ]]; then preset_image=${p}_image if [[ ${!preset_image} ]]; then - preset_cmd+=(-g "${!preset_image}") + preset_cmd+=(-g "$BASEDIR${!preset_image}") else echo "==> No image file specified. Skipping image \"${p}\"." continue @@ -199,41 +199,42 @@ if [[ $PRESET ]]; then fi fi -# remove trailing / from BASEDIR -BASEDIR="${BASEDIR%/}" - -MODULEDIR="${BASEDIR}/lib/modules/${KERNELVERSION}" - -if [[ $GENIMG ]]; then - IMGPATH=$(readlink -f "$GENIMG") - if [[ -z $IMGPATH || ! -w ${IMGPATH%/*} ]]; then - echo "error: unable to write to path: '$GENIMG'" - cleanup - exit 1 - fi -fi - -if [ -n "${BASEDIR}" ]; then - if [ "${BASEDIR}" = "${BASEDIR#/}" ]; then - BASEDIR="$(pwd)/${BASEDIR}" - elif [ ! -d "${BASEDIR}" ]; then - echo "base directory '${BASEDIR}' does not exist or is not a directory" +if [[ $BASEDIR ]]; then + # resolve the path. it might be a relative path and/or contain symlinks + abspath=$(readlink -e "$BASEDIR") + if [[ -z $abspath ]]; then + echo "base directory '$BASEDIR' does not exist or is not a directory" cleanup exit 1 fi + BASEDIR=$abspath + unset abspath fi -if [ ! -f "${CONFIG}" ]; then - echo "config file '${CONFIG}' cannot be found, aborting..." +if [[ $GENIMG ]]; then + IMGPATH=$(readlink -f "$GENIMG") + if [[ -z $IMGPATH || ! -w ${IMGPATH%/*} ]]; then + echo "error: unable to write to path: '$GENIMG'" + cleanup + exit 1 + fi +fi + +if [[ ! -f "$CONFIG" ]]; then + echo "config file '$CONFIG' cannot be found, aborting..." cleanup exit 1 fi -. "${CONFIG}" +. "$CONFIG" -BASEDIR=${BASEDIR//+(\/)//} -MODULEDIR=${MODULEDIR//+(\/)//} +MODULEDIR=$BASEDIR/lib/modules/$KERNELVERSION +if [[ ! -d $MODULEDIR ]]; then + echo "error: '$MODULEDIR' is not a valid kernel module directory" + cleanup + exit 1 +fi -. "${FUNCTIONS}" +. "$FUNCTIONS" if [ "${SHOW_AUTOMODS}" = "y" ]; then echo "Modules autodetected:" -- cgit v1.2.3-24-g4f1b