Skip to content

Commit

Permalink
Shellcheck compliance and double bracket conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo963 committed Feb 22, 2024
1 parent 5a96a01 commit 177df93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions dns_scripts/dns_add_hetzner
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ if [[ -z "$HETZNER_KEY" ]]; then
echo "HETZNER_KEY variable not set"
exit 1
fi
if [ -z "$HETZNER_ZONE_ID" ] && [ -z "$HETZNER_ZONE_NAME" ] ; then
if [[ -z "$HETZNER_ZONE_ID" && -z "$HETZNER_ZONE_NAME" ]] ; then
echo "HETZNER_ZONE_ID and HETZNER_ZONE_NAME variables not set"
exit 1
fi

# Get Zone ID if not set
if [ -z "$HETZNER_ZONE_ID" ] ; then
zone_id=$(curl --silent -X GET "$api_url/zones?name=$HETZNER_ZONE_NAME" -H 'Auth-API-Token: '"$api_key"'' | jq -r '.zones[0].id')
if [ -z "$zone_id" == "null" ] ; then
if [[ -z "$HETZNER_ZONE_ID" ]] ; then
zone_id=$(curl --silent -X GET "$api_url/zones?name=$zone_name" -H 'Auth-API-Token: '"$api_key"'' | jq -r '.zones[0].id')
if [[ "$zone_id" == "null" ]] ; then
echo "Zone ID not found"
exit 1
fi
Expand All @@ -40,10 +40,10 @@ txtname="_acme-challenge.$fulldomain."
response=$(curl --silent -X POST "$api_url/records" \
-H 'Content-Type: application/json' \
-H "Auth-API-Token: $api_key" \
-d '{"value": "'$token'","ttl": 60,"type": "TXT","name": "_acme-challenge.'$fulldomain'.","zone_id": "'$zone_id'"}' \
-d '{"value": "'"$token"'","ttl": 60,"type": "TXT","name": "'"$txtname"'","zone_id": "'"$zone_id"'"}' \
-o /dev/null -w '%{http_code}')

if [ "$response" != "200" ] ; then
if [[ "$response" != "200" ]] ; then
echo "Record not created"
echo "Response code: $response"
exit 1
Expand Down
14 changes: 7 additions & 7 deletions dns_scripts/dns_del_hetzner
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ if [[ -z "$HETZNER_KEY" ]]; then
echo "HETZNER_KEY variable not set"
exit 1
fi
if [ -z "$HETZNER_ZONE_ID" ] && [ -z "$HETZNER_ZONE_NAME" ] ; then
if [[ -z "$HETZNER_ZONE_ID" && -z "$HETZNER_ZONE_NAME" ]] ; then
echo "HETZNER_ZONE_ID and HETZNER_ZONE_NAME variables not set"
exit 1
fi

# Get Zone ID if not set
if [ -z "$HETZNER_ZONE_ID" ] ; then
zone_id=$(curl --silent -X GET "$api_url/zones?name=$HETZNER_ZONE_NAME" -H 'Auth-API-Token: '"$api_key"'' | jq -r '.zones[0].id')
if [ "$zone_id" == "null" ] ; then
if [[ -z "$HETZNER_ZONE_ID" ]] ; then
zone_id=$(curl --silent -X GET "$api_url/zones?name=$zone_name" -H 'Auth-API-Token: '"$api_key"'' | jq -r '.zones[0].id')
if [[ "$zone_id" == "null" ]] ; then
echo "Zone by name not found"
exit 1
fi
Expand All @@ -39,17 +39,17 @@ fi
txtname="_acme-challenge.$fulldomain."


record_id=$(curl --silent -X GET "$api_url/records?zone_id=$zone_id" -H "Auth-API-Token: $api_key" | jq -r '.records[] | select(.name=="'$txtname'") | .id')
record_id=$(curl --silent -X GET "$api_url/records?zone_id=$zone_id" -H "Auth-API-Token: $api_key" | jq -r '.records[] | select(.name=="'"$txtname"'") | .id')

if [ "$record_id" == "null" ] ; then
if [[ "$record_id" == "null" ]] ; then
echo "Record not found"
exit 1
fi

# Create TXT record
response=$(curl --silent -X DELETE "$api_url/records/$record_id" -H "Auth-API-Token: $api_key" -o /dev/null -w '%{http_code}')

if [ "$response" != "200" ] ; then
if [[ "$response" != "200" ]] ; then
echo "Record not deleted"
echo "Response code: $response"
exit 1
Expand Down

0 comments on commit 177df93

Please sign in to comment.