Theo Chatzimichos c336cc
#!/bin/bash
Theo Chatzimichos c336cc
Theo Chatzimichos c336cc
help() {
Theo Chatzimichos c336cc
    echo "Encrypt a given string and print out the output. This output can be"
Theo Chatzimichos c336cc
    echo "then used as encrypted pillar"
Theo Chatzimichos c336cc
    echo
Theo Chatzimichos 097450
    echo "Options:"
Theo Chatzimichos 097450
    echo "-m        Pass multiline input, end with CTRL+D when done"
Theo Chatzimichos 097450
    echo
Theo Chatzimichos c336cc
}
Theo Chatzimichos c336cc
Theo Chatzimichos c336cc
[[ $1 == '--help' ]] && help && exit
Theo Chatzimichos c336cc
Theo Chatzimichos 097450
while getopts mh arg; do
Theo Chatzimichos c336cc
    case ${arg} in
Theo Chatzimichos 097450
        m) MULTILINE=1 ;;
Theo Chatzimichos c336cc
        h) help && exit ;;
Theo Chatzimichos c336cc
        *) help && exit 1 ;;
Theo Chatzimichos c336cc
    esac
Theo Chatzimichos c336cc
done
Theo Chatzimichos c336cc
Theo Chatzimichos 097450
if [[ -n $MULTILINE ]]; then
Theo Chatzimichos 097450
    echo "Please type the lines that you want to encrypt, and press CTRL+D when done"
Theo Chatzimichos 097450
    STRING=$(cat)
Theo Chatzimichos 097450
else
Theo Chatzimichos 097450
    echo "Please type the string that you want to encrypt"
Theo Chatzimichos 097450
    read STRING
Theo Chatzimichos 097450
fi
Theo Chatzimichos 9a0754
Theo Chatzimichos 097450
[[ -z $STRING ]] && echo "ERROR: Input was empty" && exit 1
Theo Chatzimichos c336cc
Theo Chatzimichos d2d4c6
RECIPIENTS=$(egrep '^\s*0x' encrypted_pillar_recipients | while read i; do echo "-r $i"; done | xargs)
Theo Chatzimichos c336cc
echo -n "${STRING}" | gpg --armor --batch --trust-model always --encrypt ${RECIPIENTS}