-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinit.sh
executable file
·220 lines (168 loc) · 7.41 KB
/
init.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
set -x
DEST="${DEST:-dest}"
echo -e "\e[32mOutput to ${DEST}\e[0m"
mkdir -p "${DEST}"
DEST="$( cd "${DEST}" && pwd )"
echo -e "\e[32m\${DEST} resolve to ${DEST}\e[0m"
cp -r _init "${DEST}"/
# define yq && ytt function
yq() {
docker run --rm -i -v "${PWD}":/workdir mikefarah/yq:4.13.2 "$@"
}
yqw() {
docker run --rm -i --user "$UID" -v "${PWD}":/workdir mikefarah/yq:4.13.2 "$@"
}
## DEST is mounted into ytt's docker workdirt
ytt_dest() {
docker run --rm -i -v "${DEST}":/workdir -w /workdir k14s/image@sha256:1100ed870cd6bdbef229f650f044cb03e91566c7ee0c7bfdbc08efc6196a41d8 ytt "$@"
}
# check config exists
if [ ! -f config.yml ] ; then
echo -e "\e[31mCannot Found config.yml\e[0m"
exit -1
fi
# if mikefarah/yq exists we do not delete after used.
docker image inspect mikefarah/yq:4.13.2 >/dev/null 2>&1
should_del_yq=$? #0 exists 1 not exists
if test "$should_del_yq" == "1"; then
echo -e "\e[32mInstall mikefarah/yq:4.13.2. Will delete after used.\e[0m"
docker pull mikefarah/yq:4.13.2 > /dev/null 2>&1
fi
docker image inspect k14s/image@sha256:1100ed870cd6bdbef229f650f044cb03e91566c7ee0c7bfdbc08efc6196a41d8 >/dev/null 2>&1
should_del_ytt=$?
if test "$should_del_ytt" == "1"; then
echo -e "\e[32mInstall ytt from k14s/image. Will delete after used.\e[0m"
docker pull k14s/image@sha256:1100ed870cd6bdbef229f650f044cb03e91566c7ee0c7bfdbc08efc6196a41d8 > /dev/null 2>&1
fi
## since all inter-container communications are using internal url. so no necessary start reverse proxy first.
# if test $(yq e .nginx.listener config.yml ) != "443" ; then
# echo -e "\e[31mYou still need a proxy to serve at 443 before docker-compose up\e[0m"
# echo -e "\e[31mSee examples/reverse_proxy \e[0m"
# fi
if test "$(yq e .secrets.authsecret config.yml )" == "What3v3r" ; then
yqw eval -i ".secrets.authsecret =\"$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20)\"" config.yml
fi
#TODO delete
if test "$(yq e .secrets.pushboxkey config.yml )" == "YOUR_LONG_ENOUGH_RANDOM_STRING" ; then
yqw eval -i ".secrets.pushboxkey =\"$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20)\"" config.yml
fi
if test "$(yq e .secrets.flowidkey config.yml )" == "MY_FLOW_ID_KEY" ; then
yqw eval -i ".secrets.flowidkey =\"$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20)\"" config.yml
fi
if test "$(yq e .secrets.profileserver_authsecret_bearertoken config.yml )" == "I_DONT_WANT_TO_CHANGE_YOU" ; then
yqw eval -i ".secrets.profileserver_authsecret_bearertoken =\"$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20)\"" config.yml
fi
if test "$(yq e .secrets.supportpanel_authsecret_bearertoken config.yml )" == "SUPPORT_PANEL_IS_NOT_SUPPORTED" ; then
yqw eval -i ".secrets.supportpanel_authsecret_bearertoken =\"$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20)\"" config.yml
fi
cp config.yml "${DEST}"/
cp docker-compose.tmpl.yml "${DEST}"/
# TODO check if these ytts success
echo -e "\e[32mgenerate _init/auth/oauthserver-prod.json\e[0m"
ytt_dest -f config.yml -f _init/auth/oauthserver-prod.tmpl.yml -o json > "${DEST}"/_init/auth/oauthserver-prod.json
if [ $? -ne 0 ]; then
echo -e "\e[31mgenerate _init/auth/oauthserver-prod.json error \e[0m"
exit -1
fi
rm "${DEST}"/_init/auth/oauthserver-prod.tmpl.yml
echo -e "\e[32mgenerate _init/content/contentserver-prod.json\e[0m"
ytt_dest -f config.yml -f _init/content/contentserver-prod.tmpl.yml -o json > "${DEST}"/_init/content/contentserver-prod.json
if [ $? -ne 0 ]; then
echo -e "\e[31mgenerate _init/content/contentserver-prod.json error\e[0m"
exit -1
fi
rm "${DEST}"/_init/content/contentserver-prod.tmpl.yml
echo -e "\e[32mgenerate docker-compose.yml\e[0m"
ytt_dest -f config.yml -f docker-compose.tmpl.yml > "${DEST}"/docker-compose.yml
if [ $? -ne 0 ]; then
echo -e "\e[31mgenerate docker-compose.yml error \e[0m"
exit -1
fi
rm "${DEST}"/docker-compose.tmpl.yml
# echo -e "\e[32mPlease make sure that you configured subdomains and their certs: www.$DOMAIN_NAME profile.$DOMAIN_NAME token.$DOMAIN_NAME api.$DOMAIN_NAME oauth.$DOMAIN_NAME (api.$DOMAIN_NAME and oauth.$DOMAIN_NAME must use same cert) \e[0m"
# do this to ensure .env 's PERSISTENCEPATH relate to docker-compose.yml
# echo -e "\e[32mPlease make sure that 0.0.0.0:443 and 127.0.0.1:9001 is not used\e[0m"
if test "$(yq e .debug.e2e_test.enable config.yml )" == "true" ; then
cp tests/docker-compose.e2e.tmpl.yml "${DEST}"/
ytt_dest -f config.yml -f docker-compose.e2e.tmpl.yml > "${DEST}"/docker-compose.e2e.yml
rm "${DEST}"/docker-compose.e2e.tmpl.yml
fi
set +x
echo -e "\e[32mAdd to firefox about:config\e[0m"
## TODO call "./init.sh show" to display the parameter to avoid the slow speed of spawn multi yq
## TODO or at least make these yqs in a call. like yq e -o=props ... and eval result to bash assignment
export $(yq e -o=props .domain config.yml | sed 's/[[:space:]]//g' )
export $(yq e -o=props .option config.yml | grep enable | sed 's/[[:space:]]//g' | sed 's/\./_/g' )
echo -e "\e[33m"
cat <<HERE
"identity.fxaccounts.auth.uri": "https://$auth.$name/v1",
"identity.fxaccounts.remote.root": "https://$content.$name/",
"identity.fxaccounts.remote.oauth.uri": "https://$oauth.$name/v1",
"identity.fxaccounts.remote.profile.uri": "https://$profile.$name/v1",
"identity.sync.tokenserver.uri": "https://$sync.$name/token/1.0/sync/1.5",
HERE
if test "$channelserver_enable" == "true" ; then
cat <<HERE
"identity.fxaccounts.remote.pairing.uri": "wss://$channelserver.$name",
HERE
fi
cat <<HERE
Previous lines can be replaced into: "identity.fxaccounts.autoconfig.uri": "https://$content.$name/",
APPEND/PREPEND https://$content.$name to "webchannel.allowObject.urlWhitelist" (and restart browser to make webchannel work)
HERE
# TODO: yq r only once
if test "$webext_storagesync_enable" == "true" ; then
cat <<HERE
"webextensions.storage.sync.kinto": true
"webextensions.storage.sync.serverURL": "https://$kinto.$name/v1"
HERE
fi
if test "$send_enable" == "true" ; then
cat <<HERE
"identity.fxaccounts.service.sendLoginUrl": "https://$send.$name/login/"
HERE
fi
echo -e "\e[0m" #reset
echo -e "\e[32m Config for Fenix(Firefox android)\e[0m"
echo -e "\e[33m"
cat <<HERE
Enable "Secret Menu" See: https://github.com/mozilla-mobile/fenix/pull/8916
"Custom Firefox Account server":"https://$content.$name",
"Custom Sync server": "https://$sync.$name/token/1.0/sync/1.5",
HERE
echo -e "\e[0m" #reset
if test "$(yq e .mail.type config.yml)" == "localhelper" ; then
echo -e "\e[32m Check sigincode \e[0m"
echo -e "\e[33m"
cat <<HERE
docker-compose logs fxa-auth-local-mail-helper |grep -i code
HERE
echo -e "\e[0m"
# TODO replace 127.0.0.1:9001 to yq r
localhelperweb=$(yq e .mail.localhelper.web config.yml)
if test "$localhelperweb" != ""; then
echo -e "\e[32m Or (Assume your account example@test.local) \e[0m"
echo -e "\e[33m"
cat <<HERE
Get Code: curl http://$localhelperweb/mail/example
Clean up: curl -X DELETE http://$localhelperweb/mail/example
HERE
echo -e "\e[0m"
fi
fi
echo -e "\e[32m After renew certs (not using reverse proxy): \e[0m"
echo -e "\e[33m"
cat <<HERE
docker-compose exec nginx nginx -s reload
HERE
echo -e "\e[0m"
set -x
# cleanup
if test "$should_del_yq" == "1"; then
echo -e "\e[32mRemove mikefarah/yq\e[0m"
docker image rm mikefarah/yq:4.13.2 >/dev/null 2>&1
fi
if test "$should_del_ytt" == "1"; then
echo -e "\e[32mRemove ytt\e[0m"
docker image rm k14s/image@sha256:1100ed870cd6bdbef229f650f044cb03e91566c7ee0c7bfdbc08efc6196a41d8 >/dev/null 2>&1
fi