Skip to content

Instantly share code, notes, and snippets.

@mattrude
Last active January 26, 2024 20:29
Show Gist options
  • Save mattrude/d15b0ed0a8b6dacb281185fdbc82c08d to your computer and use it in GitHub Desktop.
Save mattrude/d15b0ed0a8b6dacb281185fdbc82c08d to your computer and use it in GitHub Desktop.
A simple script build for Ubuntu to download and install the current version of GnuPG.
#!/bin/bash
# ---------
# Script to build and install GnuPG 2.2.x
GNUPG='2.4.4'
LIBGPGERROR='1.47'
LIBGCRYPT='1.10.3'
LIBKSBA='1.6.5'
LIBASSUAN='2.5.6'
NTBTLS='0.3.2'
NPTH='1.6'
PINENTRY='1.2.1'
################################################################################
if [ "${LOGNAME}" != "root" ]; then
printf "\33[0;31mThis script must be ran by the 'root' user, but was ran by the ${LOGNAME} instead.\033[0m\n"
exit 1
fi
################################################################################
if [ -f /usr/local/bin/gpg ]; then
OLDVER="`/usr/local/bin/gpg --version |grep gpg |awk '{ print $3 }'`"
else
OLDVER="0"
fi
if [ "${GNUPG}" == "${OLDVER}" ]; then
exit 0
fi
################################################################################
UPDATE=""
PACKETS="bzip2 make gettext texinfo gnutls-bin libgnutls28-dev build-essential libbz2-dev zlib1g-dev libncurses-dev libsqlite3-dev libldap2-dev libgnutls28-dev bzip2 make gettext texinfo gnutls-bin build-essential libbz2-dev zlib1g-dev libsqlite3-dev libldap2-dev libreadline-dev"
dpkg --get-selections |sed 's/:/ /g' |awk '{print $1}' > /tmp/installed-packages.txt
for a in $PACKETS
do
if [ `egrep "^$a$" /tmp/installed-packages.txt |wc -l` != "1" ]; then
echo "$a is not installed"
UPDATE="$a $UPDATE"
fi
done
rm -f /tmp/installed-packages.txt
if [ "$UPDATE" != "" ]; then
apt update
apt install -y $UPDATE
fi
################################################################################
echo "/usr/local/lib" > /etc/ld.so.conf.d/gpg2.conf && ldconfig
mkdir -p /var/src/gnupg
if [ -x /usr/bin/gpg ] || [ -x /usr/local/bin/gpg ]; then
curl -Ls 'https://gnupg.org/signature_key.asc' -o /var/src/gnupg/signing-keys.asc
if [ -x /usr/bin/gpg ]; then
/usr/bin/gpg -k -qq > /dev/null
/bin/sleep 0.5
/usr/bin/gpg -qq --import /var/src/gnupg/signing-keys.asc
else
/usr/local/bin/gpg -k -qq > /dev/null
/bin/sleep 0.5
/usr/local/bin/gpg -qq --import /var/src/gnupg/signing-keys.asc
fi
fi
echo "## Starting Gnupg Install"
for Package in libgpg-error-${LIBGPGERROR} libgcrypt-${LIBGCRYPT} libassuan-${LIBASSUAN} libksba-${LIBKSBA} ntbtls-${NTBTLS} npth-${NPTH} pinentry-${PINENTRY} gnupg-${GNUPG}
do
if [ ! -d /var/src/gnupg ]; then mkdir -p /var/src/gnupg; fi
cd /var/src/gnupg
PackageDir="`echo "${Package}" |sed 's/[0-9]*//g' |sed 's/\.//g' |sed 's/-$//g'`"
Skip="No"
echo "Starting on ${Package}"
if [ -d ${Package} ]; then
echo -n " - Package found, checking: "
if [ -x /usr/bin/gpg ] || [ -x /usr/local/bin/gpg ]; then
if [ -x /usr/local/bin/gpg ]; then
/usr/local/bin/gpg -qq --verify ${Package}.tar.bz2.sig 2> /dev/null
StatusVerify=${?}
else
/usr/bin/gpg -qq --verify ${Package}.tar.bz2.sig 2> /dev/null
StatusVerify=${?}
fi
if [ ${StatusVerify} != "0" ]; then printf "\33[0;31m${Package} Failed to Verify\033[0m\n"; else Skip="Yes"; printf "\033[0;32mDone!\033[0m\n"; fi
else
Skip="Yes"
fi
fi
if [ "${Skip}" != "Yes" ]; then
cd /var/src/gnupg
rm -rf ${Package}
echo -n " - Downloading Package: "
wget -cq https://www.gnupg.org/ftp/gcrypt/${PackageDir}/${Package}.tar.bz2
StatusDown=${?}
if [ ${StatusDown} != "0" ]; then printf "\33[0;31m${Package} Failed to download\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
echo -n " - Downloading Package Sign: "
wget -cq https://www.gnupg.org/ftp/gcrypt/${PackageDir}/${Package}.tar.bz2.sig
StatusDownSig=${?}
if [ ${StatusDownSig} != "0" ]; then printf "\33[0;31m${Package} Failed to download sign\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
if [ -x /usr/bin/gpg ] || [ -x /usr/local/bin/gpg ]; then
echo -n " - Verifing package"
if [ -x /usr/local/bin/gpg ]; then
echo -n ": "
/usr/local/bin/gpg -qq --verify ${Package}.tar.bz2.sig 2> /dev/null
StatusVerify=${?}
else
echo -n " (via gpg): "
/usr/bin/gpg -qq --verify ${Package}.tar.bz2.sig 2> /dev/null
StatusVerify=${?}
fi
if [ ${StatusVerify} != "0" ]; then printf "\33[0;31m${Package} Failed to Verify\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
else
echo " - Skipping package verification."
fi
fi
echo -n " - UnTaring the package: "
tar -xjf ${Package}.tar.bz2
StatusUntar=${?}
if [ ${StatusUntar} != "0" ]; then printf "\33[0;31m${Package} Failed to UnTar\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
echo -n " - Changing into the Directory: "
cd /var/src/gnupg/${Package}
StatusCD=${?}
if [ ${StatusCD} != "0" ]; then printf "\33[0;31m${Package} Failed to change into the ${Package} directory\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
if [ "${PackageDir}" == "pinentry" ]; then
echo -n " - Running pinentry configure: "
./configure --enable-pinentry-curses --disable-pinentry-qt4 > /dev/null 2> /dev/null
StatusConfig=${?}
else
echo -n " - Running configure: "
./configure > /dev/null 2> /dev/null
StatusConfig=${?}
fi
if [ ${StatusConfig} != "0" ]; then printf "\33[0;31m${Package} Failed to run './configure'\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
echo -n " - Running make: "
make > /dev/null 2> /dev/null
StatusMake=${?}
if [ ${StatusMake} != "0" ]; then printf "\33[0;31m${Package} Failed to run 'make'\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
echo -n " - Running make check: "
make check > /dev/null 2> /dev/null
StatusMakeCheck=${?}
if [ ${StatusMakeCheck} != "0" ]; then printf "\33[0;31m${Package} Failed to run 'make check'\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
echo -n " - Running make install: "
make install > /dev/null 2> /dev/null
StatusMakeInstall=${?}
if [ ${StatusMakeInstall} != "0" ]; then printf "\33[0;31m${Package} Failed to run 'make install'\033[0m\n"; exit 1; else printf "\033[0;32mDone!\033[0m\n"; fi
done
rm /usr/bin/gpg-agent; ln -s /usr/local/bin/gpg-agent /usr/bin/gpg-agent
rm /usr/bin/dirmngr; ln -s /usr/local/bin/dirmngr /usr/bin/dirmngr
echo -n "Killing old version of gnupg: "
gpgconf --kill all
printf "\033[0;32mDone!\033[0m\n"
echo -n "Current version is: "
/usr/local/bin/gpg --version |head -1
echo "## Finished Gnupg Install"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment