return 1
}
+# Install a directory, keeping symlinks as on the original system.
+# Example: if /lib64 points to /lib on the host, "inst_dir /lib/file"
+# will create ${initdir}/lib64, ${initdir}/lib64/file,
+# and a symlink ${initdir}/lib -> lib64.
+inst_dir() {
+ local dir="$1"
+ [[ -e "${initdir}$dir" ]] && return 0
+
+ # iterate over parent directories
+ local file=""
+ local IFS="/"
+ for part in $dir; do
+ [ -z "$part" ] && continue
+ file="$file/$part"
+ [[ -e "${initdir}$file" ]] && continue
+
+ if [ -L "$file" ]; then
+ # create link as the original
+ local target=$(readlink "$file")
+ ln -sfn "$target" "${initdir}$file" || return 1
+ # resolve relative path and recursively install destionation
+ [[ "$target" = "${target##*/}" ]] && target="${file%/*}/$target"
+ inst_dir "$target"
+ else
+ # create directory
+ mkdir -p "${initdir}$file" || return 1
+ fi
+ done
+}
+
# $1 = file to copy to ramdisk
# $2 (optional) Name for the file on the ramdisk
# Location of the image dir is assumed to be $initdir
inst_simple() {
local src target
[[ -f $1 ]] || return 1
- src=$1 target=${initdir}${2:-$1}
- [[ -f $target ]] && return 0
- mkdir -p "${target%/*}"
+ src=$1 target="${2:-$1}"
+ [[ -f ${initdir}$target ]] && return 0
+ inst_dir "${target%/*}"
dinfo "Installing $src"
- cp -pfL "$src" "$target"
+ cp -fL "$src" "${initdir}$target"
}
# Same as above, but specialzed to handle dynamic libraries.
reallib=$(readlink -f "$src")
lib=${src##*/}
inst_simple "$reallib" "$reallib"
- mkdir -p "${initdir}${dest%/*}"
+ inst_dir "${dest%/*}"
(cd "${initdir}${dest%/*}" && ln -s "$reallib" "$lib")
else
inst_simple "$src" "$dest"
# create a function to install them to make life simpler.
inst_rules() {
local target=/etc/udev/rules.d
- mkdir -p "$initdir/lib/udev/rules.d" "$initdir$target"
+ inst_dir "/lib/udev/rules.d"
+ inst_dir "$target"
for rule in "$@"; do
rule=$(find_rule "$rule") && \
inst_simple "$rule" "$target/${rule##*/}"