Skip to content

Instantly share code, notes, and snippets.

@simbo1905
Last active March 19, 2018 20:29
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 simbo1905/21bd94a28c460b295c2fbef7a2bb6a71 to your computer and use it in GitHub Desktop.
Save simbo1905/21bd94a28c460b295c2fbef7a2bb6a71 to your computer and use it in GitHub Desktop.
loads an .env file containing key=value environment variables into an openshift secret `NAME=example ./create-env-secret.sh .env`
#!/bin/bash
if [ "$NAME" = "" ]
then
echo "You must set NAME of the secet as an env var"
exit 1
else
echo "Creating secet/$NAME"
fi
if [ -z "$1" ]; then
echo "No .env argument supplied. Exiting"
exit 1
fi
if [ ! -f "$1" ]; then
echo "$1 is not a file. Exiting"
exit 1
fi
# oddly bash refused to run on file `.env` so copy it to a temp file first
FILE=/tmp/$$
cp $1 $FILE
awk "BEGIN {FS = \"=\" ; print \"apiVersion: v1\nkind: Secret\nmetadata:\n name: $NAME\nstringData:\"} NF==2 && \$1 !~ /#.*/ && \$2 !~ /^$/{print \" \" \$1 \": \x22\" \$2 \"\x22\"}" $FILE | sed 's/""/"/g' | oc create -f -
rm $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment