-
Notifications
You must be signed in to change notification settings - Fork 32
/
run.sh
212 lines (188 loc) · 5.09 KB
/
run.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
#!/bin/bash
set -eou pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
declare _mail_d=~/mail
_env_common() {
export PYKERN_PKDEBUG_WANT_PID_TIME=1
}
_env_mail_common() {
export SIREPO_SMTP_FROM_NAME=DevSupport
export SIREPO_SMTP_FROM_EMAIL=$USER+support@localhost.localdomain
if [[ ! ${SIREPO_AUTH_METHODS:-} =~ email ]]; then
export SIREPO_AUTH_METHODS=email:guest
fi
}
_env_mail_smtp() {
_env_mail_common
export SIREPO_SMTP_FROM_EMAIL=$USER+support@localhost.localdomain
export SIREPO_SMTP_SEND_DIRECTLY=1
export SIREPO_SMTP_SERVER=localhost
}
_env_moderate() {
declare sim_type=$1
export SIREPO_FEATURE_CONFIG_MODERATED_SIM_TYPES=$sim_type
export SIREPO_AUTH_ROLE_MODERATION_MODERATOR_EMAIL=$USER+moderator@localhost.localdomain
_msg "Moderated sim_type=$sim_type"
_setup_smtp
_env_common
}
_err() {
_msg "$@"
return 1
}
_exec_all() {
_env_common
exec sirepo service http
}
_main() {
declare mode=${1:-missing-arg}
shift || true
declare f=_op_$mode
if [[ $(type -t "$f") != 'function' ]]; then
_err "invalid mode=$mode
usage: bash ${BASH_SOURCE[0]} mode
where mode is one of:
$(compgen -A function _op_ | sed -e 's/^_op_//')"
fi
"$f" "$@"
}
_msg() {
echo "$@" 1>&2
}
_op_bluesky() {
export SIREPO_AUTH_BLUESKY_SECRET=bluesky-secret
export SIREPO_AUTH_METHODS=email:bluesky
_msg "To test, you need a sim, but this is the structure:
curl -H 'Content-Type: application/json' -D - -X POST http://localhost:8000/auth-bluesky-login -d '{\"simulationId\": \"kRfyDC2q\", \"simulationType\": \"srw\"}'
"
_op_mail
}
_op_flash() {
export SIREPO_FEATURE_CONFIG_PROPRIETARY_OAUTH_SIM_TYPES=flash
export SIREPO_SIM_OAUTH_FLASH_INFO_VALID_USER=G
if [[ ! ${SIREPO_SIM_OAUTH_FLASH_KEY:-} || ! ${SIREPO_SIM_OAUTH_FLASH_SECRET:-} ]]; then
echo 'You must set $SIREPO_SIM_OAUTH_FLASH_KEY and $SIREPO_SIM_OAUTH_FLASH_SECRET' 1>&2
exit 1
fi
_exec_all
}
_op_jupyterhub() {
# POSIT: versions same in container-beamsim-jupyter/build.sh
# Order is important: jupyterlab-server should be last so it isn't
# overwritten with a newer version.
declare p=$(pip freeze)
declare -a i=()
declare f
for f in \
jupyterhub==1.4.2 \
jupyterlab==3.1.14 \
'notebook>=6.5.6' \
jupyterlab-server==2.8.2\
; do
if ! [[ $p =~ $f ]]; then
i+=( $f )
fi
done
if (( ${#i[@]} > 0 )); then
pip install "${i[@]}"
fi
if ! type configurable-http-proxy &> /dev/null; then
npm install --global configurable-http-proxy
fi
_env_moderate jupyterhublogin
sirepo service tornado &
sirepo service nginx-proxy &
sirepo job_supervisor &
sirepo service jupyterhub &
declare -a x=( $(jobs -p) )
# TERM is better than KILL
trap "kill ${x[*]}" EXIT
wait -n
}
_op_ldap() {
if ! systemctl is-active slapd &> /dev/null; then
_msg "setting up ldap/slapd"
bash setup-ldap.sh
fi
export SIREPO_AUTH_METHODS=guest:ldap
_msg 'To test:
Login as vagrant@radiasoft.net/vagrant
'
_exec_all
}
_op_mail() {
_setup_smtp
_exec_all
}
_op_moderate() {
_env_moderate srw
_exec_all
}
_op_no_smtp_mail() {
# POSIT: same as sirepo.smtp.DEV_SMTP_SERVER
export SIREPO_SMTP_SERVER=dev
_env_mail_common
_exec_all
}
_op_server_status() {
declare u=$(cd "$(dirname "$0")"/../run/user && ls -d ???????? 2>/dev/null | head -1)
if [[ ! $u ]]; then
_err 'Start the server first to create a user and then server_status can work'
fi
export SIREPO_AUTH_BASIC_PASSWORD=password
export SIREPO_AUTH_BASIC_UID=$u
export SIREPO_AUTH_METHODS=guest:basic
export SIREPO_FEATURE_CONFIG_API_MODULES=status
_msg "To test:
curl -u '$u:$SIREPO_AUTH_BASIC_PASSWORD' http://localhost:8000/server-status
"
_exec_all
}
_op_test_mail() {
_msg 'Testing local mail delivery'
rm -f "$_mail_d"/[0-9]*
echo xyzzy | sendmail "$USER"@localhost.localdomain
declare i
for i in $(seq 4); do
sleep 1
if grep -s xyzzy "$_mail_d"/1 &>/dev/null; then
rm "$_mail_d"/1
return
fi
done
_err mail delivery test failed
}
_setup_smtp() {
_env_mail_smtp
if [[ ! -d $_mail_d ]]; then
install -m 700 -d "$_mail_d"
fi
if [[ ! -r ~/.procmailrc ]]; then
install -m 600 /dev/stdin ~/.procmailrc <<'END'
UMASK=077
:0
mail/.
END
fi
declare f
for f in postfix procmail; do
if ! rpm -q "$f" &> /dev/null; then
_msg "installing $f"
sudo dnf install -y -q "$f"
fi
done
if [[ ! $(postconf -n recipient_delimiter) ]]; then
_msg 'configuring postfix'
sudo su - <<'END'
postconf -e \
inet_protocols=ipv4 \
mailbox_command=/usr/bin/procmail \
'mydestination=$myhostname, localhost.$mydomain, localhost, localhost.localdomain' \
recipient_delimiter=+
systemctl enable postfix
systemctl restart postfix
END
_op_test_mail
fi
}
_main "$@"