From b11f3ae95046f1c7ef1ffd2974839faa6d982f2d Mon Sep 17 00:00:00 2001 From: redxef Date: Tue, 21 Feb 2023 20:45:50 +0100 Subject: [PATCH] Add Dockerfile. --- Dockerfile | 15 +++++++++++++++ README.md | 20 ++++++++++++++++++++ main.py | 2 -- periodic.sh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 periodic.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a262943 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:latest + +RUN apk --no-cache add \ + python3 \ + py3-pip \ + py3-yaml \ + py3-click \ + py3-dnspython \ + && python3 -m pip install \ + ovh \ + schema + +COPY main.py /usr/local/bin/ovhddns +COPY periodic.sh /usr/local/bin/ovhddns-periodic +ENTRYPOINT [ "ovhddns-periodic" ] diff --git a/README.md b/README.md new file mode 100644 index 0000000..8632ed8 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# OVHDDNS + +Update a OVH subdomain to own IP. + +## Configuration file + +```yaml +--- +ovh: + application_key: str + application_secret: str + consumer_key: str + endpoint: str +zone: str; example: redxef.at +subdomain: str; example: subdomain-xyz +field_type: *Optional* str; example: 'A' or 'AAAA' +logging: *Optional* + level: *Optional* str; default: :WARNING,ovhdns:INFO +ttl: *Optional* int; default: None +``` diff --git a/main.py b/main.py index e523e92..24f9378 100755 --- a/main.py +++ b/main.py @@ -1,13 +1,11 @@ #!/usr/bin/env python3 import itertools -import json import os import sys import logging import yaml -import schema import click import ovh import dns.resolver diff --git a/periodic.sh b/periodic.sh new file mode 100755 index 0000000..de6b212 --- /dev/null +++ b/periodic.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +pids="" + +run_prog() { + "$@" & + pids="$! $pids" +} + +trap_sig() { + printf '%s' "$pids" | while IFS= read -r pid; do + echo "pid=$pid" + # shellcheck disable=2086 + kill -s $1 $pid + done +} + +trap 'trap_sig TERM' TERM + +# default to every 5 minutes +DELAY="${OVHDDNS_INTERVAL_SECONDS:-300}" + +stdin_content="$(cat -)" + +while :; do + echo "$stdin_content" | ovhddns "$@" + run_prog sleep "$DELAY" + wait $pids + pids= +done +