From 36a79c9ce26566fe0d14db5ae8f2f4ca21ea271d Mon Sep 17 00:00:00 2001 From: Travis Neely Date: Sat, 2 Sep 2023 02:11:24 -0500 Subject: [PATCH] Run shfmt --- dnsapi/dns_nfs.sh | 107 +++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/dnsapi/dns_nfs.sh b/dnsapi/dns_nfs.sh index bd930895..b07c6778 100755 --- a/dnsapi/dns_nfs.sh +++ b/dnsapi/dns_nfs.sh @@ -12,68 +12,67 @@ # Usage: dns_nfs_add _acme-challenge.domain.com "KjiayTfXPHmnHmOdevsOtJyzsU9AHw2T6R0lNVCl_oi" dns_nfs_add() { - FULLDOMAIN=$1 - ROOTDOMAIN=$(echo "$FULLDOMAIN" | awk -F '.' '{print $(NF-1)"."$NF}') - SUBDOMAIN=$(echo "$FULLDOMAIN" | sed 's/.'"$ROOTDOMAIN"'//g') - - if [ "$SUBDOMAIN" = "$FULLDOMAIN" ]; then - unset SUBDOMAIN - fi - - _nfs_rest "/dns/$ROOTDOMAIN/addRR" "name=$SUBDOMAIN" 'type=TXT' "data=$2" + FULLDOMAIN=$1 + ROOTDOMAIN=$(echo "$FULLDOMAIN" | awk -F '.' '{print $(NF-1)"."$NF}') + SUBDOMAIN=$(echo "$FULLDOMAIN" | sed 's/.'"$ROOTDOMAIN"'//g') + + if [ "$SUBDOMAIN" = "$FULLDOMAIN" ]; then + unset SUBDOMAIN + fi + + _nfs_rest "/dns/$ROOTDOMAIN/addRR" "name=$SUBDOMAIN" 'type=TXT' "data=$2" } # Usage: dns_nfs_rm domain.com "KjiayTfXPHmnHmOdevsOtJyzsU9AHw2T6R0lNVCl_oi" dns_nfs_rm() { - FULLDOMAIN=$1 - ROOTDOMAIN=$(echo "$FULLDOMAIN" | awk -F '.' '{print $(NF-1)"."$NF}') - SUBDOMAIN=$(echo "$FULLDOMAIN" | sed 's/.'"$ROOTDOMAIN"'//g') + FULLDOMAIN=$1 + ROOTDOMAIN=$(echo "$FULLDOMAIN" | awk -F '.' '{print $(NF-1)"."$NF}') + SUBDOMAIN=$(echo "$FULLDOMAIN" | sed 's/.'"$ROOTDOMAIN"'//g') - if [ "$SUBDOMAIN" = "$FULLDOMAIN" ]; then - unset SUBDOMAIN - fi + if [ "$SUBDOMAIN" = "$FULLDOMAIN" ]; then + unset SUBDOMAIN + fi - _nfs_rest "/dns/$ROOTDOMAIN/removeRR" "name=$SUBDOMAIN" 'type=TXT' "data=$2" + _nfs_rest "/dns/$ROOTDOMAIN/removeRR" "name=$SUBDOMAIN" 'type=TXT' "data=$2" } #################### Private functions below ################################## # Usage add: _nfs_rest "/dns/domain.com/addRR" "name=" 'type=TXT' "data=KjiayTfXPHmnHmOdevsOtJyzsU9AHw2T6R0lNVCl_oi" # remove: _nfs_rest "/dns/domain.com/removeRR" "name=www" 'type=TXT' "data=KjiayTfXPHmnHmOdevsOtJyzsU9AHw2T6R0lNVCl_oi" -_nfs_rest () { - - # Make sure NFS_ACCOUNT is set else exit - if [ -z "$NFS_ACCOUNT" ]; then - echo "NFS_ACCOUNT is not set, run 'export NFS_ACCOUNT=\"your_nearly_free_speech_account\" and rerun." - exit 1 - fi - - # Make sure NFS_API_KEY is set else exit - if [ -z "$NFS_API_KEY" ]; then - echo "NFS_API_KEY is not set, run 'export NFS_API_KEY=\"your_nearly_free_speech_api_key\" and rerun." - exit 1 - fi - - TIMESTAMP=$(date +%s) - SALT=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 16) - REQUEST_URI="$1" - - if [ "$#" -gt "1" ]; then - PARAMETERS="$2" - fi - - COUNT=3 - while test $COUNT -le $# - do - eval "PARAMETER=\$$COUNT" - # shellcheck disable=SC2153 - PARAMETERS="$PARAMETERS&$PARAMETER" - COUNT=$((COUNT + 1)) - done - - BODY=$PARAMETERS - BODY_HASH=$(printf "%s" "$BODY" | sha1sum | awk '{print $1}') - HASH_STRING=$(printf "%s" "$NFS_ACCOUNT;$TIMESTAMP;$SALT;$NFS_API_KEY;$REQUEST_URI;$BODY_HASH") - HASH=$(printf "%s" "$HASH_STRING" | sha1sum | awk '{print $1}') - - printf "%s" "$(curl -s -o - -k -X POST -H "X-NFSN-Authentication: $NFS_ACCOUNT;$TIMESTAMP;$SALT;$HASH" -d "$BODY" "https://api.nearlyfreespeech.net$REQUEST_URI")" -} \ No newline at end of file +_nfs_rest() { + + # Make sure NFS_ACCOUNT is set else exit + if [ -z "$NFS_ACCOUNT" ]; then + echo "NFS_ACCOUNT is not set, run 'export NFS_ACCOUNT=\"your_nearly_free_speech_account\" and rerun." + exit 1 + fi + + # Make sure NFS_API_KEY is set else exit + if [ -z "$NFS_API_KEY" ]; then + echo "NFS_API_KEY is not set, run 'export NFS_API_KEY=\"your_nearly_free_speech_api_key\" and rerun." + exit 1 + fi + + TIMESTAMP=$(date +%s) + SALT=$(tr -dc 'a-zA-Z0-9'