Skip to content

Instantly share code, notes, and snippets.

@ruario ruario/1-patchelf.md
Last active Sep 3, 2019

Embed
What would you like to do?
Fetching, building and installing PatchELF

The following assumes you want a single user install. If you want a system wide install instead, run the attached script create-patchelf-pkg.sh (after first installing a suitable build environment).

Note: create-patchelf-pkg.sh also provides an uninstall script.

Setting up a Build Environment

Install a basic build environment (if you don't already have one). How to install this varies from distro to distro. Your best bet to refer to your distro's wiki or ask in their forums. That said, here are a few example install commands for a few of the popular distros:

  • Ubunt/Mint/Debian: sudo install build-essential
  • Fedora: sudo dnf install @development-tools
  • OpenSUSE: sudo zypper install -t pattern devel_basis

Building and Installing PatchELF

First go the the PatchELF homepage to find out the latest version number, then issue the following commands (adjusting the version number as needed).

wget http://nixos.org/releases/patchelf/patchelf-0.10/patchelf-0.10.tar.bz2
tar xf patchelf-0.10.tar.bz2
cd patchelf-0.10
./configure --prefix="$HOME/.local"
make install
strip --strip-unneeded ~/.local/bin/patchelf
gzip -9 ~/.local/share/man/man1/patchelf.1

Configure your path

Update your $PATH variable to include $HOME/.local/bin (if it doesn't already).

Removing PatchELF

If you later need to uninstall, issue the following:

rm -rv ~/.local/{share/doc/patchelf,share/man/man1/patchelf.1.gz,bin/patchelf}

Note: The above command assumes a bash shell.

Removing a manual system wide install

If you didn't follow any of the above and just did a system-wide install via ./configure && sudo make install—that you could now like to remove—you can use the following generic self-compiled package removal guide to uninstall PatchELF.

#!/bin/sh -eu
available () {
command -v "$1" >/dev/null 2>&1
}
if available wget; then
DL="wget"
DLS="wget -qO-"
elif available curl; then
DL="curl -O"
DLS="curl -s"
else
echo "Install Wget or cURL" >&2
exit 1
fi
PKGNAME=patchelf
VERSION="$($DLS https://nixos.org/releases/patchelf/ | grep -o "$PKGNAME-[0-9]\+\.[0-9]\+" | cut -d- -f2 | sort -V | tail -n 1)"
if [ -z "$VERSION" ]; then
VERSION=0.10
fi
if [ ! -e "$PKGNAME-$VERSION.tar.bz2" ]; then
$DL "http://nixos.org/releases/$PKGNAME/$PKGNAME-$VERSION/$PKGNAME-$VERSION.tar.bz2"
fi
if [ -d "$PKGNAME}-$VERSION" ]; then
rm -fr "$PKGNAME-$VERSION"
fi
tar xf "$PKGNAME-$VERSION.tar.bz2"
cd "$PKGNAME-$VERSION"
./configure --prefix="$PWD/staging/usr/local" --mandir="$PWD/staging/usr/local/man" --docdir="$PWD/staging/usr/local/doc/$PKGNAME-$VERSION"
make install
cd staging
strip --strip-unneeded "usr/local/bin/$PKGNAME"
gzip -9 "usr/local/man/man1/$PKGNAME.1"
mkdir -p usr/local/bin
cat <<EOF> "usr/local/bin/uninstall-$PKGNAME-$VERSION"
#!/bin/sh -e
while read f; do
if [ -e "\$f" -o -h "\$f" ]; then
if [ -d "\$f" ]; then
if ! ls -A "\$f" | grep -q ^; then
if [ ! -h "\$f" ]; then
rmdir -v "\$f"
fi
fi
else
rm -v "\$f"
fi
fi
done << FILE_LIST
EOF
find . -depth | sed -n 's,^\./,/,p' | grep -vxE "/usr/local/bin/uninstall-$PKGNAME-$VERSION|/usr|/usr/local(/etc|/doc|/games|/include|/lib(32|64)?|/man(/man[a-z0-9]+)?|/s?bin|/share(/color|/man(/man[a-z0-9]+)?|/misc)?|/src)?" >> "usr/local/bin/uninstall-$PKGNAME-$VERSION"
printf "/usr/local/bin/uninstall-$PKGNAME-$VERSION\nFILE_LIST\n" >> "usr/local/bin/uninstall-$PKGNAME-$VERSION"
chmod 755 "usr/local/bin/uninstall-$PKGNAME-$VERSION"
find . ! -type d | sed 's,^\./,,' | tar caf "../../$PKGNAME-$VERSION.bin.tar.gz" -T- --owner 0 --group 0
cd ../..
rm -fr "$PKGNAME-$VERSION"
printf "\nCreated: $PKGNAME-$VERSION.bin.tar.gz\n\n"
printf "To install issue the following as root (or prefaced with sudo):\n\n"
printf " tar xf $PKGNAME-$VERSION.bin.tar.gz -C/\n\n"
printf "If you later need to uninstall, issue the following as root (or prefaced with sudo):\n\n"
printf " uninstall-$PKGNAME-$VERSION\n\n"
@mmistele

This comment has been minimized.

Copy link

commented Aug 23, 2018

For folks having issues with the uninstall, here's one with the absolute path (so you don't have to run it from ~):
rm -rv ~/.local/{share/doc/patchelf,share/man/man1/patchelf.1.gz,bin/patchelf}

Also there's a new version of patchelf out (0.9) - here are the updated lines for single-user install:

wget https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.bz2
tar xf patchelf-0.9.tar.bz2
cd patchelf-0.9
...
@ruario

This comment has been minimized.

Copy link
Owner Author

commented Sep 3, 2019

@mmistele Thanks for that. I totally forgot about this gist and was not notified last year when you commented. I have updated it now, correcting the path and updating the version to 0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.