FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TypeType/scripts/setup-stack.sh at main · TypeType-Video/TypeType · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TypeType-Video
/
TypeType
Public
Notifications
You must be signed in to change notification settings
Fork
14
Star
407
Code
Issues
6
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TypeType
/
scripts
/
setup-stack.sh
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
311 lines (273 loc) · 11.4 KB
Breadcrumbs
TypeType
/
scripts
/
setup-stack.sh
Copy path
File metadata and controls
executable file
·
311 lines (273 loc) · 11.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!
/usr/bin/env bash
set
-euo pipefail
ROOT_DIR=
"
$(
cd
"
$(
dirname
"
${BASH_SOURCE[0]}
"
)
/..
"
&&
pwd
)
"
ENV_FILE=
"
${ROOT_DIR}
/.env
"
DEFAULT_ALLOWED_ORIGINS=
"
http://localhost:8082,http://127.0.0.1:8082,http://localhost:5173,http://127.0.0.1:5173
"
DEFAULT_HOST_PORT_WEB=
"
8082
"
DEFAULT_HOST_PORT_SERVER=
"
8080
"
DEFAULT_HOST_PORT_TOKEN=
"
8081
"
DEFAULT_HOST_PORT_GARAGE_S3=
"
3900
"
DEFAULT_POSTGRES_DB=
"
typetype
"
DEFAULT_POSTGRES_USER=
"
typetype
"
DEFAULT_POSTGRES_PASSWORD=
"
typetype
"
DEFAULT_DRAGONFLY_URL=
"
redis://dragonfly:6379
"
DEFAULT_GITHUB_REPO=
"
TypeType-Video/TypeType
"
DEFAULT_GITHUB_ISSUE_TEMPLATE=
"
bug_report_backend.md
"
DEFAULT_DOWNLOADER_S3_ACCESS_KEY=
"
"
DEFAULT_DOWNLOADER_S3_SECRET_KEY=
"
"
DEFAULT_YOUTUBE_REMOTE_LOGIN_ENABLED=
"
false
"
DEFAULT_YOUTUBE_REMOTE_LOGIN_CALLBACK_ORIGIN=
"
http://typetype-server:8080
"
DEFAULT_YOUTUBE_REMOTE_LOGIN_TTL_MS=
"
480000
"
DEFAULT_YOUTUBE_REMOTE_LOGIN_MAX_SESSIONS=
"
2
"
DEFAULT_YOUTUBE_REMOTE_LOGIN_FRAME_FPS=
"
10
"
DEFAULT_YOUTUBE_REMOTE_LOGIN_MAX_FRAME_BYTES=
"
524288
"
PLACEHOLDER_YOUTUBE_REMOTE_LOGIN_INTERNAL_TOKEN=
"
SET_ME_SHARED_SECRET
"
generate_hex
() {
local
bytes=
"
$1
"
od -An -N
"
${bytes}
"
-tx1 /dev/urandom
|
tr -d
'
[:space:]
'
}
generate_downloader_access_key
() {
printf
'
GK%s
'
"
$(
generate_hex 12
)
"
}
generate_downloader_secret_key
() {
generate_hex 32
}
generate_youtube_remote_login_token
() {
generate_hex 32
}
ensure_generated_secrets
() {
if
[[
-z
"
${DEFAULT_DOWNLOADER_S3_ACCESS_KEY}
"
]]
;
then
DEFAULT_DOWNLOADER_S3_ACCESS_KEY=
"
$(
generate_downloader_access_key
)
"
fi
if
[[
-z
"
${DEFAULT_DOWNLOADER_S3_SECRET_KEY}
"
]]
;
then
DEFAULT_DOWNLOADER_S3_SECRET_KEY=
"
$(
generate_downloader_secret_key
)
"
fi
}
port_is_listening
() {
local
port=
"
$1
"
local
port_hex
local
socket_tables=(/proc/net/tcp)
if
[[
-r
/proc/net/tcp ]]
;
then
[[
!
-r
/proc/net/tcp6 ]]
||
socket_tables+=(/proc/net/tcp6)
port_hex=
"
$(
printf
'
%04X
'
"
${port}
"
)
"
awk -v port=
"
${port_hex}
"
'
NR > 1 && toupper(substr($2, length($2) - 3)) == port && $4 == "0A" { found = 1; exit }
END { exit found ? 0 : 1 }
'
"
${socket_tables[@]}
"
return
fi
(exec
3<>
"
/dev/tcp/127.0.0.1/
${port}
"
)
2>
/dev/null
}
require_free_port
() {
!
port_is_listening
"
$1
"
}
set_env_var
() {
local
env_file=
"
$1
"
local
key=
"
$2
"
local
value=
"
$3
"
if
grep -q
"
^
${key}
=
"
"
${env_file}
"
;
then
sed -i
"
s|^
${key}
=.*$|
${key}
=
${value}
|
"
"
${env_file}
"
else
printf
'
%s=%s\n
'
"
${key}
"
"
${value}
"
>>
"
${env_file}
"
fi
}
ensure_env_default
() {
local
env_file=
"
$1
"
local
key=
"
$2
"
local
value=
"
$3
"
local
current
current=
"
$(
get_env_var
"
${env_file}
"
"
${key}
"
)
"
if
[[
-z
"
${current}
"
]]
;
then
set_env_var
"
${env_file}
"
"
${key}
"
"
${value}
"
fi
}
ensure_youtube_remote_login_env
() {
local
env_file=
"
$1
"
local
current_token
ensure_env_default
"
${env_file}
"
"
YOUTUBE_REMOTE_LOGIN_ENABLED
"
"
${DEFAULT_YOUTUBE_REMOTE_LOGIN_ENABLED}
"
ensure_env_default
"
${env_file}
"
"
YOUTUBE_REMOTE_LOGIN_CALLBACK_ORIGIN
"
"
${DEFAULT_YOUTUBE_REMOTE_LOGIN_CALLBACK_ORIGIN}
"
ensure_env_default
"
${env_file}
"
"
YOUTUBE_REMOTE_LOGIN_TTL_MS
"
"
${DEFAULT_YOUTUBE_REMOTE_LOGIN_TTL_MS}
"
ensure_env_default
"
${env_file}
"
"
YOUTUBE_REMOTE_LOGIN_MAX_SESSIONS
"
"
${DEFAULT_YOUTUBE_REMOTE_LOGIN_MAX_SESSIONS}
"
ensure_env_default
"
${env_file}
"
"
YOUTUBE_REMOTE_LOGIN_FRAME_FPS
"
"
${DEFAULT_YOUTUBE_REMOTE_LOGIN_FRAME_FPS}
"
ensure_env_default
"
${env_file}
"
"
YOUTUBE_REMOTE_LOGIN_MAX_FRAME_BYTES
"
"
${DEFAULT_YOUTUBE_REMOTE_LOGIN_MAX_FRAME_BYTES}
"
current_token=
"
$(
get_env_var
"
${env_file}
"
"
YOUTUBE_REMOTE_LOGIN_INTERNAL_TOKEN
"
)
"
if
[[
-z
"
${current_token}
"
||
"
${current_token}
"
==
"
${PLACEHOLDER_YOUTUBE_REMOTE_LOGIN_INTERNAL_TOKEN}
"
]]
;
then
set_env_var
"
${env_file}
"
"
YOUTUBE_REMOTE_LOGIN_INTERNAL_TOKEN
"
"
$(
generate_youtube_remote_login_token
)
"
echo
"
[setup] Generated internal YouTube remote login token in
${env_file}
"
fi
}
get_env_var
() {
local
env_file=
"
$1
"
local
key=
"
$2
"
grep
"
^
${key}
=
"
"
${env_file}
"
|
cut -d= -f2-
||
true
}
is_valid_port
() {
local
port=
"
$1
"
[[
"
${port}
"
=~
^[0-9]+$ ]]
||
return
1
((
port
>=
1
&&
port
<=
65535
))
}
find_random_free_port
() {
local
attempt
local
port
for
((
attempt
=
0
; attempt
<
500
; attempt
++
))
;
do
port=
$((
20000
+
(((RANDOM
<<
15
)
|
RANDOM)
%
41000
))
)
if
require_free_port
"
${port}
"
;
then
echo
"
${port}
"
return
fi
done
echo
"
[setup] No free port found between 20000 and 60999.
"
>&2
return
1
}
is_arm64_host
() {
case
"
$(
uname -m
)
"
in
aarch64|arm64)
return
0 ;;
*
)
return
1 ;;
esac
}
choose_stack_port
() {
local
env_file=
"
$1
"
local
key=
"
$2
"
local
fallback=
"
$3
"
local
label=
"
$4
"
local
configured
configured=
"
$(
get_env_var
"
${env_file}
"
"
${key}
"
)
"
if
!
is_valid_port
"
${configured}
"
;
then
configured=
"
${fallback}
"
fi
if
require_free_port
"
${configured}
"
;
then
set_env_var
"
${env_file}
"
"
${key}
"
"
${configured}
"
echo
"
${configured}
"
return
fi
local
random_port
random_port=
"
$(
find_random_free_port
)
"
set_env_var
"
${env_file}
"
"
${key}
"
"
${random_port}
"
echo
"
[setup]
${label}
port
${configured}
is in use, using
${random_port}
instead.
"
>&2
echo
"
${random_port}
"
}
prompt_value
() {
local
out_var=
"
$1
"
local
label=
"
$2
"
local
default_value=
"
$3
"
local
value=
"
"
read
-r -p
"
${label}
[
${default_value}
]:
"
value
if
[[
-z
"
${value}
"
]]
;
then
value=
"
${default_value}
"
fi
printf
-v
"
${out_var}
"
'
%s
'
"
${value}
"
}
echo
"
TypeType interactive setup
"
echo
ensure_generated_secrets
if
[[
-f
"
${ENV_FILE}
"
]]
;
then
read
-r -p
"
.env already exists. Overwrite it? [y/N]:
"
overwrite
if
[[
!
"
${overwrite}
"
=~
^[Yy]$ ]]
;
then
echo
"
Keeping existing .env
"
else
echo
"
Rebuilding .env with prompted values...
"
prompt_value ALLOWED_ORIGINS
"
ALLOWED_ORIGINS
"
"
${DEFAULT_ALLOWED_ORIGINS}
"
prompt_value HOST_PORT_WEB
"
HOST_PORT_WEB
"
"
${DEFAULT_HOST_PORT_WEB}
"
prompt_value HOST_PORT_SERVER
"
HOST_PORT_SERVER
"
"
${DEFAULT_HOST_PORT_SERVER}
"
prompt_value HOST_PORT_TOKEN
"
HOST_PORT_TOKEN
"
"
${DEFAULT_HOST_PORT_TOKEN}
"
prompt_value POSTGRES_DB
"
POSTGRES_DB
"
"
${DEFAULT_POSTGRES_DB}
"
prompt_value POSTGRES_USER
"
POSTGRES_USER
"
"
${DEFAULT_POSTGRES_USER}
"
prompt_value POSTGRES_PASSWORD
"
POSTGRES_PASSWORD
"
"
${DEFAULT_POSTGRES_PASSWORD}
"
prompt_value DRAGONFLY_URL
"
DRAGONFLY_URL
"
"
${DEFAULT_DRAGONFLY_URL}
"
prompt_value GITHUB_REPO
"
GITHUB_REPO
"
"
${DEFAULT_GITHUB_REPO}
"
prompt_value GITHUB_ISSUE_TEMPLATE
"
GITHUB_ISSUE_TEMPLATE
"
"
${DEFAULT_GITHUB_ISSUE_TEMPLATE}
"
prompt_value DOWNLOADER_S3_ACCESS_KEY
"
DOWNLOADER_S3_ACCESS_KEY
"
"
${DEFAULT_DOWNLOADER_S3_ACCESS_KEY}
"
prompt_value DOWNLOADER_S3_SECRET_KEY
"
DOWNLOADER_S3_SECRET_KEY
"
"
${DEFAULT_DOWNLOADER_S3_SECRET_KEY}
"
cat
>
"
${ENV_FILE}
"
<<
EOF
ALLOWED_ORIGINS=
${ALLOWED_ORIGINS}
HOST_PORT_WEB=
${HOST_PORT_WEB}
HOST_PORT_SERVER=
${HOST_PORT_SERVER}
HOST_PORT_TOKEN=
${HOST_PORT_TOKEN}
POSTGRES_DB=
${POSTGRES_DB}
POSTGRES_USER=
${POSTGRES_USER}
POSTGRES_PASSWORD=
${POSTGRES_PASSWORD}
DRAGONFLY_URL=
${DRAGONFLY_URL}
GITHUB_REPO=
${GITHUB_REPO}
GITHUB_ISSUE_TEMPLATE=
${GITHUB_ISSUE_TEMPLATE}
DOWNLOADER_S3_ACCESS_KEY=
${DOWNLOADER_S3_ACCESS_KEY}
DOWNLOADER_S3_SECRET_KEY=
${DOWNLOADER_S3_SECRET_KEY}
EOF
fi
else
echo
"
No .env found. Let's create one.
"
prompt_value ALLOWED_ORIGINS
"
ALLOWED_ORIGINS
"
"
${DEFAULT_ALLOWED_ORIGINS}
"
prompt_value HOST_PORT_WEB
"
HOST_PORT_WEB
"
"
${DEFAULT_HOST_PORT_WEB}
"
prompt_value HOST_PORT_SERVER
"
HOST_PORT_SERVER
"
"
${DEFAULT_HOST_PORT_SERVER}
"
prompt_value HOST_PORT_TOKEN
"
HOST_PORT_TOKEN
"
"
${DEFAULT_HOST_PORT_TOKEN}
"
prompt_value POSTGRES_DB
"
POSTGRES_DB
"
"
${DEFAULT_POSTGRES_DB}
"
prompt_value POSTGRES_USER
"
POSTGRES_USER
"
"
${DEFAULT_POSTGRES_USER}
"
prompt_value POSTGRES_PASSWORD
"
POSTGRES_PASSWORD
"
"
${DEFAULT_POSTGRES_PASSWORD}
"
prompt_value DRAGONFLY_URL
"
DRAGONFLY_URL
"
"
${DEFAULT_DRAGONFLY_URL}
"
prompt_value GITHUB_REPO
"
GITHUB_REPO
"
"
${DEFAULT_GITHUB_REPO}
"
prompt_value GITHUB_ISSUE_TEMPLATE
"
GITHUB_ISSUE_TEMPLATE
"
"
${DEFAULT_GITHUB_ISSUE_TEMPLATE}
"
prompt_value DOWNLOADER_S3_ACCESS_KEY
"
DOWNLOADER_S3_ACCESS_KEY
"
"
${DEFAULT_DOWNLOADER_S3_ACCESS_KEY}
"
prompt_value DOWNLOADER_S3_SECRET_KEY
"
DOWNLOADER_S3_SECRET_KEY
"
"
${DEFAULT_DOWNLOADER_S3_SECRET_KEY}
"
cat
>
"
${ENV_FILE}
"
<<
EOF
ALLOWED_ORIGINS=
${ALLOWED_ORIGINS}
HOST_PORT_WEB=
${HOST_PORT_WEB}
HOST_PORT_SERVER=
${HOST_PORT_SERVER}
HOST_PORT_TOKEN=
${HOST_PORT_TOKEN}
POSTGRES_DB=
${POSTGRES_DB}
POSTGRES_USER=
${POSTGRES_USER}
POSTGRES_PASSWORD=
${POSTGRES_PASSWORD}
DRAGONFLY_URL=
${DRAGONFLY_URL}
GITHUB_REPO=
${GITHUB_REPO}
GITHUB_ISSUE_TEMPLATE=
${GITHUB_ISSUE_TEMPLATE}
DOWNLOADER_S3_ACCESS_KEY=
${DOWNLOADER_S3_ACCESS_KEY}
DOWNLOADER_S3_SECRET_KEY=
${DOWNLOADER_S3_SECRET_KEY}
EOF
fi
cd
"
${ROOT_DIR}
"
COMPOSE_ARGS=(-f
"
${ROOT_DIR}
/docker-compose.yml
"
)
COMPOSE_OVERRIDE_FILE=
"
"
COMPOSE_CUSTOM_FILE=
"
"
if
is_arm64_host
&&
[[
-f
"
${ROOT_DIR}
/docker-compose.arm64.yml
"
]]
;
then
COMPOSE_OVERRIDE_FILE=
"
${ROOT_DIR}
/docker-compose.arm64.yml
"
COMPOSE_ARGS+=(-f
"
${COMPOSE_OVERRIDE_FILE}
"
)
echo
"
[setup] ARM64 host detected, using Redis cache override.
"
fi
if
[[
-f
"
${ROOT_DIR}
/docker-compose.override.yml
"
]]
;
then
COMPOSE_CUSTOM_FILE=
"
${ROOT_DIR}
/docker-compose.override.yml
"
COMPOSE_ARGS+=(-f
"
${COMPOSE_CUSTOM_FILE}
"
)
echo
"
[setup] Custom Compose override detected.
"
fi
install -d -m 700
"
${ROOT_DIR}
/.typetype-migration
"
if
[[
-s
"
${ROOT_DIR}
/garage.toml
"
]]
;
then
install -D -m 600
"
${ROOT_DIR}
/garage.toml
"
"
${ROOT_DIR}
/.typetype-migration/garage.toml
"
echo
"
[setup] Staged the existing garage.toml for import into the managed config volume.
"
fi
ensure_youtube_remote_login_env
"
${ENV_FILE}
"
"
${ROOT_DIR}
/scripts/bootstrap-env.sh
"
HOST_PORT_SERVER_RESOLVED=
"
$(
choose_stack_port
"
${ENV_FILE}
"
"
HOST_PORT_SERVER
"
"
${DEFAULT_HOST_PORT_SERVER}
"
"
API
"
)
"
HOST_PORT_TOKEN_RESOLVED=
"
$(
choose_stack_port
"
${ENV_FILE}
"
"
HOST_PORT_TOKEN
"
"
${DEFAULT_HOST_PORT_TOKEN}
"
"
token
"
)
"
HOST_PORT_WEB_RESOLVED=
"
$(
choose_stack_port
"
${ENV_FILE}
"
"
HOST_PORT_WEB
"
"
${DEFAULT_HOST_PORT_WEB}
"
"
frontend
"
)
"
HOST_PORT_GARAGE_S3_RESOLVED=
"
$(
choose_stack_port
"
${ENV_FILE}
"
"
HOST_PORT_GARAGE_S3
"
"
${DEFAULT_HOST_PORT_GARAGE_S3}
"
"
Garage S3
"
)
"
set_env_var
"
${ENV_FILE}
"
"
DOWNLOADER_S3_PUBLIC_ENDPOINT
"
"
http://localhost:
${HOST_PORT_GARAGE_S3_RESOLVED}
"
CURRENT_ALLOWED_ORIGINS=
"
$(
get_env_var
"
${ENV_FILE}
"
"
ALLOWED_ORIGINS
"
)
"
LEGACY_ALLOWED_ORIGINS=
"
http://localhost:
${HOST_PORT_WEB_RESOLVED}
,http://localhost:5173
"
PACKAGED_ALLOWED_ORIGINS=
"
http://localhost:8082,http://localhost:5173
"
GENERATED_ALLOWED_ORIGINS=
"
http://localhost:
${HOST_PORT_WEB_RESOLVED}
,http://127.0.0.1:
${HOST_PORT_WEB_RESOLVED}
,http://localhost:5173,http://127.0.0.1:5173
"
if
[[
-z
"
${CURRENT_ALLOWED_ORIGINS}
"
||
"
${CURRENT_ALLOWED_ORIGINS}
"
==
"
${PACKAGED_ALLOWED_ORIGINS}
"
||
"
${CURRENT_ALLOWED_ORIGINS}
"
==
"
${DEFAULT_ALLOWED_ORIGINS}
"
||
"
${CURRENT_ALLOWED_ORIGINS}
"
==
"
${LEGACY_ALLOWED_ORIGINS}
"
]]
;
then
set_env_var
"
${ENV_FILE}
"
"
ALLOWED_ORIGINS
"
"
${GENERATED_ALLOWED_ORIGINS}
"
fi
echo
echo
"
[setup] Validating the resolved Compose stack...
"
docker compose
"
${COMPOSE_ARGS[@]}
"
config -q
echo
"
[setup] Pulling images...
"
docker compose
"
${COMPOSE_ARGS[@]}
"
pull
echo
"
[setup] Starting services...
"
docker compose
"
${COMPOSE_ARGS[@]}
"
up -d --wait --wait-timeout 180
echo
"
[setup] Bootstrapping Garage for downloader...
"
COMPOSE_FILE=
"
${ROOT_DIR}
/docker-compose.yml
"
\
COMPOSE_OVERRIDE_FILE=
"
${COMPOSE_OVERRIDE_FILE}
"
\
COMPOSE_CUSTOM_FILE=
"
${COMPOSE_CUSTOM_FILE}
"
\
"
${ROOT_DIR}
/scripts/bootstrap-garage.sh
"
echo
"
[setup] Current service status:
"
docker compose
"
${COMPOSE_ARGS[@]}
"
ps
echo
echo
"
Done. Open http://localhost:
${HOST_PORT_WEB_RESOLVED}
"
Back
|
FazBrowse Home
|
New Git URL