Created
July 24, 2022 12:38
-
-
Save Gerst20051/9610f737406481ba4b9fc4cccf280ebc to your computer and use it in GitHub Desktop.
Automate GitHub GPG Key Setup
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 sh | |
# ASCII: http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Create%20Github%20GPG%20Key | |
# SOURCE: https://gist.github.com/Gerst20051/ | |
function double_echo { | |
echo && echo | |
} | |
function newline { | |
echo | |
} | |
bold=$(tput bold) | |
normal=$(tput sgr0) | |
function init { | |
echo | |
print_purpose_header && double_echo | |
confirm_continue && double_echo | |
prompt_gpg_passphrase && double_echo | |
print_finished_header && double_echo | |
} | |
function print_purpose_header { | |
echo '_________ __ ________.__ __ .__ ___. __________________ ________ ____ __. ' | |
echo '\_ ___ \_______ ____ _____ _/ |_ ____ / _____/|__|/ |_| |__ __ _\_ |__ / _____/\______ \/ _____/ | |/ _|____ ___.__.' | |
echo '/ \ \/\_ __ \_/ __ \\__ \\ __\/ __ \ / \ ___| \ __\ | \| | \ __ \ / \ ___ | ___/ \ ___ | <_/ __ < | |' | |
echo '\ \____| | \/\ ___/ / __ \| | \ ___/ \ \_\ \ || | | Y \ | / \_\ \ \ \_\ \| | \ \_\ \ | | \ ___/\___ |' | |
echo ' \______ /|__| \___ >____ /__| \___ > \______ /__||__| |___| /____/|___ / \______ /|____| \______ / |____|__ \___ > ____|' | |
echo ' \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/\/ ' | |
} | |
function confirm_continue { | |
echo '_________ _____.__ _________ __ .__ ' | |
echo '\_ ___ \ ____ _____/ ____\__|______ _____ \_ ___ \ ____ _____/ |_|__| ____ __ __ ____ ' | |
echo '/ \ \/ / _ \ / \ __\| \_ __ \/ \ / \ \/ / _ \ / \ __\ |/ \| | \_/ __ \ ' | |
echo '\ \___( <_> ) | \ | | || | \/ Y Y \ \ \___( <_> ) | \ | | | | \ | /\ ___/ ' | |
echo ' \______ /\____/|___| /__| |__||__| |__|_| / \______ /\____/|___| /__| |__|___| /____/ \___ >' | |
echo ' \/ \/ \/ \/ \/ \/ \/ ' | |
double_echo | |
local CONTINUE_CONFIRM='' | |
until [ "$CONTINUE_CONFIRM" = 'run' ]; do | |
read -p 'type "run" to continue: ' CONTINUE_CONFIRM | |
done | |
} | |
function prompt_gpg_passphrase { | |
echo ' __________________ ________ __________ .__ ' | |
echo ' / _____/\______ \/ _____/ \______ \_____ ______ ____________ | |______________ ______ ____ ' | |
echo '/ \ ___ | ___/ \ ___ | ___/\__ \ / ___// ___/\____ \| | \_ __ \__ \ / ___// __ \ ' | |
echo '\ \_\ \| | \ \_\ \ | | / __ \_\___ \ \___ \ | |_> > Y \ | \// __ \_\___ \\ ___/ ' | |
echo ' \______ /|____| \______ / |____| (____ /____ >____ >| __/|___| /__| (____ /____ >\___ >' | |
echo ' \/ \/ \/ \/ \/ |__| \/ \/ \/ \/ ' | |
double_echo | |
# the gpg key can be edited to change or remove the passphrase (the public key will stay the same) | |
# [$]> gpg --edit-key $(grep gpg_key ~/.secrets/vars/macmini.yml | cut -d\ -f2) | |
# gpg> passwd | |
if [ -z ${gpg_key+x} ]; then | |
echo 'A passphrase should be at least 8 characters long.' | |
echo 'A passphrase should contain at least 1 digit or special character.' | |
# TODO: verify that the passphrase satisfies these constraints so that gpg doesn't throw an error | |
double_echo | |
# TODO: add support for not setting a passphrase | |
while true; do | |
read -s -p 'gpg passphrase: ' gpg_passphrase | |
echo | |
read -s -p 'gpg passphrase (confirm): ' gpg_passphrase_confirm | |
echo | |
[ ${#gpg_passphrase} -ge 8 ] && [ "$gpg_passphrase" = "$gpg_passphrase_confirm" ] && break | |
echo | |
echo 'bad passphrase please re-enter this passphrase' | |
echo | |
done | |
else | |
echo "using gpg key \"$gpg_key\"" | |
fi | |
} | |
function print_finished_header { | |
echo '___________.__ .__ .__ .___ ________.__ __ .__ ___. __________________ ________ ____ __. ' | |
echo '\_ _____/|__| ____ |__| _____| |__ ____ __| _/ / _____/|__|/ |_| |__ __ _\_ |__ / _____/\______ \/ _____/ | |/ _|____ ___.__.' | |
echo ' | __) | |/ \| |/ ___/ | \_/ __ \ / __ | / \ ___| \ __\ | \| | \ __ \ / \ ___ | ___/ \ ___ | <_/ __ < | |' | |
echo ' | \ | | | \ |\___ \| Y \ ___// /_/ | \ \_\ \ || | | Y \ | / \_\ \ \ \_\ \| | \ \_\ \ | | \ ___/\___ |' | |
echo ' \___ / |__|___| /__/____ >___| /\___ >____ | \______ /__||__| |___| /____/|___ / \______ /|____| \______ / |____|__ \___ > ____|' | |
echo ' \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/\/ ' | |
} | |
init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment