Last active
October 6, 2020 21:56
-
-
Save jul/817feed13de86707fded04296812cea1 to your computer and use it in GitHub Desktop.
keeping my secrets in exported variables (CLI on video + k8s, docker, vagrant)
This file contains 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 -S bash -i | |
STASH=~/.secrets | |
RZ="\e[0m" | |
GR="\e[92m" | |
RD="\e[91m" | |
HL="\e[1m" | |
mkdir $STASH &> /dev/null | |
chmod 700 $STASH | |
if [ ! -z "$1" ]; then | |
if [ -f "$1" ]; then | |
FILE="$1"; | |
elif [ -f "$STASH/$1" ]; then | |
FILE="$STASH/$1"; | |
else | |
echo no secret found for "$1" check ls $STASH | |
exit 1 | |
fi | |
else | |
i=1; | |
for f in $( ls -rt $STASH/* ) ; do | |
if [ ! -z "$f" ]; then | |
STATUS=$( [[ $( stat --printf "%a" $f ) == "600" ]] \ | |
|| echo -n "${RD}pliz chmod 600 $f" ) | |
ff=` basename $f ` | |
if [ "$ff" != '.' ] && [ "$ff" != '..' ]; then | |
printf "%3d: %-32s %s " $i "$ff" ; | |
echo -e $STATUS ${RZ} | |
FL[i]=$f | |
i=`echo $(( i + 1 )) ` | |
fi | |
fi | |
done | |
echo "which secret do you want?" | |
read choice | |
FILE="${FL[$choice]}" | |
fi | |
CAGE=$( basename $FILE ) | |
if [ ! -z "$CAGE_C" ]; then | |
CAGE_C="${CAGE_C}->${CAGE}" | |
else | |
CAGE_C="#SEC:${CAGE}" | |
fi | |
export CAGE | |
export CAGE_C | |
source "$FILE" | |
shift | |
if [ -z "$1" ]; then | |
PRMPT="${HL}${RD}${CAGE_C}${RZ}:" | |
( PS1="${PRMPT}$PS1" bash --norc -i) | |
else | |
eval "$@" | |
fi | |
unset CAGE | |
unset CAGE_C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment