diff options
author | David Härdeman <david@hardeman.nu> | 2007-05-01 19:25:27 +0200 |
---|---|---|
committer | maximilian attems <maks@debian.org> | 2007-05-01 19:25:27 +0200 |
commit | 97463b8108d05b33a09d8847c7f4d7c1be7e41db (patch) | |
tree | 930c29c7d3d1f843877a4806142213f7b7dfbf35 /hook-functions | |
parent | 8800b09a519db23e0fefd32868a57c45c0a013e8 (diff) | |
download | initramfs-tools-97463b8108d05b33a09d8847c7f4d7c1be7e41db.tar.gz initramfs-tools-97463b8108d05b33a09d8847c7f4d7c1be7e41db.zip |
hook-funtions: copy_exec work
* Change copy_exec to use the same source and
destination path if only one argument is given.
* document how copy_exec determines the target path.
This also fixes a minor bug, these two commands:
copy_exec /some/thing /thing
copy_exec /some/other/thing /thing
Would previously print (note the incorrect path):
W:copy_exec: Not copying /some/other/thing to $DESTDIR/thing/thing...
Diffstat (limited to 'hook-functions')
-rw-r--r-- | hook-functions | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/hook-functions b/hook-functions index 12faeff..6c75b5f 100644 --- a/hook-functions +++ b/hook-functions @@ -55,24 +55,55 @@ manual_add_modules() done } -# $1 is source -# $2 is relative destination +# $1 is the source path (e.g. /usr/bin/time) +# $2 is the relative destination (e.g. /usr or /usr/time) +# +# The destination is interpreted in the same way "cp" would, meaning +# (assuming /bin is a directory): +# +# "copy_exec /usr/bin/time /bin" -> /bin/time +# "copy_exec /usr/bin/time /bin/mytime" -> /bin/mytime +# +# If $2 is left out, the same destination path as for the source arg will +# be used and directories will be created as needed, so: +# +# "copy_exec /usr/bin/time" -> /usr/bin/time +# copy_exec() { - final_destination=${DESTDIR}/${2}/`basename ${1}` + local source target destination final_destination x nonoptlib + local libname dirname + + source="${1}" + if [ -n "${2}" ]; then + target="${2}" + else + if [ ! -e "${DESTDIR}/$(dirname "${1}")" ]; then + mkdir -p "${DESTDIR}/$(dirname "${1}")" + fi + target="${1}" + fi + + if [ -d "${DESTDIR}/${target}" ]; then + destination="${target}/$(basename "${source}")" + else + destination="${target}" + fi + final_destination="${DESTDIR}/${destination}" + if [ -L "$final_destination" ]; then - if ! [ `readlink ${final_destination}` = "${1}" ]; then - echo "W:copy_exec: Not copying ${1} to \$DESTDIR${2}/`basename ${1}`, which is already a copy of `readlink ${final_destination}`" >&2 + if [ $(readlink "${final_destination}") != "${source}" ]; then + echo "W:copy_exec: Not copying ${source} to \$DESTDIR${destination}, which is already a copy of $(readlink ${final_destination})" >&2 return fi else - ln -s ${1} ${DESTDIR}/${2} - if [ -n "${verbose}" ] && [ "${verbose}" = "y" ]; then - echo "Adding binary ${1}" + ln -s ${source} ${DESTDIR}/${destination} + if [ "${verbose}" = "y" ]; then + echo "Adding binary ${source}" fi fi # Copy the dependant libraries - for x in $(ldd ${1} 2>/dev/null | sed -e ' + for x in $(ldd ${source} 2>/dev/null | sed -e ' /\//!d; /linux-gate/d; /=>/ {s/.*=>[[:blank:]]*\([^[:blank:]]*\).*/\1/}; @@ -80,19 +111,19 @@ copy_exec() { # Try to use non-optimised libraries where possible. # We assume that all HWCAP libraries will be in tls. - nonoptlib=$(echo ${x} | sed -e 's#/lib/tls.*/\(lib.*\)#/lib/\1#') + nonoptlib=$(echo "${x}" | sed -e 's#/lib/tls.*/\(lib.*\)#/lib/\1#') - if [ -e ${nonoptlib} ]; then - x=${nonoptlib} + if [ -e "${nonoptlib}" ]; then + x="${nonoptlib}" fi - libname=$(basename ${x}) - dirname=$(dirname ${x}) + libname=$(basename "${x}") + dirname=$(dirname "${x}") - mkdir -p ${DESTDIR}/${dirname} - if [ ! -e ${DESTDIR}/${dirname}/${libname} ]; then - ln -s ${x} ${DESTDIR}/${dirname} - if [ -n "${verbose}" ] && [ "${verbose}" = "y" ]; then + mkdir -p "${DESTDIR}/${dirname}" + if [ ! -e "${DESTDIR}/${dirname}/${libname}" ]; then + ln -s "${x}" "${DESTDIR}/${dirname}" + if [ "${verbose}" = "y" ]; then echo "Adding library ${x}" fi fi |