This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.sh
224 lines (204 loc) Β· 5.9 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
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
#!/bin/bash
if [[ "$FRONTEND" == "" ]]; then
echo "Please tell your frontend host (or IP:PORT) with -e FRONTEND. e.g. http://demo.syzoj.org"
echo "This host should be proxy_pass-ed to container:2001."
exit 1
fi
if [[ "$MINIO_ENDPOINT_USER" == "" || "$MINIO_ENDPOINT_JUDGE" == "" ]]; then
echo "Please tell your MinIO endpoint for user and judge with -e MINIO_ENDPOINT_USER and -e MINIO_ENDPOINT_JUDGE"
echo "The hosts should be proxy_pass-ed to http://container:2003 and the HTTP Host header should be '127.0.0.1:2003'."
exit 1
fi
if [[ "$SITE_NAME" == "" ]]; then
echo "Please tell your site name with -e SITE_NAME. e.g. Demo"
exit 1
fi
if [[ "$ADMIN_USERNAME" == "" ]]; then
echo "Please tell your admin username with -e ADMIN_USERNAME."
exit 1
fi
if [[ "$ADMIN_EMAIL" == "" ]]; then
echo "Please tell your admin email with -e ADMIN_EMAIL."
exit 1
fi
if [[ "$ADMIN_PASSWORD" == "" ]]; then
echo "Please tell your admin password with -e ADMIN_PASSWORD."
exit 1
fi
if [[ "$MINIO_ACCESS_KEY" == "" ]]; then
echo "Please tell your MinIO access key with -e MINIO_ACCESS_KEY."
exit
fi
if [[ "$MINIO_SECRET_KEY" == "" ]]; then
echo "Please tell your MinIO secret key with -e MINIO_SECRET_KEY."
exit
fi
# Start MinIO
cd
./minio server ./minio-data --address :2003 &
while ! ./mc config host add minio http://127.0.0.1:2003 "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY"; do sleep 1; done
while ! ./mc mb -p minio/syzoj-ng-files; do sleep 1; done
# Start MySQL
mysqld_safe &
while ! mysqladmin ping --silent; do
sleep 1
done
# Start Redis
redis-server --protected-mode no &
while ! redis-cli ping | grep PONG; do
sleep 1
done
# Update
cd ~/syzoj-ng
while ! git fetch; do sleep 1; done
git reset --hard origin/master
yarn
if [ "$MAIL_TRANSPORT" = "" ]; then
MAIL_ENABLED="false"
else
MAIL_ENABLED="true"
fi
if [ "$TELEGRAM_BOT_TOKEN" = "" ]; then
TELEGRAM_BOT_TOKEN="null"
fi
if [ "$TELEGRAM_SEND_TO" = "" ]; then
TELEGRAM_SEND_TO="null"
fi
# Make config
cat > config.yaml <<EOF
server:
hostname: 0.0.0.0
port: 2002
trustProxy: ["loopback", "linklocal", "uniquelocal"]
clusters: 0
services:
database:
type: mariadb
host: 127.0.0.1
port: 3306
username: syzoj-ng
password: syzoj-ng
database: syzoj-ng
minio:
endpoint: http://127.0.0.1:2003
endpointForUser: "$MINIO_ENDPOINT_USER"
endpointForJudge: "$MINIO_ENDPOINT_JUDGE"
accessKey: "$MINIO_ACCESS_KEY"
secretKey: "$MINIO_SECRET_KEY"
bucket: syzoj-ng-files
redis: redis://127.0.0.1:6379
mail:
address: "$MAIL_ADDRESS"
transport: "$MAIL_TRANSPORT"
security:
crossOrigin:
enabled: true
whiteList:
- "$FRONTEND"
sessionSecret: "$MINIO_SECRET_KEY"
maintainceKey: "$(echo $(dd if=/dev/urandom | base64 -w0 | dd bs=1 count=20 2>/dev/null))"
recaptcha:
secretKey: ${RECAPTCHA_SECRET:=null}
useRecaptchaNet: true
proxyUrl: null
rateLimit:
maxRequests: 200
durationSeconds: 10
preference:
siteName: "$SITE_NAME"
security:
recaptchaEnabled: ${RECAPTCHA_ENABLED:=false}
recaptchaKey: ${RECAPTCHA_KEY:=null}
requireEmailVerification: false
allowUserChangeUsername: true
allowEveryoneCreateProblem: true
allowNonPrivilegedUserEditPublicProblem: true
allowOwnerManageProblemPermission: false
allowOwnerDeleteProblem: true
allowEveryoneCreateDiscussion: true
discussionDefaultPublic: true
discussionReplyDefaultPublic: true
pagination:
homepageUserList: 20
homepageProblemList: 5
problemSet: 50
searchProblemsPreview: 7
submissions: 10
submissionStatistics: 10
userList: 30
userAuditLogs: 10
discussions: 10
searchDiscussionsPreview: 7
discussionReplies: 40
discussionRepliesHead: 20
discussionRepliesMore: 20
misc:
appLogo: ${APP_LOGO:=default}
appLogoForTheme:
pure: original
far: inverted
googleAnalyticsId: ${GA_ID:=null}
gravatarCdn: ${GRAVATAR_CDN:=https://gravatar.loli.net}
redirectLegacyUrls: false
legacyContestsEntryUrl: null
homepageUserListOnMainView: true
sortUserByRating: false
renderMarkdownInUserBio: false
discussionReactionEmojis: [π, π, π, π, β€οΈ, π€, π€£, πΏ, π, ποΈ]
discussionReactionAllowCustomEmojis: true
serverSideOnly:
discussionReactionCustomEmojisBlacklist: /(\uD83C[\uDDE6-\uDDFF]){2}/
dynamicTaskPriority: false
resourceLimit:
problemTestdataFiles: 40
problemTestdataSize: 134217728
problemAdditionalFileFiles: 40
problemAdditionalFileSize: 134217728
problemSamplesToRun: 10
problemTestcases: 20
problemTimeLimit: 2000
problemMemoryLimit: 512
submissionFileSize: 10485760
queryLimit:
problemSet: 100
submissions: 10
submissionStatistics: 10
searchUser: 10
searchGroup: 10
userList: 100
userAuditLogs: 20
discussions: 20
discussionReplies: 50
judge:
limit:
compilerMessage: 524288
outputSize: 104857600
dataDisplay: 128
dataDisplayForSubmitAnswer: 128
stderrDisplay: 5120
eventReport:
telegramBotToken: ${TELEGRAM_BOT_TOKEN:=null}
telegramApiRoot: ${TELEGRAM_API_ROOT:=null}
sentTo: ${TELEGRAM_SEND_TO:=null}
proxyUrl: ${TELEGRAM_PROXY_URL:=null}
vendor:
ip2region: null
EOF
# Setup admin user
HASHED_PASSWORD=$(mkfifo /tmp/admin-password; echo -n "$ADMIN_PASSWORD" > /tmp/admin-password & node -e "require('/root/syzoj-ng/node_modules/bcrypt').hash(fs.readFileSync('/tmp/admin-password').toString('utf-8'), 10).then(res => console.log(res))"; rm /tmp/admin-password)
mysql <<EOF
USE syzoj-ng;
UPDATE user SET username = '$ADMIN_USERNAME' WHERE id = 1;
UPDATE user SET email = '$ADMIN_EMAIL' WHERE id = 1;
UPDATE user_auth SET password = '$HASHED_PASSWORD' WHERE userId = 1;
EOF
# Start
NODE_ENV=production SYZOJ_NG_CONFIG_FILE=./config.yaml yarn start &
# Update
cd ~/syzoj-ng-app
while ! git fetch; do sleep 1; done
git reset --hard origin/master
yarn
# Start
yarn build
serve -s build -l tcp://0.0.0.0:2001