diff options
author | Aaron Ball <nullspoon@iohq.net> | 2016-02-24 00:34:41 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@iohq.net> | 2016-02-24 00:34:41 -0700 |
commit | d9140c41b7d7ee956b8f72d09b6467ea8ff604f8 (patch) | |
tree | a066f7a3f27926b619fc9aa28d468abf6a9088fa | |
parent | 432ba80152b18a4ed37da6d3c823d17f41230800 (diff) | |
parent | 1a14de94b5b40324d2633e3e77feb7f80cd4e1f3 (diff) | |
download | mkinitramfs-d9140c41b7d7ee956b8f72d09b6467ea8ff604f8.tar.gz mkinitramfs-d9140c41b7d7ee956b8f72d09b6467ea8ff604f8.tar.xz |
Merge branch 'bin_resolver'
-rw-r--r-- | mkinitramfs | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/mkinitramfs b/mkinitramfs index a26c367..b7b63b3 100644 --- a/mkinitramfs +++ b/mkinitramfs @@ -1,5 +1,9 @@ #!/usr/bin/env bash +# Hash of fully-qualified binaries +declare -a fqbins + + function get_bin_deps { [[ -z ${1} ]] && echo 'Binary path required.\n' & exit 1 @@ -8,6 +12,35 @@ function get_bin_deps { # +# Searches PATH for all binaries listed as function arguments. Each found +# binary is then put into the global "bins" array. +# +# This function also serves to ensure all specified binaries are present and +# in PATH. It will exit code 1 with an error message if any binaries are not +# found. +# +# Note: To use this function, insert "declare -a fqbins" at top of script). +# +# @param bins All function arguments are the names of binaries to locate. +# +function resolve_bins { + local args=${@} + + for i in ${args[@]}; do + local path=$(which ${i} 2>/dev/null) + + if [[ $? -gt 0 ]]; then + echo "Could not find binary ${i}. Is it installed?" + exit 1 + fi + + echo "Located ${i} at ${path}" + fqbins+=("${path}") + done +} + + +# # Gets first path locatable in a string # function get_first_path { @@ -132,34 +165,17 @@ function main { local res_path=/usr/share/mkinitramfs/ # List of binaries to exist in the new initramfs - local bins=( - /bin/bash - /bin/cat - /bin/echo - /bin/ls - /usr/sbin/cryptsetup - /bin/chmod - /bin/chown - /bin/mount - /bin/sleep - /bin/umount - /usr/bin/clear - /usr/bin/cut - /usr/bin/grep - /usr/bin/less - /usr/bin/tr - /usr/bin/which - /sbin/blkid - /sbin/shutdown - /sbin/switch_root - ) + resolve_bins \ + bash cat echo ls cryptsetup chmod chown mount sleep umount clear cut \ + grep less tr which blkid shutdown switch_root + cache_dir_setup ${cache} check_crypto_support ${version} # Copy binary and dependencies locally - for bin in ${bins[@]}; do + for bin in ${fqbins[@]}; do bindirname=$(dirname ${bin}) # Copy the binary of interest cp -u ${bin} "${cache}/${bindirname}/" |