mirror of
https://github.com/EV21/dynb.git
synced 2025-12-26 16:39:32 +01:00
fix: 🐛 fix sourcing of config file
♻️ do some shellcheck fixes
This commit is contained in:
@@ -11,6 +11,12 @@
|
|||||||
|
|
||||||
* :sparkles: add dynb. [Eduard Veit]
|
* :sparkles: add dynb. [Eduard Veit]
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
* :bug: fix sourcing of config file. [Eduard Veit]
|
||||||
|
|
||||||
|
:recycle: do some shellcheck fixes
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
* :memo: add CHANGELOG.md. [Eduard Veit]
|
* :memo: add CHANGELOG.md. [Eduard Veit]
|
||||||
|
|||||||
49
dynb.sh
49
dynb.sh
@@ -12,16 +12,16 @@ _version=0.1.0
|
|||||||
## Configuration ##
|
## Configuration ##
|
||||||
###################
|
###################
|
||||||
|
|
||||||
_dyn_domain=dyndns.example.com
|
_dyn_domain=
|
||||||
|
|
||||||
## service provider could be inwx
|
## service provider could be inwx
|
||||||
_serviceProvider=inwx
|
_serviceProvider=
|
||||||
|
|
||||||
## update method options: domrobot, dyndns
|
## update method options: domrobot, dyndns
|
||||||
_update_method=domrobot
|
_update_method=
|
||||||
|
|
||||||
## ip mode could be either: 4, 6 or dual for dualstack
|
## ip mode could be either: 4, 6 or dual for dualstack
|
||||||
_ip_mode=dual
|
_ip_mode=
|
||||||
|
|
||||||
## If you are using the DomRobot RPC-API enter your credentials for the web interface login here
|
## If you are using the DomRobot RPC-API enter your credentials for the web interface login here
|
||||||
## If you are using the DynDNS2 protocol enter your credentials here
|
## If you are using the DynDNS2 protocol enter your credentials here
|
||||||
@@ -83,18 +83,20 @@ dynb --ip-mode dualstack --update-method dyndns --service-provider inwx --domain
|
|||||||
EOF
|
EOF
|
||||||
)"
|
)"
|
||||||
|
|
||||||
|
function echoerr() { printf "%s\n" "$*" >&2; }
|
||||||
|
|
||||||
# The main domain or another identifier for the zone is required for the updateRecord call
|
# The main domain or another identifier for the zone is required for the updateRecord call
|
||||||
function getMainDomain() {
|
function getMainDomain() {
|
||||||
request=$( echo "{}" | \
|
request=$( echo "{}" | \
|
||||||
jq '(.method="'nameserver.list'")' | \
|
jq '(.method="nameserver.list")' | \
|
||||||
jq '(.params.user="'$_username'")' | \
|
jq "(.params.user=\"$_username\")" | \
|
||||||
jq '(.params.pass="'$_password'")'
|
jq "(.params.pass=\"$_password\")"
|
||||||
)
|
)
|
||||||
|
|
||||||
response=$(curl --silent \
|
response=$(curl --silent \
|
||||||
--request POST $_INWX_JSON_API_URL \
|
--request POST $_INWX_JSON_API_URL \
|
||||||
--header "Content-Type: application/json" \
|
--header "Content-Type: application/json" \
|
||||||
--data "$request" | jq '.resData.domains[] | select(inside(.domain="'"$_dyn_domain"'"))'
|
--data "$request" | jq ".resData.domains[] | select(inside(.domain=\"$_dyn_domain\"))"
|
||||||
)
|
)
|
||||||
_main_domain=$( echo "$response" | jq --raw-output '.domain' )
|
_main_domain=$( echo "$response" | jq --raw-output '.domain' )
|
||||||
}
|
}
|
||||||
@@ -102,10 +104,10 @@ function getMainDomain() {
|
|||||||
function fetchDNSRecords() {
|
function fetchDNSRecords() {
|
||||||
request=$( echo "{}" | \
|
request=$( echo "{}" | \
|
||||||
jq '(.method="'nameserver.info'")' | \
|
jq '(.method="'nameserver.info'")' | \
|
||||||
jq '(.params.user="'$_username'")' | \
|
jq "(.params.user=\"$_username\")" | \
|
||||||
jq '(.params.pass="'$_password'")' | \
|
jq "(.params.pass=\"$_password\")" | \
|
||||||
jq '(.params.domain="'"$_main_domain"'")' | \
|
jq "(.params.domain=\"$_main_domain\")" | \
|
||||||
jq '(.params.name="'"$_dyn_domain"'")'
|
jq "(.params.name=\"$_dyn_domain\")"
|
||||||
)
|
)
|
||||||
|
|
||||||
response=$( curl --silent \
|
response=$( curl --silent \
|
||||||
@@ -114,19 +116,19 @@ function fetchDNSRecords() {
|
|||||||
--data "$request"
|
--data "$request"
|
||||||
)
|
)
|
||||||
|
|
||||||
_dns_records=$( echo $response | jq '.resData.record[]' )
|
_dns_records=$( echo "$response" | jq '.resData.record[]' )
|
||||||
}
|
}
|
||||||
|
|
||||||
# requires parameter A or AAAA
|
# requires parameter A or AAAA
|
||||||
# result to stdout
|
# result to stdout
|
||||||
function getRecordID() {
|
function getRecordID() {
|
||||||
echo $_dns_records | jq 'select(.type == "'${1}'") | .id'
|
echo "$_dns_records" | jq "select(.type == \"${1}\") | .id"
|
||||||
}
|
}
|
||||||
|
|
||||||
# requires parameter A or AAAA
|
# requires parameter A or AAAA
|
||||||
# result to stdout
|
# result to stdout
|
||||||
function getDNSIP() {
|
function getDNSIP() {
|
||||||
echo $_dns_records | jq --raw-output 'select(.type == "'${1}'") | .content'
|
echo "$_dns_records" | jq --raw-output "select(.type == \"${1}\") | .content"
|
||||||
}
|
}
|
||||||
|
|
||||||
# requires parameter
|
# requires parameter
|
||||||
@@ -134,7 +136,7 @@ function getDNSIP() {
|
|||||||
# 2. param: IP check server address
|
# 2. param: IP check server address
|
||||||
# result to stdout
|
# result to stdout
|
||||||
function getRemoteIP() {
|
function getRemoteIP() {
|
||||||
curl --silent --ipv${1} --dns-servers 1.1.1.1 --location ${2}
|
curl --silent --ipv"${1}" --dns-servers 1.1.1.1 --location "${2}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# requires parameter
|
# requires parameter
|
||||||
@@ -150,13 +152,14 @@ function updateRecord() {
|
|||||||
fi
|
fi
|
||||||
if [[ $IP != "" ]]; then
|
if [[ $IP != "" ]]; then
|
||||||
request=$( echo "{}" | \
|
request=$( echo "{}" | \
|
||||||
jq '(.method="'nameserver.updateRecord'")' | \
|
jq '(.method="nameserver.updateRecord")' | \
|
||||||
jq '(.params.user="'$_username'")' | \
|
jq "(.params.user=\"$_username\")" | \
|
||||||
jq '(.params.pass="'$_password'")' | \
|
jq "(.params.pass=\"$_password\")" | \
|
||||||
jq '(.params.id="'$ID'")' | \
|
jq "(.params.id=\"$ID\")" | \
|
||||||
jq '(.params.content="'$IP'")' | \
|
jq "(.params.content=\"$IP\")" | \
|
||||||
jq '(.params.ttl="'$TTL'")'
|
jq "(.params.ttl=\"$TTL\")"
|
||||||
)
|
)
|
||||||
|
|
||||||
response=$(curl --silent \
|
response=$(curl --silent \
|
||||||
--request POST $_INWX_JSON_API_URL \
|
--request POST $_INWX_JSON_API_URL \
|
||||||
--header "Content-Type: application/json" \
|
--header "Content-Type: application/json" \
|
||||||
@@ -363,7 +366,7 @@ function checkDependencies() {
|
|||||||
## MAIN section ##
|
## MAIN section ##
|
||||||
##################
|
##################
|
||||||
|
|
||||||
FILE=$(dirname "$0")/.env
|
FILE=$(dirname "$(realpath "$0")")/.env
|
||||||
if test -f "$FILE"; then
|
if test -f "$FILE"; then
|
||||||
# shellcheck source=.env
|
# shellcheck source=.env
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
|
|||||||
Reference in New Issue
Block a user