-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
98 lines (78 loc) · 3.33 KB
/
Copy pathsetup.py
File metadata and controls
98 lines (78 loc) · 3.33 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
import shutil
import os
setup_env_done = False
default_values = {
'ENV': 'production',
'BASE_DOMAIN': 'valentine.gdscuic.org',
'FRONTEND_URL': 'https://valentine.gdscuic.org',
'BACKEND_URL': 'https://valentine.gdscuic.org/pb',
}
try:
print("Setting up .env file...")
# check if .env file does not exist
if not os.path.exists('.env'):
# copy .env.example to .env
shutil.copy('.env.example', '.env')
else:
setup_env_done = True
print(".env file already exists.")
# open .env file
with open('.env', 'r') as file:
# read a list of lines into data
data = file.readlines()
# uncomment and change the value of the commented environment variables
for idx, line in enumerate(data):
if line.startswith('#') and line.endswith('=\n'):
# remove the comment
data[idx] = line[2:]
line = data[idx]
# get name of the environment variable
env_var_name = line.split('=')[0]
while True:
# prompt value of the environment variable
env_var_value = input(f'Enter value for {env_var_name}: ')
if len(env_var_value) == 0:
# if default value is empty and user is empty, prompt again
print(f'Value for {env_var_name} is required.')
continue
break
# change the value of the environment variable
data[idx] = f'{env_var_name}={env_var_value}\n'
elif (line.startswith('#') and not line.endswith('=\n')) or len(line.strip()) == 0:
continue
else:
kv = line.split('=')
# check if the environment variable is not commented
env_var_name = kv[0]
env_var_value = kv[1].strip()
if env_var_name in default_values and env_var_value != default_values[env_var_name]:
env_var_value = default_values[env_var_name]
while True:
# prompt value of the environment variable
if len(env_var_value) == 0:
env_var_value = input(f'Enter value for {env_var_name}: ')
print(len(env_var_value))
else:
env_var_value2 = input(f'Enter value for {env_var_name} (Default: {env_var_value}): ')
if len(env_var_value2) != 0:
env_var_value = env_var_value2
if len(env_var_value) == 0:
# if default value is empty and user is empty, prompt again
print(f'Value for {env_var_name} is required.')
continue
break
# change the value of the environment variable
data[idx] = f'{env_var_name}={env_var_value}\n'
# write data to .env file
with open('.env', 'w') as file:
file.writelines(data)
setup_env_done = True
print(".env file setup done.")
# Execute ./deploy.sh
print("Deploying...")
os.system('./deploy.sh')
except KeyboardInterrupt:
if not setup_env_done:
# Remove .env file
os.remove('.env')
print("Setup cancelled.")