-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathinstall_server.sh
More file actions
122 lines (92 loc) · 3.81 KB
/
install_server.sh
File metadata and controls
122 lines (92 loc) · 3.81 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# Only set if not already set
if [ -z "$PHATCRACK_VERSION_TAG" ]; then
export PHATCRACK_VERSION_TAG=v0.7.0
fi
set -e
is_yes() {
[[ "$1" =~ ^([yY][eE][sS]|[yY])$ ]]
}
if [ "$EUID" -ne 0 ]; then
echo "This script must be run as root. Exiting..."
exit 1
fi
if id "phatcrack-server" &>/dev/null || [ -d "/opt/phatcrack-server" ]; then
echo "Warning: It appears that there is an existing installation of Phatcrack."
echo "Please clean up by ensuring the phatcrack-server user and /opt/phatcrack-server directory do not exist."
echo "(userdel --remove phatcrack-server)"
exit 1
fi
if ! command -v docker &>/dev/null; then
echo "Docker is not installed on this system."
read -p "Do you want to install Docker? (yes/no): " install_docker
if is_yes "$install_docker"; then
echo "Installing Docker..."
case "$(. /etc/os-release && echo "$ID")" in
# EL-derivatvie distros not supported by get.docker.com
rocky|almalinux)
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
;;
*)
curl -fsSL https://get.docker.com | bash
;;
esac
if ! command -v docker &>/dev/null; then
echo "Docker installation failed. Exiting..."
exit 1
else
echo "Docker installed successfully."
systemctl enable --now docker
fi
else
echo "Docker is required to run this script. Exiting..."
exit 1
fi
else
echo "Docker is already installed."
fi
echo "Creating phatcrack-server user..."
useradd --system --create-home --home-dir /opt/phatcrack-server phatcrack-server
cd /opt/phatcrack-server
echo "Downloading docker-compose.yml..."
curl -qLO https://github.com/lachlan2k/phatcrack/releases/download/$PHATCRACK_VERSION_TAG/docker-compose.yml
echo "PHATCRACK_VERSION_TAG=${PHATCRACK_VERSION_TAG}" >> .env
read -p "What DNS hostname will resolve to your Phatcrack instance (leave blank for anything)?: " server_hostname
if [ "$server_hostname" == "" ]; then
echo "HOST_NAME=:443" >> .env
echo "TLS_OPTS=\"tls internal {\\non_demand\\n}\"" >> .env
echo "INSECURE_ORIGIN=1" >> .env
else
echo "HOST_NAME=$server_hostname" >> .env
read -p "Would you like to use self-signed certificates? (yes/no): " use_self_signed
if is_yes "$use_self_signed"; then
echo "TLS_OPTS=tls internal" >> .env
else
read -p "Would you like to provide your own certificates? (yes/no): " provide_certs
if is_yes "$provide_certs"; then
mkdir ./certs
sed -i '/^\s*# - \.\/certs:\/etc\/caddy\/Certs:ro/s/^# //' docker-compose.yml
echo "TLS_OPTS=tls /etc/caddy/certs/cert.pem /etc/caddy/certs/key.pem" >> .env
echo "Please provide your certificates files cert.pem and key.pem in /opt/phatcrack-server/certs/"
echo "You may need to restart the server (docker compose restart)"
else
read -p "Would you like to use Let's Encrypt to provision certificates ($server_hostname must be publicly accessible) ?" use_letsencrypt
if is_yes "$use_letsencrypt"; then
# Default, doesnt need anything
:
else
echo "No supported TLS configuration was accepted"
exit 1
fi
fi
fi
fi
echo "DB_PASS=$(openssl rand -hex 16)" >> .env
echo "PHATCRACK_USER=$(id -u phatcrack-server):$(id -g phatcrack-server)" >> .env
chmod 600 .env
mkdir filerepo
chown phatcrack-server:phatcrack-server filerepo
echo "Starting Phatcrack"
docker compose up -d