summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2011-07-03 18:21:36 +0200
committerDave Reisner <dreisner@archlinux.org>2011-07-04 22:11:31 +0200
commitab9e920b52ca2d178e174b04d89b3eec875deed7 (patch)
tree51ff373922a8c4fa3d1851299219de273c9e2dbb
parentc262a6dd486070018351b776d8612373590c2f74 (diff)
downloadmkinitcpio-ab9e920b52ca2d178e174b04d89b3eec875deed7.tar.gz
mkinitcpio-ab9e920b52ca2d178e174b04d89b3eec875deed7.tar.xz
mkinitcpio: refactor BASEDIR resolution
This should be performed first, to avoid false positives on any checks that would have been previously done before we knew our BASEDIR was valid. Remove usage of readlink here as well, and use pushd/pwd to resolve. The final trimming of any trailing slash (which might be the entire BASEDIR value) resolves an edge case bug where specifying a BASEDIR that resolved to '/' would cause explosions in add_symlink. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rwxr-xr-xmkinitcpio23
1 files changed, 12 insertions, 11 deletions
diff --git a/mkinitcpio b/mkinitcpio
index 289c98d..434172e 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -31,7 +31,8 @@ declare -a SKIPHOOKS ADDED_MODULES MODPATHS
PATH=$PATH:/sbin:/usr/sbin
# Sanitize environment further
# GREP_OPTIONS="--color=always" will break everything
-unset GREP_OPTIONS
+# CDPATH can affect cd and pushd
+unset GREP_OPTIONS CDPATH
usage() {
cat <<EOF
@@ -159,6 +160,16 @@ if [[ -t 2 ]] && (( COLOR )); then
fi
readonly NC BOLD BLUE GREEN RED YELLOW
+if [[ $BASEDIR ]]; then
+ # resolve the path. it might be a relative path and/or contain symlinks
+ if ! pushd "$BASEDIR" &>/dev/null; then
+ die "base directory '$BASEDIR' does not exist or is not a directory"
+ fi
+ BASEDIR=$(pwd -P)
+ BASEDIR=${BASEDIR%/}
+ popd &>/dev/null
+fi
+
if [[ $optkver ]]; then
if ! KERNELVERSION=$(get_kernver "$optkver"); then
die "'$optkver' is an invalid kernel specifier"
@@ -230,16 +241,6 @@ if [[ $PRESET ]]; then
fi
fi
-if [[ $BASEDIR ]]; then
- # resolve the path. it might be a relative path and/or contain symlinks
- abspath=$(readlink -e "$BASEDIR")
- if [[ -z $abspath ]]; then
- die "base directory '$BASEDIR' does not exist or is not a directory"
- fi
- BASEDIR=$abspath
- unset abspath
-fi
-
if [[ $GENIMG ]]; then
IMGPATH=$(readlink -f "$GENIMG")
if [[ -z $IMGPATH || ! -w ${IMGPATH%/*} ]]; then