summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functions25
-rw-r--r--mkinitcpio.8.txt9
2 files changed, 24 insertions, 10 deletions
diff --git a/functions b/functions
index 4f25a86..8a270fd 100644
--- a/functions
+++ b/functions
@@ -402,22 +402,33 @@ add_dir() {
}
add_symlink() {
- # Add a symlink to the initcpio image.
+ # Add a symlink to the initcpio image. There is no checking done
+ # to ensure that the target of the symlink exists.
# $1: pathname of symlink on image
- # $2: absolute path to target of symlink
+ # $2: absolute path to target of symlink (optional, can be read from $1)
- (( $# == 2 )) || return 1
+ local name_=$1 target_=$2
- add_dir "${1%/*}"
+ (( $# == 1 || $# == 2 )) || return 1
+
+ if [[ -z $target_ ]]; then
+ target_=$(readlink -f "$name_")
+ if [[ -z $target_ ]]; then
+ error 'invalid symlink: %s' "$name_"
+ return 1
+ fi
+ fi
+
+ add_dir "${name_%/*}"
if (( ! QUIET )); then
if [[ -L $BUILDROOT$1 ]]; then
- plain "overwriting symlink %s -> %s" "$1" "$2"
+ plain "overwriting symlink %s -> %s" "$name_" "$target_"
else
- plain "adding symlink: %s -> %s" "$1" "$2"
+ plain "adding symlink: %s -> %s" "$name_" "$target_"
fi
fi
- ln -sfn "$2" "$BUILDROOT$1"
+ ln -sfn "$target_" "$BUILDROOT$name_"
}
add_file() {
diff --git a/mkinitcpio.8.txt b/mkinitcpio.8.txt
index a33869d..efa385f 100644
--- a/mkinitcpio.8.txt
+++ b/mkinitcpio.8.txt
@@ -131,10 +131,13 @@ functions exist to facilitate this.
calling *add_file*, *add_dir*, and *add_symlink* accordingly. This function
will not follow symlinks, nor will it add the targets of symlinks.
-*add_symlink* 'path' 'link-target'::
+*add_symlink* 'path' [ 'link-target' ]::
- Adds a symlink to the image at the specified `path`, pointing to the specified
- `link-target`.
+ Adds a symlink to the image at the specified `path`, optionally pointing to
+ the specified `link-target`. If the `link-target` is not provided, it is assumed
+ that this symlink exists in the real filesystem, and the target will be read
+ using readlink. There is no checking done to ensure that the target of the
+ symlink exists, and symlinks will not be followed recursively.
*add_all_modules* [ '-f filter' ] *pattern*::