-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-probe_setup.sh
executable file
·30 lines (25 loc) · 1 KB
/
gh-probe_setup.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
#!/bin/sh
#
# GITHUB_TOKEN - secret token
# ORIGIN - public domain
# BASENAME - path
#
if [ ! "$GITHUB_TOKEN" ] || [ ! "$ORIGIN" ]; then
echo "GITHUB_TOKEN and ORIGIN required" >&2
exit 1
fi
index_html="/usr/share/nginx/gh-probe/index.html"
# patching index.html is a way to pass environment variables
origin=$(echo "${ORIGIN}" | sed 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')
sed -i "s/<body>/&<script>ORIGIN=\'${origin}\'<\/script>/i" "$index_html"
if [ "$BASENAME" ]; then
basename=$(echo "${BASENAME}" | sed 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')
sed -i "s/<body><script>/&BASENAME=\'${basename}\';/i;\
s/\/favicon.ico/${basename}&/ig;\
s/\/static\/js/${basename}&/ig;\
s/\/manifest.json/${basename}&/ig" \
"$index_html"
fi
sed -i "/^\s*pid/c\pid /run/nginx_gh-probe.pid;" "/etc/nginx/nginx.conf"
sed -i "/^\s*#/d; s/__GITHUB_TOKEN__/${GITHUB_TOKEN}/g;" "/etc/nginx/conf.d/gh-probe.conf"
rm -r /etc/nginx/conf.d/default.conf /usr/share/nginx/html /tmp/gh-probe_setup.sh