|
### No shebang since I want to set the environment |
|
### for the current shell |
|
|
|
if [ -z "$GNUPGHOME" ]; then |
|
# begin if; not indented b/c of heredocs |
|
|
|
## Create GnuPG directory with a dmg and tmp subdir |
|
2>/dev/null mkdir ~/GnuPG |
|
2>/dev/null mkdir ~/GnuPG/tmp |
|
2>/dev/null mkdir ~/GnuPG/dmg |
|
|
|
## Download dmg, sig, and signing keys to dmg subdir |
|
cd ~/GnuPG/dmg |
|
gpgosx=http://downloads.sourceforge.net/project/gpgosx |
|
enigmail=https://www.enigmail.net/documentation |
|
|
|
# Download dmg |
|
curl -LO ${gpgosx}/GnuPG-2.1.7.dmg |
|
# Download sig |
|
curl -LO ${gpgosx}/GnuPG-2.1.7.dmg.sig |
|
# Download signing keys |
|
curl -LO ${enigmail}/pgp-key.php |
|
|
|
## Extract temp files to tmp directory |
|
cd ~/GnuPG/tmp |
|
|
|
# Mount DMG while saving off the device allocated |
|
dmgdev=$(hdiutil attach ../dmg/GnuPG-2.1.7.dmg \ |
|
| grep /dev/disk | head -n 1 | awk '{print $1}') |
|
# Extract the pkg file contents |
|
tar -xf /Volumes/GnuPG\ 2.1/Install.pkg |
|
# Unmount the dmg file |
|
hdiutil detach $dmgdev |
|
# Extract the directory stucture to GnuPG directory |
|
cd ~/GnuPG |
|
cat ./tmp/GnuPG.pkg/Payload | gunzip -dc |cpio -i |
|
|
|
## Set up profile and config files |
|
|
|
# Set up GnuPG environment |
|
touch ~/.profile ./setGnuPGenv.sh |
|
> ./setGnuPGenv.sh cat << EOL |
|
if [ -z "\$GNUPGHOME" ]; then |
|
export PATH=\${PATH}:${PWD}/bin |
|
export DYLD_FALLBACK_LIBRARY_PATH=${PWD}/lib |
|
export GNUPGHOME=\${HOME}/.gnupg |
|
fi |
|
EOL |
|
|
|
>> ~/.profile cat << 'EOL' |
|
if [ -z "$GNUPGHOME" ]; then |
|
source ~/GnuPG/setGnuPGenv.sh |
|
fi |
|
EOL |
|
|
|
source ~/GnuPG/setGnuPGenv.sh |
|
|
|
# Set up GnuPG config files |
|
> ${GNUPGHOME}/gpg.conf echo "agent-program" \ |
|
"${PWD}/bin/gpg-agent" |
|
> ${GNUPGHOME}/gpg-agent.conf echo "pinentry-program" \ |
|
"${PWD}/bin/pinentry-mac.app/Contents/MacOS/pinentry-mac" |
|
|
|
## Verify the dmg we downloaded |
|
cd ~/GnuPG/dmg |
|
gpg2 --import pgp-key.php |
|
gpg2 --verify GnuPG-2.1.7.dmg.sig GnuPG-2.1.7.dmg |
|
if [ $? -eq 0 ]; then |
|
# Verify worked, files are good. |
|
rm -r -f ~/GnuPG/tmp |
|
else |
|
# Verify failed, files are corrupt |
|
echo "ERROR: SIGNATURE CHECK FAILED!" |
|
export GNUPGHOME="" |
|
fi |
|
|
|
# end if; not indented b/c of heredocs |
|
fi |