-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtinysta.sh
executable file
·51 lines (44 loc) · 1.09 KB
/
tinysta.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
#!/bin/sh
OPENRESTY_PREFIX=${OPENRESTY_PREFIX:-/usr/local/openresty}
export OPENRESTY_PREFIX
TINYSTASH_DIR=$(dirname "$(readlink -f "${0}")")
export TINYSTASH_DIR
TINYSTASH_CONFIG_PATH=$(readlink -f "${TINYSTASH_CONFIG_PATH:-"${TINYSTASH_DIR}/config.lua"}")
export TINYSTASH_CONFIG_PATH
command_runner="${TINYSTASH_DIR}/commands/command-runner.sh"
nginx_conf="${TINYSTASH_DIR}/nginx.conf"
usage() {
echo "
usage: ${0} COMMAND [ARGS]
commands:
run
conf
webhook
"
exit 1
}
if [ "${#}" -eq 0 ] || [ "${1}" = '-h' ]; then
usage
fi
command=${1}
shift
case "${command}" in
conf|webhook)
echo "using config: ${TINYSTASH_CONFIG_PATH}"
echo
exec "${command_runner}" "${command}" "${@}"
;;
run)
echo "using config: ${TINYSTASH_CONFIG_PATH}"
echo
if ! nginx_conf_content=$("${command_runner}" conf); then
echo "error while generating nginx.conf:"
echo "${nginx_conf_content}"
exit 2
fi
echo "${nginx_conf_content}" > "${nginx_conf}"
exec "${OPENRESTY_PREFIX}/nginx/sbin/nginx" -c "${nginx_conf}" -p "${TINYSTASH_DIR}"
;;
*)
usage
esac