1
0
mirror of https://github.com/EV21/dynb.git synced 2025-12-26 16:39:32 +01:00

11 Commits

Author SHA1 Message Date
5210c35400 ♻️ refactor, fix and debug error handling 2021-01-27 17:52:15 +01:00
522a0f99bb ♻️ refactor main code 2021-01-26 22:23:03 +01:00
3bf6b69ae8 add interpretaton of status codes and act accordingly 2021-01-26 21:43:07 +01:00
d139022295 make network interface configurable 2021-01-26 21:43:07 +01:00
8997835903 🐛 fix sourcing of config file
♻️ do some shellcheck fixes
2021-01-26 21:43:07 +01:00
d6dc223794 add DynDNS2 support for dynv6.com 2021-01-26 21:43:07 +01:00
dc12f71d00 📝 add CHANGELOG.md 2021-01-26 21:43:07 +01:00
5ba730cff1 add .gitchangelog.rc 2021-01-26 21:43:07 +01:00
1104cf8505 📝 add example.env 2021-01-26 21:43:07 +01:00
99a446f4c7 📝 write README.md 2021-01-26 21:42:21 +01:00
f056e96e25 add dynb.sh 2021-01-26 21:24:33 +01:00
11 changed files with 247 additions and 973 deletions

View File

@@ -1,9 +0,0 @@
**/.env
**/.dockerignore
**/.docker-compose.debug.yml
**/.docker-compose.yml
**/.git
**/.gitignore
**/.gitchangelog.rc
man/man.rst
man/man-defs.rst

3
.gitignore vendored
View File

@@ -1,2 +1 @@
.env*
docker-compose*
.env*

View File

@@ -1,42 +1,10 @@
# Changelog
## 0.1.2 (2021-04-23)
### Documentation
* :memo: document environment variables. [Eduard Veit]
### Other
* :recycle: refactor: method extractions and other beautifications. [Eduard Veit]
## 0.1.1 (2021-04-23)
### Fix
* :bug: fix loop and error handling in case of connection issues. [Eduard Veit]
## 0.1.0 (2021-04-22)
## (unreleased)
### New
* :sparkles: add Dockerfile. [Eduard Veit]
* :sparkles: add loop mode. [Eduard Veit]
* :sparkles: add support for Duck DNS as DynDNS2 provider. [Eduard Veit]
* :sparkles: add support for deSEC as DynDNS2 provider. [Eduard Veit]
* :sparkles: add completion. [Eduard Veit]
:sparkles: add man page
* :sparkles: replace getopt with argbash. [Eduard Veit]
* :sparkles: add interpretaton of status codes and act accordingly. [Eduard Veit]
* :sparkles: make network interface configurable. [Eduard Veit]
@@ -45,7 +13,7 @@
* :sparkles: add .gitchangelog.rc. [Eduard Veit]
* :sparkles: add dynb.sh. [Eduard Veit]
* :sparkles: add dynb. [Eduard Veit]
### Fix
@@ -55,26 +23,14 @@
### Documentation
* :memo: document example of an docker-compose.yml file. [Eduard Veit]
* :memo: document loop mode and dig as requirement. [Eduard Veit]
* :memo: update example of .env in README.md. [Eduard Veit]
* :memo: add CHANGELOG.md. [Eduard Veit]
* :memo: add example.env. [Eduard Veit]
* :memo: add .env.example. [Eduard Veit]
* :memo: write README.md. [Eduard Veit]
### Other
* :recycle: refactor: rename environment variables. [Eduard Veit]
* :recycle: refactor, fix and debug error handling. [Eduard Veit]
* :recycle: refactor main code. [Eduard Veit]
* Initial commit. [EV21]

View File

@@ -1,5 +0,0 @@
FROM alpine:latest
RUN apk update && apk add bash curl jq bind-tools
WORKDIR /usr/src/app
COPY . .
CMD /bin/bash /usr/src/app/dynb.sh

View File

@@ -11,7 +11,6 @@ IPv4 (A) and IPv6 (AAAA) record updates are supported.
- [⚙ Configuration](#-configuration)
- [🏃 Run](#-run)
- [⏰ Cron](#-cron)
- [🐟 docker](#-docker)
<!-- /TOC -->
## ✨ Update Methods
@@ -19,26 +18,27 @@ The following update methods are currently implemented:
### APIs
* INWX.com Domrobot JSON-RPC-API
* INWX.com JSON-RPC-API
Limitations:
- minimum TTL is 300 (5 minutes)
### DynDNS2
* INWX.com
* deSEC.io (dedyn.io)
* DuckDNS.org
* dynv6.com
* dynv6.com
## 📦 Requirements
* `curl` - The minimum requirement for all API requests.
* `dig` - You can get it by installing `dnsutils` (debian/ubuntu/ArchLinux), `bind-utils` (CentOS/RHEL), `bind-tools` (Alpine)
* `curl` - The minimum requirement for running DynDNS2 operations
also essential if you are using other APIs:
essential for APIs:
* `jq` - Command-line JSON processor
optional requirement:
* `getopt` for CLI parameter handling from [util-linux](https://pkgs.org/download/util-linux)
## 🚀 Installation
Download the latest release
@@ -52,31 +52,30 @@ If you want to add the script to you PATH, run :point_down:
```
bash dynb.sh --link
```
This convenience function only works if `util-linux` is installed on your system.
## ⚙ Configuration
You can use a config in form of an `.env` file.
Or you can just use CLI parameters.
Or if your system meets the relevant requirements you can use CLI parameters.
Create `.env` in the app root directory or at `~/.local/share/dynb/.env`.
```
DYNB_DYN_DOMAIN=dyndns.example.com
_dyn_domain=dyndns.example.com
## service provider could be deSEC, duckdns, dynv6, inwx
DYNB_SERVICE_PROVIDER=inwx
## service provider could be inwx
_serviceProvider=inwx
## update method options: domrobot, dyndns
DYNB_UPDATE_METHOD=domrobot
_update_method=domrobot
## ip mode could be either: 4, 6 or dual for dualstack
DYNB_IP_MODE=64
_ip_mode=dual
## 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
DYNB_USERNAME=User42
DYNB_PASSWORD=SuperSecretPassword
## or use a token
DYNB_TOKEN=
_username=
_password=
```
## 🏃 Run
@@ -98,14 +97,7 @@ dynb --ip-mode dualstack --update-method dyndns --provider inwx --domain dyndns.
```
## ⏰ Cron
To automatically call the script you can use either crontab or the script can also run in a loop mode.
### loop mode
Just use the parameter `--interval 60` or the environment variable `DYNB_INTERVAL=60` so the script will check every 60 seconds if it needs to do an update.
### crontab
To automatically call the script you can use cron.
execute :point_down:
```
@@ -116,42 +108,3 @@ then enter :point_down: to run dynb every five minutes.
*/5 * * * * $HOME/.local/bin/dynb >> $HOME/.local/share/dynb/dynb-cron.log
```
Note, cron typically does not use the users PATH variable.
## 🐟 docker
This is an example of a `docker-compose.yml` file. If you are using IPv6 make sure the routing works properly with your docker container.
```yaml
version: '3.4'
services:
dynb:
image: ev21/dynb
container_name: dynb
network_mode: host
build:
context: .
dockerfile: ./Dockerfile
environment:
- DYNB_DYN_DOMAIN=dyndns.example.com
- DYNB_SERVICE_PROVIDER=inwx
- DYNB_UPDATE_METHOD=dyndns
- DYNB_IP_MODE=64
- DYNB_USERNAME=User42
- DYNB_PASSWORD=SuperSecretPassword
- DYNB_INTERVAL=60
```
## environment variables
| variable | default value | description |
| --------------------- | --------------- | ----------- |
| DYNB_DYN_DOMAIN | undefined | required |
| DYNB_SERVICE_PROVIDER | undefined | required |
| DYNB_UPDATE_METHOD | undefined | required |
| DYNB_IP_MODE | undefined | required |
| DYNB_USERNAME | undefined | the requirement depends on your provider and the update method |
| DYNB_PASSWORD | undefined | the requirement depends on your provider and the update method |
| DYNB_TOKEN | undefined | the requirement depends on your provider and the update method |
| DYNB_INTERVAL | undefined | without this setting the script/docker container will run one time and exits |
| DYNB_DEBUG | undefined | more console outputs |
| DYNB_IPv4_CHECK_SITE | api64.ipify.org | You need a website or Web-API that outputs your remote IP |
| DYNB_IPv6_CHECK_SITE | api64.ipify.org | You need a website or Web-API that outputs your remote IP |
| DYNB_DNS_CHECK_SERVER | 1.1.1.1 | If you are using a local DNS Resolver/Server make sure it answers with the public answer |

View File

@@ -1,41 +0,0 @@
#!/bin/bash
# Put this file to /etc/bash_completion.d/dynb.sh
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.10.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
_dynb_sh ()
{
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
all_long_opts="--version --link --reset --debug --update-method --ip-mode --domain --service-provider --username --password --token --interval --help "
all_short_opts="-v -l -r -m -i -d -s -u -p -t -h "
case "$prev" in
--update-method|-m|--ip-mode|-i|--domain|-d|--service-provider|-s|--username|-u|--password|-p|--token|-t|--interval)
COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )
return 0
;;
*)
case "$cur" in
--*)
COMPREPLY=( $(compgen -W "${all_long_opts}" -- "${cur}") )
return 0
;;
-*)
COMPREPLY=( $(compgen -W "${all_short_opts}" -- "${cur}") )
return 0
;;
*)
COMPREPLY=( $(compgen -o bashdefault -o default -- "${cur}") )
return 0
;;
esac
esac
}
complete -F _dynb_sh dynb.sh
### END OF CODE GENERATED BY Argbash (sortof) ### ])

764
dynb.sh

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,7 @@
###################
## Configuration ##
###################
DYNB_DYN_DOMAIN=dyndns.example.com
## service provider could be deSEC, duckdns, dynv6, inwx
DYNB_SERVICE_PROVIDER=inwx
## update method options: domrobot, dyndns
DYNB_UPDATE_METHOD=domrobot
## ip mode could be either: 4, 6 or dual for dualstack
DYNB_IP_MODE=64
## 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
DYNB_USERNAME=User42
DYNB_PASSWORD=SuperSecretPassword
## or use a token
DYNB_TOKEN=
_dyn_domain=dyndns.example.com
_serviceProvider=inwx
_update_method=domrobot
_ip_mode=dual
_username=User42
_password=SuperSecretPassword
_token=

View File

@@ -1,114 +0,0 @@
.\" Man page generated from reStructuredText.
.
.TH MAN 1 "2021-04-21" "" ""
.SH NAME
man \- DynB - dynamic DNS update script for bash
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.SH SYNOPSIS
.sp
\fBman [\-\-version] [\-\-link] [\-\-reset] [\-\-debug] [\-\-update\-method UPDATE\-METHOD] [\-\-ip\-mode IP\-MODE] [\-\-domain DOMAIN] [\-\-service\-provider SERVICE\-PROVIDER] [\-\-username USERNAME] [\-\-password PASSWORD] [\-\-token TOKEN] [\-\-interval INTERVAL] [\-\-help]\fP
.SH DESCRIPTION
.sp
IPv4 (A) and IPv6 (AAAA) record updates are supported.
.SH ARGUMENTS
.INDENT 0.0
.TP
.B \-v\fP,\fB \-\-version
outputs the client version.
[Default: off]
.sp
.TP
.B \-l\fP,\fB \-\-link
links to your script at ~/.local/bin/dynb.
[Default: off]
.sp
.TP
.B \-r\fP,\fB \-\-reset
deletes the client blocking status file.
[Default: off]
.sp
.TP
.B \-\-debug
enables debug mode.
[Default: off]
.sp
.TP
.BI \-m \ UPDATE\-METHOD\fR,\fB \ \-\-update\-method \ UPDATE\-METHOD
choose if you want to use DynDNS2 or the DomRobot RPC\-API.
.sp
dyndns | domrobot
.TP
.BI \-i \ IP\-MODE\fR,\fB \ \-\-ip\-mode \ IP\-MODE
updates type A (IPv4) and AAAA (IPv6) records.
.sp
4 | 6 | dual
.TP
.BI \-d \ DOMAIN\fR,\fB \ \-\-domain \ DOMAIN
set the domain you want to update.
.sp
dyndns.example.com
.TP
.BI \-s \ SERVICE\-PROVIDER\fR,\fB \ \-\-service\-provider \ SERVICE\-PROVIDER
set your provider in case you are using DynDNS2.
.sp
deSEC | duckdns | dynv6 | inwx
.TP
.BI \-u \ USERNAME\fR,\fB \ \-\-username \ USERNAME
depends on your selected update method and your provider.
.sp
e.g. user42
.TP
.BI \-p \ PASSWORD\fR,\fB \ \-\-password \ PASSWORD
depends on your selected update method and your provider.
.sp
e.g. SuperSecretPassword
.TP
.BI \-t \ TOKEN\fR,\fB \ \-\-token \ TOKEN
depends on your selected update method and your provider.
.sp
YourProviderGivenToken
.TP
.BI \-\-interval \ INTERVAL
choose the seconds interval to run the script in a loop, minimum is 60.
.sp
.TP
.B \-h\fP,\fB \-\-help
Prints help.
.sp
.UNINDENT
.SH AUTHOR
Eduard Veit
.\" Generated by docutils manpage writer.
.

View File

@@ -1,35 +0,0 @@
.. |AUTHOR| replace:: Eduard Veit
.. |VERSION| replace:: \
.. |MAN_SECTION| replace:: 1
.. |DESCRIPTION| replace::
IPv4 (A) and IPv6 (AAAA) record updates are supported.
.. |OPTION_VERSION| replace:: \
.. |OPTION_LINK| replace:: \
.. |OPTION_RESET| replace:: \
.. |OPTION_DEBUG| replace:: \
.. |OPTION_UPDATE_METHOD| replace:: dyndns | domrobot
.. |OPTION_IP_MODE| replace:: 4 | 6 | dual
.. |OPTION_DOMAIN| replace:: dyndns.example.com
.. |OPTION_SERVICE_PROVIDER| replace:: deSEC | duckdns | dynv6 | inwx
.. |OPTION_USERNAME| replace:: e.g. user42
.. |OPTION_PASSWORD| replace:: e.g. SuperSecretPassword
.. |OPTION_TOKEN| replace:: YourProviderGivenToken
.. |OPTION_INTERVAL| replace:: \
.. |OPTION_HELP| replace:: \

View File

@@ -1,88 +0,0 @@
.. include:: man-defs.rst
===
man
===
-----------------------------------------
DynB - dynamic DNS update script for bash
-----------------------------------------
:Author: |AUTHOR|
:Date: 2021-04-21
:Version: |VERSION|
:Manual section: |MAN_SECTION|
SYNOPSIS
========
``man [--version] [--link] [--reset] [--debug] [--update-method UPDATE-METHOD] [--ip-mode IP-MODE] [--domain DOMAIN] [--service-provider SERVICE-PROVIDER] [--username USERNAME] [--password PASSWORD] [--token TOKEN] [--interval INTERVAL] [--help]``
DESCRIPTION
===========
|DESCRIPTION|
ARGUMENTS
=========
-v, --version outputs the client version.
[Default: off]
|OPTION_VERSION|
-l, --link links to your script at ~/.local/bin/dynb.
[Default: off]
|OPTION_LINK|
-r, --reset deletes the client blocking status file.
[Default: off]
|OPTION_RESET|
--debug enables debug mode.
[Default: off]
|OPTION_DEBUG|
-m UPDATE-METHOD, --update-method UPDATE-METHOD choose if you want to use DynDNS2 or the DomRobot RPC-API.
|OPTION_UPDATE_METHOD|
-i IP-MODE, --ip-mode IP-MODE updates type A (IPv4) and AAAA (IPv6) records.
|OPTION_IP_MODE|
-d DOMAIN, --domain DOMAIN set the domain you want to update.
|OPTION_DOMAIN|
-s SERVICE-PROVIDER, --service-provider SERVICE-PROVIDER set your provider in case you are using DynDNS2.
|OPTION_SERVICE_PROVIDER|
-u USERNAME, --username USERNAME depends on your selected update method and your provider.
|OPTION_USERNAME|
-p PASSWORD, --password PASSWORD depends on your selected update method and your provider.
|OPTION_PASSWORD|
-t TOKEN, --token TOKEN depends on your selected update method and your provider.
|OPTION_TOKEN|
--interval INTERVAL choose the seconds interval to run the script in a loop, minimum is 60.
|OPTION_INTERVAL|
-h, --help Prints help.
|OPTION_HELP|