Last active
July 3, 2024 02:04
-
-
Save totszwai/1f82fdd8af47e77e2b2decb0e71bf393 to your computer and use it in GitHub Desktop.
Script that will update system pkgconf to the desire version as alternatives
This file contains hidden or 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 | |
set -e | |
WHAT=pkgconf | |
VERSION=2.2.0 | |
FULLNAME=${WHAT}-${VERSION} | |
INSTDIR=/opt/${FULLNAME} | |
function install() { | |
[ $# -eq 0 ] && { run_error "Usage: install <version>"; exit; } | |
local VERSION=${1} | |
local TARBALL=${FULLNAME}.tar.gz | |
local URL=https://github.com/pkgconf/pkgconf/archive/refs/tags/${TARBALL} | |
local WHERE=/tmp/update-${WHAT} | |
local ARCH=$(gcc -dumpmachine) | |
mkdir -p ${WHERE} | |
cd ${WHERE} | |
echo "Downloading ${URL}" | |
curl -L --create-dirs -o ${TARBALL} ${URL} | |
if [ -f "${TARBALL}" ]; then | |
tar -xzf ${TARBALL} | |
cd pkgconf-${FULLNAME} | |
libtoolize | |
./autogen.sh | |
./configure --prefix=${INSTDIR} --with-pkg-config-dir=/usr/local/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/${ARCH}/pkgconfig | |
make | |
echo "Installing..." | |
sudo make install | |
# Making a local install alias pkg-config | |
sudo ln -sf ${INSTDIR}/bin/pkgconf ${INSTDIR}/bin/pkg-config | |
echo -e "${TARBALL} installed \e[1;32mOK\e[39m" | |
else | |
echo -e "Cannot download ${URL}" | |
exit 1 | |
fi | |
} | |
function install_alternatives() { | |
for fullpath in ${INSTDIR}/bin/* ; do | |
local NAME="$(basename ${fullpath})" | |
#echo "sudo update-alternatives --install /usr/local/bin/${NAME} ${NAME} ${fullpath} 50" | |
sudo update-alternatives --install /usr/local/bin/${NAME} ${NAME} ${fullpath} 50 | |
done | |
# Note: without the pkg.m4 macros, you will see PKG_CHECK_MODULES | |
# errors during configure phase, so let's provide it to aclocal | |
local ACDIR=$(aclocal --print-ac-dir) | |
if [ ! -z "${ACDIR}" ]; then | |
sudo ln ${INSTDIR}/share/aclocal/pkg.m4 ${ACDIR}/pkg.m4 | |
else | |
echo "Warning: Cannot provide pkg.m4" | |
fi | |
# Note: if pkgconf/pkg-config fail to run, you will see PKG_CHECK_MODULES | |
# errors during configure phase. So add shared libraries to the ld cache. | |
sudo ldconfig ${INSTDIR}/lib | |
. ~/.profile | |
} | |
function remove_alternatives() { | |
for fullpath in ${INSTDIR}/bin/* ; do | |
local NAME="$(basename ${fullpath})" | |
#echo "sudo update-alternatives --remove ${NAME} ${fullpath}" | |
sudo update-alternatives --remove ${NAME} ${fullpath} | |
done | |
local ACDIR=$(aclocal --print-ac-dir) | |
if [ ! -z "${ACDIR}" ]; then | |
sudo rm ${ACDIR}/pkg.m4 | |
fi | |
. ~/.profile | |
} | |
if declare -f "$1" > /dev/null | |
then | |
"$@" | |
else | |
install ${VERSION} | |
install_alternatives | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment