aboutsummaryrefslogtreecommitdiff
path: root/setup.sh
blob: 8159db67561c5fd7762fd281366ab7994cb62a21 (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
#!/bin/sh

# https://stackoverflow.com/questions/2990414/echo-that-outputs-to-stderr
errcho(){ >&2 echo "$@"; }

# run this script as root, once, at installation
if id -u 0tdns > /dev/null 2>&1; then
    errcho "User 0tdns already exists."
    errcho "Do you have Zero Trust DNS already set up?"
    errcho "If so, you need to uninstall it properly"
    errcho "(e.g. via provided uninstall.sh script)"
    errcho "before setting it up again"
    exit 1
fi

if [ `id -u` != 0 ]; then
    errcho "This script needs to be run as root"
    exit 1
fi

# part of the program running inside network namespace
# will run under this user
useradd --system 0tdns

# crontab automatically adds a 'DO NOT EDIT' header to
# crontab file; if we don't remove it every time - headers
# will accumulate :/ (not on Debian, though)
# line we want to add to crontab is in 0tdns_crontab file
crontab -l 2> /dev/null |
    grep -vE '^# DO NOT EDIT THIS FILE|^# \(- installed on .*\)|^# \(Cron version .*\)' |
    cat - 0tdns_crontab | crontab