summaryrefslogtreecommitdiff
path: root/gen-new-auth-token
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-03-30 20:20:27 +0100
committerErich Eckner <git@eckner.net>2019-03-30 20:20:27 +0100
commit36c29f82abf95dc1520989a48814b6882a6db374 (patch)
treef72f1b2a6e857cd782fe428f18a7a45d3f731d86 /gen-new-auth-token
downloadddns-36c29f82abf95dc1520989a48814b6882a6db374.tar.xz
Initial commit
Diffstat (limited to 'gen-new-auth-token')
-rwxr-xr-xgen-new-auth-token36
1 files changed, 36 insertions, 0 deletions
diff --git a/gen-new-auth-token b/gen-new-auth-token
new file mode 100755
index 0000000..681f35a
--- /dev/null
+++ b/gen-new-auth-token
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+set -e
+
+echoToken() {
+ base64 < /dev/urandom | \
+ tr -d '\n/+' | \
+ head -c 64
+}
+
+dir="$(dirname "$(readlink -f "$0")")"
+
+read -p 'Subdomain von ddns.eckner.net: ' subDom
+
+if [ -z "${subDom}" ]; then
+ inh="$(sed 's|^.\{64\} ||' "${dir}/tokens")"
+ echo "${inh}" | \
+ while read -r s; do
+ echoToken
+ echo " ${s}"
+ done > \
+ "${dir}/tokens"
+else
+ authToken="$(
+ echoToken
+ )"
+
+ if [ ! -f "${dir}/tokens" ]; then
+ touch "${dir}/tokens"
+ fi
+ chmod 600 "${dir}/tokens"
+
+ sed -i "/ ${subDom}\$/d" "${dir}/tokens"
+
+ echo "${authToken} ${subDom}" >> "${dir}/tokens"
+fi