-
Notifications
You must be signed in to change notification settings - Fork 9
/
start.sh
executable file
·193 lines (165 loc) · 6.07 KB
/
start.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env sh
detect_user_os() {
case "$OSTYPE" in
darwin*) PLATFORM_OS="macOS" ;;
linux*) PLATFORM_OS="linux" ;;
*) echo "Our start script only supports macOS and Linux at this moment" | exit 1 ;;
esac
}
check_has_app_url() {
# Check if user already has APP_URL set
APP_URL=$(awk '$1 ~ /^APP_URL/' configs/core/.env | cut -d "=" -f 2)
if [ -z "$APP_URL" ]; then
echo "For a few things to work, we need to know your platform URL"
echo "Please input the URL: (e.g. http://127.0.0.1:8000)"
read APP_URL
if [ -z "$APP_URL" ]; then
APP_URL="http:\/\/127.0.0.1:8000"
else
APP_URL=$(echo "$APP_URL" | sed 's;/;\\/;g')
fi
if [ "$PLATFORM_OS" = "macOS" ]; then
sed -i '' -e "s/^APP_URL=/APP_URL=$APP_URL/g" configs/core/.env
else
sed -i "s/^APP_URL=/APP_URL=\"$APP_URL\"/g" configs/core/.env
fi
fi
}
generate_basic_token() {
# Generate a new basic auth token and set to .env file
BASIC_TOKEN=$(openssl rand -hex 32)
echo "Done, your basic static token is: $BASIC_TOKEN"
if [ "$PLATFORM_OS" = "macOS" ]; then
sed -i '' -e "s/^BASIC_AUTH_TOKEN=/BASIC_AUTH_TOKEN=$BASIC_TOKEN/g" configs/core/.env
sed -i '' -e "s/^PLATFORM_KEY=/PLATFORM_KEY=$BASIC_TOKEN/g" configs/daemon/.env
else
sed -i "s/^BASIC_AUTH_TOKEN=/BASIC_AUTH_TOKEN=$BASIC_TOKEN/g" configs/core/.env
sed -i "s/^PLATFORM_KEY=/PLATFORM_KEY=$BASIC_TOKEN/g" configs/daemon/.env
fi
}
check_has_basic_token() {
# Check if user already has BASIC_AUTH_TOKEN set
AUTH_TOKEN=$(awk '$1 ~ /^BASIC_AUTH_TOKEN/' configs/core/.env | cut -d "=" -f 2)
if [ -z "$AUTH_TOKEN" ]; then
echo "We also use a static token to protect your platform from unauthorized access"
echo "Your BASIC_AUTH_TOKEN is not set, do you want to generate one? (y/n)"
read generate_token
if [ "$generate_token" = "${generate_token#[Yy]}" ] ;then
echo "Please set BASIC_AUTH_TOKEN in configs/core/.env and run this script again"
exit 1
else
generate_basic_token
fi
fi
}
check_and_generate_app_key() {
APP_KEY=$(awk '$1 ~ /^APP_KEY/' configs/core/.env | cut -d "=" -f 2)
if [ -z "$APP_KEY" ]; then
echo "No application key set. A new key will be generated automatically."
APP_KEY=$(dd if=/dev/urandom bs=32 count=1 status=none | base64)
if [ "$PLATFORM_OS" = "macOS" ]; then
sed -i '' -e "s#^APP_KEY=#APP_KEY=base64:$APP_KEY#g" configs/core/.env
else
sed -i "s#^APP_KEY=#APP_KEY=base64:$APP_KEY#g" configs/core/.env
fi
fi
}
generate_daemon_password() {
# Generate a new key pass for the daemon and set to .env file
WALLET_PASSWORD=$(openssl rand -hex 32)
echo "Done, your daemon password is: $WALLET_PASSWORD"
sed -i '' -e "s/^KEY_PASS=/KEY_PASS=$WALLET_PASSWORD/g" configs/daemon/.env
if [ "$PLATFORM_OS" = "macOS" ]; then
sed -i '' -e "s/^KEY_PASS=/KEY_PASS=$WALLET_PASSWORD/g" configs/daemon/.env
else
sed -i "s/^KEY_PASS=/KEY_PASS=$WALLET_PASSWORD/g" configs/daemon/.env
fi
}
check_has_daemon_password() {
# Check if user already has KEY_PASS set
KEY_PASS=$(awk '$1 ~ /^KEY_PASS/' configs/daemon/.env | cut -d "=" -f 2)
if [ -z "$KEY_PASS" ]; then
echo "Finally, we also use a password to protect your wallet daemon"
echo "Your KEY_PASS is not set, do you want to generate one? (y/n)"
read generate_daemon
if [ "$generate_daemon" = "${generate_daemon#[Yy]}" ] ;then
echo "Please set KEY_PASS in configs/daemon/.env and run this script again"
exit 1
else
generate_daemon_password
fi
fi
}
get_daemon_address() {
# Check if user already has DAEMON_ACCOUNT set
DAEMON_ACCOUNT=$(awk '$1 ~ /^DAEMON_ACCOUNT/' configs/core/.env | cut -d "=" -f 2)
if [ -z "$DAEMON_ACCOUNT" ]; then
echo "Let's get your wallet daemon address, please wait..."
(docker compose up -d daemon)
sleep 3
WALLET_ADDRESS=$(docker compose logs daemon 2>&1 | grep -A2 "Wallet daemon address" | awk '{print $NF}' | tail -n 2)
echo "Your wallet daemon address is:"
echo "$WALLET_ADDRESS"
WALLET_ADDRESS=$(echo "$WALLET_ADDRESS" | head -n 1)
if [ "$PLATFORM_OS" = "macOS" ]; then
sed -i '' -e "s/^DAEMON_ACCOUNT=/DAEMON_ACCOUNT=$WALLET_ADDRESS/g" configs/core/.env
else
sed -i "s/^DAEMON_ACCOUNT=/DAEMON_ACCOUNT=$WALLET_ADDRESS/g" configs/core/.env
fi
else
echo "Your wallet daemon address is: $DAEMON_ACCOUNT"
fi
}
check_docker_is_installed() {
if ! [ -x "$(command -v docker)" ]; then
echo "Please install docker and run this script again"
exit 1
fi
}
check_compose_is_installed() {
if ! [ "$(docker compose --version)" ]; then
echo "Please install docker compose and run this script again"
fi
}
check_docker_is_running() {
if ! [ "$(docker ps)" ]; then
echo "Please start docker and run this script again"
exit 1
fi
}
check_openssl_is_installed() {
if ! [ "$(openssl version)" ]; then
echo "Please install OpenSSL and run this script again"
exit 1
fi
}
check_git_is_installed() {
if ! [ "$(git --version)" ]; then
echo "Please install git and run this script again"
exit 1
fi
}
echo "Welcome to Enjin Platform, this script will help you start it up"
detect_user_os
check_git_is_installed
check_openssl_is_installed
check_docker_is_installed
check_compose_is_installed
check_docker_is_running
check_has_app_url
check_has_basic_token
check_has_daemon_password
check_and_generate_app_key
get_daemon_address
echo "Do you want to start all platform services? (y/n)"
read start_services
if [ "$start_services" != "${start_services#[Yy]}" ] ;then
docker compose build app --no-cache
docker compose up -d
echo "Your Enjin Platform is now installing the UI and other dependencies..."
echo "It should be available in a few minutes at: http://127.0.0.1:8000 "
else
docker compose down
echo "Please run this script again when you are ready"
exit 1
fi