summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-06-07 00:54:49 +0200
committerDave Reisner <d@falconindy.com>2011-06-16 22:16:47 +0200
commit28b191ea76efc0f8c39bc9159cdc10b72ddf8740 (patch)
tree973e611a783025a7977466f58eb29904e884df95
parentb9904b535a4ead62a125bacde38e55c570aacb32 (diff)
downloadmkinitcpio-28b191ea76efc0f8c39bc9159cdc10b72ddf8740.tar.gz
mkinitcpio-28b191ea76efc0f8c39bc9159cdc10b72ddf8740.tar.xz
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 <d@falconindy.com>
-rwxr-xr-xmkinitcpio53
1 files 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:"