Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.2.21'
LIBGPGERROR='1.38'
LIBGCRYPT='1.8.6'
LIBKSBA='1.4.0'
LIBASSUAN='2.5.3'
NTBTLS='0.1.2'
NPTH='1.6'
PINENTRY='1.1.0'
################################################################################
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 libncurses5-dev libsqlite3-dev libldap2-dev libgnutls28-dev bzip2 make gettext texinfo gnutls-bin build-essential libbz2-dev zlib1g-dev libncurses5-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://gist.githubusercontent.com/mattrude/d15b0ed0a8b6dacb281185fdbc82c08d/raw/signing-keys.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"
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBE0ti4EBCACqGtKlX9jI/enhlBdy2cyQP6Q7JoyxtaG6/ckAKWHYrqFTQk3I
Ue8TuDrGT742XFncG9PoMBfJDUNltIPgKFn8E9tYQqAOlpSA25bOb30cA2ADkrjg
jvDAH8cZ+fkIayWtObTxwqLfPivjFxEM//IdShFFVQj+QHmXYBJggWyEIil8Bje7
KRw6B5ucs4qSzp5VH4CqDr9PDnLD8lBGHk0x8jpwh4V/yEODJKATY0Vj00793L8u
qA35ZiyczUvvJSLYvf7STO943GswkxdAfqxXbYifiK2gjE/7SAmB+2jFxsonUDOB
1BAY5s3FKqrkaxZr3BBjeuGGoCuiSX/cXRIhABEBAAG0Fldlcm5lciBLb2NoIChk
aXN0IHNpZymJAT4EEwECACgFAk0ti4ECGwMFCRDdnwIGCwkIBwMCBhUIAgkKCwQW
AgMBAh4BAheAAAoJECSbOdJPJeO2PlMIAJxPtFXf5yozPpFjRbSkSdjsk9eru05s
hKZOAKw3RUePTU80SRLPdg4AH+vkm1JMWFFpwvHlgfxqnE9rp13o7L/4UwNUwqH8
5zCwu7SHz9cX3d4UUwzcP6qQP4BQEH9/xlpQS9eTK9b2RMyggqwd/J8mxjvoWzL8
Klf/wl6jXHn/yP92xG9/YA86lNOL1N3/PhlZzLuJ6bdD9W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cCtoZsIoVzZEy7DjqIvGgnTssD8HCLnIAHCDvnP7dJ
W3uMuLCdSqym3cjlEIiQMsaGywklfzJISAwJrGQdWSKRd535jXpEXQlXDKal/IwM
KAUt0PZtlCc9S3gwixQryxdJ28lJ6h2T9fVDr8ZswMmTAFG91uctfhjKOMgPt8Uh
SPGW484WsIsQgkbOvf+Kfswl0eHuywX+pKAB5ZQ/9GVC6Ug4xfrdiJL0azJTPnvj
MY5JYp6/L9RURs5hP5AnHR2j/PPosAtsFCjmbRbOMiASzklnUJPbSz5kfLloDWZm
rUScjbzmsXehGyt433JGyRhZJl4x/jPbzKhaaAHsGd+fRao6vlLOwFywDDVMp6Ju
yK7UeUb7I8ekTbSkGFA+l2Oa3O6/Y7PYhq7hwwAFuZckYI98IpHNCG1fS9W07FyK
dvQbK1PbF1JFRKfsUCWYMKqDnbqEo5jivPEHZImw6iYhhXcyEYl8fjcb9T6/S+wO
P7av
=ud/7
-----END PGP PUBLIC KEY BLOCK-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment