Last active
February 25, 2019 15:18
-
-
Save snorremd/858c59ffcd65d0ec93c979e575a1bf6f to your computer and use it in GitHub Desktop.
Script to grab credentials from gpg encrypted file and run clj with them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# cljgp is a script for decrypting a credentials file with environment | |
# variables and set them on the clj process. Combine this with the | |
# ~/.m2/settings.xml file and tell maven to use your environment vars: | |
# https://maven.apache.org/settings.html. | |
# | |
# Credentials file should contain: | |
# MY_USER=someuser | |
# MY_PASS=somepass | |
# | |
# Settings.xml file should then contain: | |
# <username>${env.MY_USER}</username> | |
# <password>${env.MY_PASS}</password> | |
ENCRYPTED_CREDENTIALS=${HOME}/.clojure/credentials.gpg | |
neededutils=( gpg clj rlwrap ) | |
for UTIL in ${neededutils[@]} ; do | |
if [ ! -x "`which $UTIL`" ] ; then | |
echo "$0 Failure: Could not find $UTIL in \$PATH" | |
exit 2 | |
fi | |
done | |
# Check if credential file exists | |
if [ ! -e ${ENCRYPTED_CREDENTIALS} ]; then | |
echo "Missing credential file at ${ENCRYPTED_CREDENTIALS}" | |
exit 1 | |
fi | |
# Decrypt credentials file and source it | |
CREDENTIALS=$(gpg -d ${ENCRYPTED_CREDENTIALS} 2> /dev/null) | |
if [ $? -ne 0 ]; then | |
echo "Could not decrypt credential file at ${ENCRYPTED_CREDENTIALS}" | |
exit 1 | |
fi | |
echo "Running clj with environment variables from ${ENCRYPTED_CREDENTIALS}" | |
env $(echo $CREDENTIALS | grep -v "^#" | xargs) clj $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edit: Add this as a shell script in your
~/bin/
folder under some name likecljpg
and make it executable.Add an alias from
clj
tocljpg
if you want to shadow the original clj command.Original comment: Put this in your
~/.bash_aliases
file, configure the~/.m2/settings.xml
file, and you are good to go.