Skip to content

Instantly share code, notes, and snippets.

@TheFlash2k
Created December 9, 2023 23:42
Show Gist options
  • Save TheFlash2k/79e44f3ae4c5d500dd687255b9c77365 to your computer and use it in GitHub Desktop.
Save TheFlash2k/79e44f3ae4c5d500dd687255b9c77365 to your computer and use it in GitHub Desktop.
Install any version of GLIBC, configure automatically and setup an alias to patch binaries using that version.
#!/bin/bash
######### YOU CAN CHANGE THESE ############
TMP_FOLDER="/tmp"
INSTALL_FOLDER="/opt"
BASE_URL="https://ftp.gnu.org"
RC_FILE=`echo ~/.my_functions`
if [ ! -f $RC_FILE ]; then
touch $RC_FILE
chmod +x $RC_FILE
fi
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root."
exit 1
fi
set -e
function show_patcher() {
echo -e "Please add the following function to the rc file:\n"
echo "function patchbin_$1() {" | tee -a $RC_FILE
echo " patchelf --set-interpreter $INSTALL_FOLDER/glibc-$1/lib/ld-linux-x86-64.so.2 --set-rpath $INSTALL_FOLDER/glibc-$1/ \$1" | tee -a $RC_FILE
echo "}" | tee -a $RC_FILE
echo -e "\nAlso, the function has been added to $RC_FILE. You can source it if you want."
}
if [[ -z $1 ]]; then
echo "No arguments provided. Please provide the libc version you want to install"
exit 1
fi
version=$1
ver_name=`echo $1 | tr '.' '-'`
echo "Downloading GLIBC $version"
cd /tmp/
file="glibc-$version"
tar_file="$file.tar.gz"
wget -c $BASE_URL/gnu/glibc/$tar_file
tar -zxvf $tar_file && cd $file
mkdir glibc-build && cd glibc-build
../configure --prefix="$INSTALL_FOLDER/glibc-$ver_name" --disable-werror
make
make install
cd ..
rm -rf glibc-build $file
show_patcher `echo $ver_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment