Last active
July 31, 2022 19:40
-
-
Save Fusion/fd9f88cb2365095f50f6e46df3756d8a to your computer and use it in GitHub Desktop.
Awful script to quickly put together a "portable-enough" binary for decrepit Gentoo setups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
verbose=0 | |
blacklist=("linux-vdso.so.1" "libc.so.6" "libm.so.6" "/lib64/ld-linux-x86-64.so.2" "libpthread.so.0") | |
copied=() | |
grab_deps() { | |
[ $verbose -ne 0 ] && { echo "Processing: $2"; } | |
processed=() | |
while read row; do | |
read -r depname _ deppath _ <<< $row | |
[[ " ${blacklist[@]} " =~ " ${depname} " ]] && { continue; } | |
[[ " ${copied[@]} " =~ " ${depname} " ]] && { continue; } | |
[ "$deppath" == "" ] && { deppath="$depname"; } | |
cp $deppath $1/lib/$depname | |
processed+=($1/lib/$depname) | |
copied+=($depname) | |
done < <(ldd $2) | |
for item in "${processed[@]}"; do | |
grab_deps $1 $item | |
done | |
} | |
[ "$1" == "-v" ] && { verbose=1; shift; } | |
[ "$1" == "" ] && { echo "Please provide a binary as an argument."; exit 1; } | |
[ -f $1 ] && { binpath=$1; } || { binpath=$(which $1); [ $? -ne 0 ] && { echo "Unable to find binary."; exit 1; } } | |
pkgname=$(basename $1) | |
mkdir -p $pkgname/bin $pkgname/lib | |
cp $binpath $pkgname/bin/exe | |
grab_deps $pkgname $pkgname/bin/exe | |
res=$? | |
[ $res -eq 0 ] || { exit $res; } | |
cat > $pkgname/run.sh <<- "EOB" | |
#!/bin/sh | |
loc=$(dirname "$0") | |
export LD_LIBRARY_PATH="${loc}/lib" | |
exec "${loc}/bin/exe" "$@" | |
EOB | |
chmod +x $pkgname/run.sh | |
tar zcf ${pkgname}.tgz $pkgname | |
echo -e "\nDone.\nGenerated ${pkgname}.tgz\nHope it works!\nPush to server, unpack, symlink using e.g. 'ln -s $pkgname/run.sh /usr/bin/$pkgname'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment