f2d90b38 commited on
Commit
0fe5e35
·
verified ·
1 Parent(s): a38895d

Upload 4 files

Browse files
Files changed (1) hide show
  1. start.sh +24 -27
start.sh CHANGED
@@ -1,13 +1,14 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
 
4
- if [[ -z "${PROXY_PATH:-}" ]]; then
5
  PROXY_PATH="/api"
6
  fi
7
- if [[ "${PROXY_PATH}" != /* ]]; then
8
- PROXY_PATH="/${PROXY_PATH}"
9
- fi
10
- if [[ "${PROXY_PATH}" == "/" ]]; then
 
11
  echo "PROXY_PATH cannot be '/' because '/' is reserved for the cover page."
12
  exit 1
13
  fi
@@ -16,16 +17,16 @@ CONFIG_PATH="${CONFIG_PATH:-/data/config.yaml}"
16
  AUTH_DIR="${AUTH_DIR:-/data/auth}"
17
 
18
  mkdir -p "$(dirname "${CONFIG_PATH}")" "${AUTH_DIR}"
19
- if [[ -f "${CONFIG_PATH}" ]]; then
20
  ln -sf "${CONFIG_PATH}" /CLIProxyAPI/config.yaml
21
  fi
22
- if [[ -e /root/.cli-proxy-api && ! -L /root/.cli-proxy-api ]]; then
23
  rm -rf /root/.cli-proxy-api
24
  fi
25
  ln -sfn "${AUTH_DIR}" /root/.cli-proxy-api
26
 
27
  NGINX_CONF_DIR="/etc/nginx/conf.d"
28
- if [[ -d "/etc/nginx/http.d" ]]; then
29
  NGINX_CONF_DIR="/etc/nginx/http.d"
30
  fi
31
 
@@ -35,55 +36,51 @@ envsubst '${PORT} ${PROXY_PATH} ${CLI_PROXY_HOST} ${CLI_PROXY_PORT}' \
35
  > "${NGINX_CONF_DIR}/default.conf"
36
 
37
  detect_cmd() {
38
- if [[ -n "${CLI_PROXY_CMD:-}" ]]; then
39
  echo "${CLI_PROXY_CMD}"
40
  return 0
41
  fi
42
- if [[ -x "/docker-entrypoint.sh" ]]; then
43
  echo "/docker-entrypoint.sh"
44
  return 0
45
  fi
46
- if [[ -x "/entrypoint.sh" ]]; then
47
  echo "/entrypoint.sh"
48
  return 0
49
  fi
50
- if [[ -x "/start.sh" && "/start.sh" != "$0" ]]; then
51
- echo "/start.sh"
52
- return 0
53
- fi
54
- if [[ -x "/CLIProxyAPI/cli-proxy-api" ]]; then
55
  echo "/CLIProxyAPI/cli-proxy-api"
56
  return 0
57
  fi
58
- if [[ -x "/CLIProxyAPI/start.sh" ]]; then
59
  echo "/CLIProxyAPI/start.sh"
60
  return 0
61
  fi
62
- if [[ -x "/CLIProxyAPI/run.sh" ]]; then
63
  echo "/CLIProxyAPI/run.sh"
64
  return 0
65
  fi
66
- if [[ -x "/CLIProxyAPI/CLIProxyAPI" ]]; then
67
  echo "/CLIProxyAPI/CLIProxyAPI"
68
  return 0
69
  fi
70
- if [[ -f "/CLIProxyAPI/main.py" ]]; then
71
  echo "python /CLIProxyAPI/main.py"
72
  return 0
73
  fi
74
- if [[ -f "/CLIProxyAPI/app.py" ]]; then
75
  echo "python /CLIProxyAPI/app.py"
76
  return 0
77
  fi
78
- if [[ -f "/CLIProxyAPI/server.py" ]]; then
79
  echo "python /CLIProxyAPI/server.py"
80
  return 0
81
  fi
82
- if [[ -f "/CLIProxyAPI/index.js" ]]; then
83
  echo "node /CLIProxyAPI/index.js"
84
  return 0
85
  fi
86
- if [[ -f "/CLIProxyAPI/package.json" ]]; then
87
  echo "npm start --prefix /CLIProxyAPI"
88
  return 0
89
  fi
@@ -91,7 +88,7 @@ detect_cmd() {
91
  }
92
 
93
  CLI_CMD="$(detect_cmd || true)"
94
- if [[ -z "${CLI_CMD}" ]]; then
95
  echo "Cannot detect how to start CLIProxyAPI."
96
  echo "Set CLI_PROXY_CMD in Space Variables to the correct launch command."
97
  exit 1
 
1
+ #!/bin/sh
2
+ set -eu
3
 
4
+ if [ -z "${PROXY_PATH:-}" ]; then
5
  PROXY_PATH="/api"
6
  fi
7
+ case "${PROXY_PATH}" in
8
+ /*) ;;
9
+ *) PROXY_PATH="/${PROXY_PATH}" ;;
10
+ esac
11
+ if [ "${PROXY_PATH}" = "/" ]; then
12
  echo "PROXY_PATH cannot be '/' because '/' is reserved for the cover page."
13
  exit 1
14
  fi
 
17
  AUTH_DIR="${AUTH_DIR:-/data/auth}"
18
 
19
  mkdir -p "$(dirname "${CONFIG_PATH}")" "${AUTH_DIR}"
20
+ if [ -f "${CONFIG_PATH}" ]; then
21
  ln -sf "${CONFIG_PATH}" /CLIProxyAPI/config.yaml
22
  fi
23
+ if [ -e /root/.cli-proxy-api ] && [ ! -L /root/.cli-proxy-api ]; then
24
  rm -rf /root/.cli-proxy-api
25
  fi
26
  ln -sfn "${AUTH_DIR}" /root/.cli-proxy-api
27
 
28
  NGINX_CONF_DIR="/etc/nginx/conf.d"
29
+ if [ -d "/etc/nginx/http.d" ]; then
30
  NGINX_CONF_DIR="/etc/nginx/http.d"
31
  fi
32
 
 
36
  > "${NGINX_CONF_DIR}/default.conf"
37
 
38
  detect_cmd() {
39
+ if [ -n "${CLI_PROXY_CMD:-}" ]; then
40
  echo "${CLI_PROXY_CMD}"
41
  return 0
42
  fi
43
+ if [ -x "/docker-entrypoint.sh" ]; then
44
  echo "/docker-entrypoint.sh"
45
  return 0
46
  fi
47
+ if [ -x "/entrypoint.sh" ]; then
48
  echo "/entrypoint.sh"
49
  return 0
50
  fi
51
+ if [ -x "/CLIProxyAPI/cli-proxy-api" ]; then
 
 
 
 
52
  echo "/CLIProxyAPI/cli-proxy-api"
53
  return 0
54
  fi
55
+ if [ -x "/CLIProxyAPI/start.sh" ]; then
56
  echo "/CLIProxyAPI/start.sh"
57
  return 0
58
  fi
59
+ if [ -x "/CLIProxyAPI/run.sh" ]; then
60
  echo "/CLIProxyAPI/run.sh"
61
  return 0
62
  fi
63
+ if [ -x "/CLIProxyAPI/CLIProxyAPI" ]; then
64
  echo "/CLIProxyAPI/CLIProxyAPI"
65
  return 0
66
  fi
67
+ if [ -f "/CLIProxyAPI/main.py" ]; then
68
  echo "python /CLIProxyAPI/main.py"
69
  return 0
70
  fi
71
+ if [ -f "/CLIProxyAPI/app.py" ]; then
72
  echo "python /CLIProxyAPI/app.py"
73
  return 0
74
  fi
75
+ if [ -f "/CLIProxyAPI/server.py" ]; then
76
  echo "python /CLIProxyAPI/server.py"
77
  return 0
78
  fi
79
+ if [ -f "/CLIProxyAPI/index.js" ]; then
80
  echo "node /CLIProxyAPI/index.js"
81
  return 0
82
  fi
83
+ if [ -f "/CLIProxyAPI/package.json" ]; then
84
  echo "npm start --prefix /CLIProxyAPI"
85
  return 0
86
  fi
 
88
  }
89
 
90
  CLI_CMD="$(detect_cmd || true)"
91
+ if [ -z "${CLI_CMD}" ]; then
92
  echo "Cannot detect how to start CLIProxyAPI."
93
  echo "Set CLI_PROXY_CMD in Space Variables to the correct launch command."
94
  exit 1