aboutsummaryrefslogtreecommitdiff
path: root/setup.sh
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-06-04 20:41:50 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-06-04 20:41:50 +0200
commit3dbec14a792b2ea6d8f67a6090d57f0f1859e6d9 (patch)
tree9527df38ab3c86f12759a7781d6b777bbc168466 /setup.sh
parent5921557e322c0386ebc9a4ae00a9466c484eefb4 (diff)
download0tdns-3dbec14a792b2ea6d8f67a6090d57f0f1859e6d9.tar.gz
0tdns-3dbec14a792b2ea6d8f67a6090d57f0f1859e6d9.zip
integrate with cron daemon
Diffstat (limited to 'setup.sh')
-rwxr-xr-xsetup.sh24
1 files changed, 23 insertions, 1 deletions
diff --git a/setup.sh b/setup.sh
index 959a48f..8159db6 100755
--- a/setup.sh
+++ b/setup.sh
@@ -1,9 +1,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
-# more will go here (e.g. initialization of postgres database)
+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