This repository was archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·89 lines (74 loc) · 2.86 KB
/
setup.sh
File metadata and controls
executable file
·89 lines (74 loc) · 2.86 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -e
if ! ( command -v sudo > /dev/null ); then
echo "sudo is required in order to install and configure Zercurity
Please run the commands below to install sudo:
"
echo "su -"
echo "apt -y install sudo"
echo "echo '$(whoami) ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/$(whoami) ;"
echo "chmod 440 /etc/sudoers.d/$(whoami) ;"
echo "exit"
exit 1
fi
INSTALL_PATH="/var/lib/zercurity"
ENV_FILE="$INSTALL_PATH/production.env"
SYSTEM_SERVICE="/etc/systemd/system/zercurity.service"
if [[ ! -d "$INSTALL_PATH" ]]; then
echo "Installing Zercurity to: $INSTALL_PATH"
sudo mkdir -p "$INSTALL_PATH"
fi
if [[ ! -f "$ENV_FILE" ]]; then
echo "Default environment file: $ENV_FILE"
sudo cp ./example.env "$ENV_FILE"
sudo chmod 600 "$ENV_FILE"
fi
# Check sudo permissions
# sudo -l
# shellcheck disable=SC2046
export $(sudo cat $ENV_FILE | grep -v '#' | awk '/=/ {print $1}')
if [[ -z "${ZERCURITY_DOMAIN}" ]]; then
echo "The environment variable \"ZERCURITY_DOMAIN\" is not set.
A domain name is required in order to continue. e.g. zercurity.local.
Please enter one now .."
read -r ZERCURITY_DOMAIN
export ZERCURITY_DOMAIN=$ZERCURITY_DOMAIN
echo "ZERCURITY_DOMAIN=$ZERCURITY_DOMAIN" | sudo tee -a "$ENV_FILE"
fi
if [[ -z "${SECRET}" ]]; then
ZERCURITY_SECRET=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 32 | head -n 1)
export SECRET=$ZERCURITY_SECRET
echo "SECRET=$ZERCURITY_SECRET" | sudo tee -a "$ENV_FILE"
fi
if [[ -z "${GRAFANA_ADMIN_PASSWORD}" ]]; then
GRAFANA_PASSWORD=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 16 | head -n 1)
export "$GRAFANA_ADMIN_PASSWORD"="$GRAFANA_PASSWORD"
echo "$GRAFANA_ADMIN_PASSWORD=$GRAFANA_PASSWORD" | sudo tee -a "$ENV_FILE"
fi
echo "Starting up as \"$ZERCURITY_DOMAIN\" .."
sudo mkdir -p "$INSTALL_PATH/certs/$ZERCURITY_DOMAIN/"
sudo mkdir -p "$INSTALL_PATH/secrets/$ZERCURITY_DOMAIN/"
sudo mkdir -p "$INSTALL_PATH/data/backend/download.$ZERCURITY_DOMAIN/"
sudo mkdir -p "$INSTALL_PATH/data/postgres/"
sudo mkdir -p "$INSTALL_PATH/data/grafana/"
if [[ ! -f "$SYSTEM_SERVICE" ]]; then
sudo cp zercurity.service "$SYSTEM_SERVICE"
sudo systemctl daemon-reload
sudo systemctl enable zercurity
fi
sudo -- sh -c "echo \"127.0.0.1 $ZERCURITY_DOMAIN app.$ZERCURITY_DOMAIN api.$ZERCURITY_DOMAIN download.$ZERCURITY_DOMAIN grafana.$ZERCURITY_DOMAIN\" >> /etc/hosts"
./update.sh
echo "Zercurity has now been successfully setup."
echo ""
echo "Please visit each of the following URLs to both ensure
a successful deployment but also accept the self-signed
certificates. Otherwise, the app will not load:"
echo ""
echo "-> https://api.$ZERCURITY_DOMAIN/"
echo "-> https://download.$ZERCURITY_DOMAIN/"
echo "-> https://app.$ZERCURITY_DOMAIN/"
echo ""
echo "You can create your first user with the following command:"
echo ""
echo "docker exec zercurity_backend_1 ./zercurity --register --name \"$(whoami)\" --email \"your@email.com\""
echo ""