-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-aws.sh
executable file
·87 lines (72 loc) · 2.18 KB
/
init-aws.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
#!/bin/bash
# Self-Hosting Initialization
#
# Usage:
#
# ./init-aws.sh 83f0ebdf-eafb-4c8d-bd7b-04ea07d61b7f localhost
#
#
# Flow:
#
# First, check to see if there is a VERSION file, if so, use that version.
# If not, then check for the first command line argument, if so, use that version.
# Else, prompt the user.
#
# First, check to see if there is a HOST file, if so, use that host.
# If not, then check for the first command line argument, if so, use that host.
# Else, prompt the user.
REPO="https://github.com/quadratichq/quadratic-selfhost.git"
SELF_HOSTING_URI="https://selfhost.quadratichq.com/"
INVALID_LICENSE_KEY="Invalid license key."
PROFILE=""
LICENSE_KEY=""
HOST=""
# Download and source utils.sh
curl -sSf https://raw.githubusercontent.com/quadratichq/quadratic-selfhost/main/utils.sh -o utils.sh
source ./utils.sh
if [ -f "quadratic-selfhost/LICENSE_KEY" ]; then
LICENSE_KEY=$(<quadratic-selfhost/LICENSE_KEY)
elif [ $1 ]; then
LICENSE_KEY=$1
else
LICENSE_KEY=$(get_license_key)
fi
if [ -f "quadratic-selfhost/HOST" ]; then
HOST=$(<quadratic-selfhost/HOST)
elif [ $2 ]; then
HOST=$2
else
HOST=$(get_host)
fi
# retrieve the code from github
checkout
# copy the aws config files
cp docker/ory-auth/config/kratos.aws.yml docker/ory-auth/config/kratos.yml
cp .env.aws .env
# write license key to LICENSE file
touch LICENSE_KEY
echo $LICENSE_KEY > LICENSE_KEY
# write docker compose profile to PROFILE file
PROFILE=$(parse_profile)
touch PROFILE
echo $PROFILE > PROFILE
# write host to HOST file
touch HOST
echo $HOST > HOST
# generate a random encryption key
ENCRYPTION_KEY=$(generate_random_encryption_key)
touch ENCRYPTION_KEY
echo $ENCRYPTION_KEY > ENCRYPTION_KEY
# remove the utils.sh and init.sh script
rm ../utils.sh
rm ../init.sh
# adding .bak for compatibility with both GNU (Linux) and BSD (MacOS) sed
sed -i.bak "s/#LICENSE_KEY#/$LICENSE_KEY/g" ".env"
sed -i.bak "s/#HOST#/$HOST/g" ".env"
sed -i.bak "s/#HOST#/$HOST/g" "docker/ory-auth/config/kratos.yml"
sed -i.bak "s/#HOST#/$HOST/g" "docker/caddy/config/Caddyfile"
sed -i.bak "s/#ENCRYPTION_KEY#/$ENCRYPTION_KEY/g" ".env"
rm .env.bak
rm docker/ory-auth/config/kratos.yml.bak
rm docker/caddy/config/Caddyfile.bak
sh start.sh