bin: Update import-pgp-keys + create cloudflarectl

Just in case flarectl is browoken in Termux  on
some Android devices KEK.

Signed-off-by: Andrei Jiroh Eugenio Halili <andreijiroh@madebythepins.tk>
This commit is contained in:
Andrei Jiroh Eugenio Halili 2021-04-25 16:09:34 +08:00
parent 28b4369bd9
commit 295697a1bf
Signed by: ajhalili2006
GPG Key ID: A30EBE40AD856D88
2 changed files with 66 additions and 1 deletions

59
bin/cloudflarectl Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
HTTP_CLIENT_PATH=$(command -v curl)
if [[ $HTTP_CLIENT_PATH == "" ]]; then
echo "Please install cURL first as this script may not work in wGET."
exit 1
fi
if command -v jq >> /dev/null; then
echo "OK" >> /dev/null
else
echo "Please install jq to prettify JSON responses from API."
exit 1
fi
# API Handler
apiHandler() {
CF_HOST="https://api.cloudflare.com/client/v4"
RESPONSE_FORMAT="application/json"
API_METHOD=${2:GET}
curl -H "Content-Type:$RESPONSE_FORMAT" \
-H "Authorization: Bearer $CF_API_KEY" \
-X "$API_METHOD" "$CF_HOST/$1"
}
if [[ $# == "0" ]] || [[ $1 == "help" ]]; then
echo "Usage: $0 COMMAND ARGS"
echo "Available commands:"
echo "validate-token Check if an token is still working"
echo "zones Manage your Cloudflare zones"
else
if [[ $@ == "validate-token" ]]; then
if [[ $CF_API_EMAIL != "" ]]; then
echo "Unsupported variable found: CF_API_EMAIL"
echo "Please use API keys instead of global API token."
exit 1
fi
if [[ $CF_API_KEY != "" ]]; then
apiHandler user/tokens/verify GET | jq
else
echo "No token found! Set your API token with:"
echo " export CF_API_KEY=abcdef123456"
fi
elif [[ $@ == "zones" ]]; then
echo "Usage: $0 zones [ARGS]"
echo
echo "Manage and list your zones managed by Cloudflare."
echo "Available arguments:"
echo "list List available zones to manage"
echo "add Add new zone"
echo "remove Remove an zone"
exit
elif [[ $@ == "zones list" ]]; then
apiHandler zones GET | jq .result
else
echo "Unsupported command! See the help command for details"
fi
fi

View File

@ -4,5 +4,11 @@ if [ "$#" == "0" ]; then
echo "Usage: $0 your-pgp-key-name-here"
echo "If the script says the file isn't found, make sure"
echo "you placed it on your DOTFILES_HOME/secrets/pgp directory"
echo "(
exit
fi
PGP_KEY_EXPORT_FILE="$HOME/.dotfiles/secrets/pgp/$1.pgp.sec"
echo "info: Export file: ~/.dotfiles/secrets/pgp/$1.pgp.sec"
PASSPHRASE_BASE64=$(cat ~/.dotfiles/secrets/pgp/passphrase-$PGP_KEY_EXPORT_FILE)
echo "info: Base64'd file contents: $PASSPHRASE_BASE64"
echo $PASSPHARSE_BASE64 | base64 -d