Skip to content

Instantly share code, notes, and snippets.

@DragonBe
Created June 7, 2018 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DragonBe/d2851e4b93ccff3e420129f843574dd7 to your computer and use it in GitHub Desktop.
Save DragonBe/d2851e4b93ccff3e420129f843574dd7 to your computer and use it in GitHub Desktop.
Creating a GPG signed archive of your GIT source code with SHA 256 checksums in bash
#!/bin/bash
# Getting the current project's directory
pf=$(printf '%q\n' "${PWD##*/}")
# Getting the current configured user's email
gpguser=$(git config user.email)
if [ -z $gpguser ]
then
echo "!!! ERROR: No user for GIT configured !!!"
echo " You might want to set 'git config user.email <user@domain.tld>'"
exit 1
fi
# Looking up their GPG key ID
gpgid=$(gpg --list-keys --keyid-format LONG $gpguser | grep "^ " | sed 's/\ //g')
if [ -z $gpgid ]
then
echo "!!! ERROR: Couldn't find matching GPG ID for user $gpguser !!!"
exit 1
fi
# Clean up
rm -f $pf.zip
rm -f $pf.zip.asc
rm -f $pf.tar.gz
rm -f $pf.tar.gz.asc
rm -f $pf.sum
# Running archive
for format in zip tar.gz
do
git archive --format=$format --prefix=$pf/ --output=$pf.$format HEAD
shasum -a 256 $pf.$format >> $pf.sum
gpg --detach-sign -a -u $gpgid $pf.$format
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment