From 99b861b27b51a0af01c1eaef4df48c67ca1fffc4 Mon Sep 17 00:00:00 2001 From: sbkelley Date: Thu, 28 May 2026 00:18:58 -0400 Subject: [PATCH] replace cpbin with cpbin from Makefile branch (cherry picked from commit a66fefce7bdfe86799e6c74bd7090942b49829cb) --- cpbin | 210 ++++++++++++++++++++++++++++++++++++++++++++----------- findlibs | 10 +++ sanepath | 5 ++ 3 files changed, 186 insertions(+), 39 deletions(-) create mode 100644 findlibs create mode 100644 sanepath diff --git a/cpbin b/cpbin index a389b94..860959b 100644 --- a/cpbin +++ b/cpbin @@ -1,51 +1,152 @@ #!/bin/bash +# cpbin copies a binary and its necessary libraries into a given directory. +# The purpose is to aid in preparing chroots. +# +# It doesn't do any other preparation of the directory as a chroot; it only +# copies bins and libs. +# +# refactored out of original dgl-create-chroot +# +# cpbin [OPTIONS] BINARY [DIRECTORY] +# +# [DIRECTORY] defaults to "$HOME/chroot" +# +# OPTIONS +# --bindir [dir] Sets BINDIR, the directory for the binary to live. +# Defaults to the binary's dirname. +# Path is from inside the chroot! So -b /bin will +# install binaries in //bin + +# --libdir [dir] Sets LIBDIR, the directory for libraries to live. +# Defaults to the library's dirname, for each library. +# Path is from inside the chroot! See above. + +# --only-libs Causes the program to refrain from copying the +# binaries; it only copies libraries. It still makes +# the directory, unless DRYRUN is set. + +# --only-bin Causes the program to refrain from copying the +# libraries; it only copies binaries. It still makes +# the directory, unless DRYRUN is set. + +# --only-dirs Creates the requisite directory structure only. Does +# not copy any files. Equivalent to setting both +# NOBIN and NOLIBS. + +# --dry Causes the program to output what it would do, +# ie it had not received the --dry option. ie do nothing + +# --quiet Causes the program to refrain from making extraneous +# noises. + +# --really-quiet Causes the program to refrain from even reporting +# errors... + +# --help Display this help message. +# ^^ line 46 + set -e +umask 022 -## All of these were written for dgl-create-chroot -# findlibs from original dgl-create-chroot -findlibs() -{ - for i in "$@"; do - if [ -z "`ldd "$i" | grep 'not a dynamic executable'`" ]; then - echo $(ldd "$i" | awk '{ print $3 }' | egrep -v ^'\(') - echo $(ldd "$i" | grep 'ld-linux' | awk '{print $1}') - fi - done +##### Some other programs +cpbindir=`dirname $0` +sanepath=$cpbindir/sanepath +findlibs=$cpbindir/findlibs +cpbinname="cpbin" + +##### functions +# Echo a message absent the QUIET env var. +say() { [ "$QUIET" -lt 2 ] && printf "$cpbinname: $1\n" || :; } + +# Echo a message to stderr. +err() { [ "$QUIET" -lt 1 ] && >&2 echo "$cpbinname - ERROR: $1" || :; } + +# Echo to stderr and exit 1. +errexit() { err "$1"; exit 1; } + +# mkdirif