Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.