summaryrefslogtreecommitdiff
path: root/gen-new-auth-token
blob: 681f35afdf194be8eb031a6c4535c7127f06f378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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