Commit bace2ef8 authored by jberryman's avatar jberryman

utility for unpacking/repacking ar library files

parent 7e2ed2a5
#!/usr/bin/zsh
# Not portable, sorry...
set -e
set -o pipefail
# set -x
# Another variation on these reopt script. THis unpacks an archive and pauses
# while the programmer fiddles with it, then repacks and backs up original.
# Calls `reopt` on objects in archive and repacks
TARGET_AR=$(realpath "$@")
echo -n "$TARGET_AR: "
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
# Individual libraries can and do have identical names, which makes this a huge pain.
# We unpack each member into a separate numbered directory, and repack in the same order
O_NUM=1
for cnt nm in `ar t "$TARGET_AR" | sort | uniq -c`; do
for c in {1..$cnt}; do
mkdir $O_NUM
cd $O_NUM
ar xN $c "$TARGET_AR" $nm
cd ..
((O_NUM++))
done
done
echo
echo "Pausing while you fiddle with contents of $TARGET_AR, unpacked at:"
echo " $TMP_DIR"
read "?Enter to continue and repack"
# rearchive; use zsh numeric blob qualifier.
ar cq repackaged.a */*(n)
# Backup original
cp --force --backup=numbered "$TARGET_AR" "$TARGET_AR"
cp repackaged.a "$TARGET_AR"
rm -r "$TMP_DIR"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment