# Get the source
cd
test -f installed/zstd-1.5.5.tar.gz &&
mv -f installed/zstd-1.5.5.tar.gz .
test ! -f zstd-1.5.5.tar.gz &&
wget https://github.com/facebook/zstd/releases/download/v1.5.5/\
zstd-1.5.5.tar.gz
# Extract the source
mkdir -p -m 0700 ~/src
cd ~/src
find -maxdepth 1 -type d -name "zstd-*" -exec rm -r {} \;
tar xzvf ~/zstd-1.5.5.tar.gz
cd zstd-1.5.5
test $UID = 0 && chown -R root:root .
# Build it, specifying paths for 64-bit
test $(uname -m) = 'x86_64' &&
PREFIX=/usr LIBDIR=/usr/lib64 MANDIR=/usr/man/man1 make
# Build it, specifying paths for anything else
test $(uname -m) != 'x86_64' &&
PREFIX=/usr MANDIR=/usr/man/man1 make
# Become root to install it
su
# Install it 64-bit
# MAN1DIR (not MANDIR) because programs/Makefile doesn't handle that
test $(uname -m) = 'x86_64' &&
PREFIX=/usr LIBDIR=/usr/lib64 MAN1DIR=/usr/man/man1 make install
# Install it anything else
test $(uname -m) != 'x86_64' &&
PREFIX=/usr MAN1DIR=/usr/man/man1 make install
ldconfig
# Become your non-root user again
exit
# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/zstd-*.tar.gz
mv -f zstd-1.5.5.tar.gz installed/
# If you ever want to uninstall Zstandard, this should do it
# 'make uninstall' as root (with PREFIX= and such) should do it
# The rest is in case old files are left over
cd
su
test -d src/zstd-* && ( cd src/zstd-* ; make uninstall )
( /usr/bin
rm -f unzstd zstd zstdcat zstdgrep zstdless zstdmt )
( /usr/include
rm -f zdict.h zstd.h zstd_errors.h )
( cd /usr/lib
rm -f libzstd.* pkgconfig/libzstd.pc )
test -d /usr/lib64 &&
( cd /usr/lib64
rm -f libzstd.* pkgconfig/libzstd.pc )
( cd /usr/man/man1
rm -f unzstd.1 zstd.1 zstdcat.1 zstdgrep.1 zstdless.1 )
ldconfig
exit
find ~/src -maxdepth 1 -type d -name "zstd-*" -exec rm -r {} \;
rm -f ~/installed/zstd-*.tar.*