tools -> scripts

This commit is contained in:
2025-11-14 10:44:57 +08:00
parent 0493f18b18
commit c7449f4acb
70 changed files with 369 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
DUCK_TOKEN=
DUCK_DOMAINS=
DUCK_IP=

2
scripts/duckdns/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.env
*.log

9
scripts/duckdns/install.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
thisdir="$( dirname "$(readlink -e -- "${BASH_SOURCE[0]}")")"
# https://www.duckdns.org/install.jsp
croncmd="$thisdir/update.sh"
cronjob="*/30 * * * * $croncmd" # every 30 min
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -
cp -f "$thisdir/.env.example" "$thisdir/.env"

3
scripts/duckdns/uninstall.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
( crontab -l | grep -v -F "duckdns" ) | crontab -

30
scripts/duckdns/update.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
# shellcheck disable=SC1091
thisdir="$( dirname "$(readlink -e -- "${BASH_SOURCE[0]}")")"
log() {
timestamp="$(date +'%Y-%m-%d %H:%M:%S')"
datestamp="$(date +'%Y-%m-%d')"
[ ! -d "$thisdir/log" ] && mkdir "$thisdir/log"
echo "[$timestamp] $*" >> "$thisdir/log/$datestamp.log"
}
[ ! -f "$thisdir/.env" ] && {
log "ERROR: .env not exists"
exit 1
}
source "$thisdir/.env"
[ -z "$DUCK_TOKEN" ] && {
log "ERROR: env var DUCK_TOKEN not specified"
exit 1
}
[ -z "$DUCK_DOMAINS" ] && {
log "ERROR: env var DUCK_DOMAINS not specified"
exit 1
}
result=$(curl -s "https://www.duckdns.org/update?domains=${DUCK_DOMAINS}&token=${DUCK_TOKEN}&ip=${DUCK_IP}")
log "$result"