From 70176ad2c847fdcf76e00de1eb438e6c5f2a6165 Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Sat, 4 Feb 2017 20:00:06 -0700 Subject: mkinitramfs:Convert cp calls to install Install supports -D and -m switches to create leading paths if they don't exist yet, and set destination permissions on copy. These make the script more reliable and shorter. Updated cache directory setup function to create fewer directories since the install command handles much of that now. Cleaned up some parent directory determination logic as a result of this new functionalty as well. Also added reboot command to binaries to be installed. --- mkinitramfs | 44 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/mkinitramfs b/mkinitramfs index 4c738bb..d7d3d61 100755 --- a/mkinitramfs +++ b/mkinitramfs @@ -126,27 +126,7 @@ function cache_dir_setup { # Clean the cache so we start fresh rm -rf ${cache} && mkdir ${cache} - local dirs=( - bin - dev - dev/disk - dev/disk/by-uuid - etc - lib - lib32 - lib64 - mnt/root - proc - root - run - sbin - sys - usr/lib - usr/lib64 - usr/lib32 - usr/bin - usr/sbin - ) + local dirs=(bin dev etc lib lib32 lib64 mnt/root proc root run sbin sys usr) # Create the temporary directory structure for i in ${dirs[*]}; do @@ -209,7 +189,7 @@ function main { # List of binaries to exist in the new initramfs resolve_bins \ bash cat echo ls cryptsetup chmod chown mount sleep umount clear cut \ - grep less tr which blkid shutdown switch_root + grep less tr which blkid reboot shutdown switch_root # Set up the archive source dir. @@ -220,28 +200,22 @@ function main { # Copy binary and dependencies to cache dir for bin in ${fqbins[@]}; do - bindirname=$(dirname ${bin}) # Copy the binary of interest - cp -u ${bin} "${cache}/${bindirname}/" + install -D "${bin}" "${cache}/${bin}" - deps=$(get_deps ${bin}) + local deps=$(get_deps ${bin}) # Copy each of the binary's deps for dep in ${deps[@]}; do - local depdirname=$(dirname ${dep}) - cp -u ${dep} "${cache}/${depdirname}/" - if [[ $? -gt 0 ]]; then - echo "Error: Problem copying ${dep} into ${cache}." - exit 1 - fi + install -D ${dep} "${cache}/${dep}" done done - # Copy in init script and add execute - cp ${res_path}/init ${cache}/init && chmod +x ${cache}/init # Copy in message file - cp ${res_path}/msg ${cache}/etc/msg + [[ -f ${res_path}/msg ]] && install -D ${res_path}/msg ${cache}/etc/msg + # Copy in init script and add execute + install -D -m 755 ${res_path}/init ${cache}/init # Copy in the system shell profile - cp /etc/profile ${cache}/etc/profile + install -D /etc/profile ${cache}/etc/profile # Create archive image mkcpio ${cache} ${version} -- cgit v1.2.3