Skip to content

Commit 361c7b1

Browse files
author
farfarfun
committed
chore: enhance nlt-common.sh sourcing with fallbacks and error handling
1 parent c0fc8d0 commit 361c7b1

8 files changed

Lines changed: 81 additions & 16 deletions

File tree

scripts/services/airflow/setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,16 @@ FAB_AUTH_MANAGER_CLASS="airflow.providers.fab.auth_manager.fab_auth_manager.FabA
6464
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6565
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
6666

67-
# shellcheck source=../../lib/nlt-common.sh
68-
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
67+
if [[ -f "${SCRIPT_DIR}/../lib/nlt-common.sh" ]]; then
68+
# shellcheck source=../lib/nlt-common.sh
69+
source "${SCRIPT_DIR}/../lib/nlt-common.sh"
70+
elif [[ -f "${SCRIPT_DIR}/../../lib/nlt-common.sh" ]]; then
71+
# shellcheck source=../../lib/nlt-common.sh
72+
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
73+
else
74+
echo "错误: 找不到 lib/nlt-common.sh(已检查 ${SCRIPT_DIR}/../lib 与 ${SCRIPT_DIR}/../../lib)" >&2
75+
exit 1
76+
fi
6977

7078
say_info() {
7179
gum style --foreground 212 "$*"

scripts/services/celery/setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@
3030
set -euo pipefail
3131

3232
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
33-
# shellcheck source=../../lib/nlt-common.sh
34-
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
33+
if [[ -f "${SCRIPT_DIR}/../lib/nlt-common.sh" ]]; then
34+
# shellcheck source=../lib/nlt-common.sh
35+
source "${SCRIPT_DIR}/../lib/nlt-common.sh"
36+
elif [[ -f "${SCRIPT_DIR}/../../lib/nlt-common.sh" ]]; then
37+
# shellcheck source=../../lib/nlt-common.sh
38+
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
39+
else
40+
echo "错误: 找不到 lib/nlt-common.sh(已检查 ${SCRIPT_DIR}/../lib 与 ${SCRIPT_DIR}/../../lib)" >&2
41+
exit 1
42+
fi
3543

3644
usage() {
3745
cat <<'USAGE'

scripts/services/code-server/setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@
2121
set -euo pipefail
2222

2323
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24-
# shellcheck source=../../lib/nlt-common.sh
25-
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
24+
if [[ -f "${SCRIPT_DIR}/../lib/nlt-common.sh" ]]; then
25+
# shellcheck source=../lib/nlt-common.sh
26+
source "${SCRIPT_DIR}/../lib/nlt-common.sh"
27+
elif [[ -f "${SCRIPT_DIR}/../../lib/nlt-common.sh" ]]; then
28+
# shellcheck source=../../lib/nlt-common.sh
29+
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
30+
else
31+
echo "错误: 找不到 lib/nlt-common.sh(已检查 ${SCRIPT_DIR}/../lib 与 ${SCRIPT_DIR}/../../lib)" >&2
32+
exit 1
33+
fi
2634

2735
CODE_SERVER_SERVICE_HOME="${CODE_SERVER_SERVICE_HOME:-${HOME}/opt/code-server}"
2836
CODE_SERVER_BIND="${CODE_SERVER_BIND:-127.0.0.1:8080}"

scripts/services/new-api/setup.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@
2222
set -euo pipefail
2323

2424
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25-
# shellcheck source=../../lib/nlt-common.sh
26-
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
25+
# 仓库内为 scripts/.../<域>/;install 同步后为 libexec/nltdeploy/<域>/(与 lib/ 同级)→ 先试 ../lib 再 ../../lib
26+
if [[ -f "${SCRIPT_DIR}/../lib/nlt-common.sh" ]]; then
27+
# shellcheck source=../lib/nlt-common.sh
28+
source "${SCRIPT_DIR}/../lib/nlt-common.sh"
29+
elif [[ -f "${SCRIPT_DIR}/../../lib/nlt-common.sh" ]]; then
30+
# shellcheck source=../../lib/nlt-common.sh
31+
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
32+
else
33+
echo "错误: 找不到 lib/nlt-common.sh(已检查 ${SCRIPT_DIR}/../lib 与 ${SCRIPT_DIR}/../../lib)" >&2
34+
exit 1
35+
fi
2736

2837
NEW_API_GITHUB_REPO="${NEW_API_GITHUB_REPO:-QuantumNous/new-api}"
2938
NEW_API_SERVICE_HOME="${NEW_API_SERVICE_HOME:-${HOME}/opt/new-api}"

scripts/services/paperclip/setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@
2222
set -euo pipefail
2323

2424
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25-
# shellcheck source=../../lib/nlt-common.sh
26-
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
25+
if [[ -f "${SCRIPT_DIR}/../lib/nlt-common.sh" ]]; then
26+
# shellcheck source=../lib/nlt-common.sh
27+
source "${SCRIPT_DIR}/../lib/nlt-common.sh"
28+
elif [[ -f "${SCRIPT_DIR}/../../lib/nlt-common.sh" ]]; then
29+
# shellcheck source=../../lib/nlt-common.sh
30+
source "${SCRIPT_DIR}/../../lib/nlt-common.sh"
31+
else
32+
echo "错误: 找不到 lib/nlt-common.sh(已检查 ${SCRIPT_DIR}/../lib 与 ${SCRIPT_DIR}/../../lib)" >&2
33+
exit 1
34+
fi
2735

2836
PAPERCLIP_SERVICE_HOME="${PAPERCLIP_SERVICE_HOME:-${HOME}/opt/paperclip}"
2937
PAPERCLIP_REPO_URL="${PAPERCLIP_REPO_URL:-https://github.com/paperclipai/paperclip.git}"

scripts/tools/github-net/setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@
1818
set -euo pipefail
1919

2020
_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21-
# shellcheck source=../../lib/nlt-common.sh
22-
source "${_SCRIPT_DIR}/../../lib/nlt-common.sh"
21+
if [[ -f "${_SCRIPT_DIR}/../lib/nlt-common.sh" ]]; then
22+
# shellcheck source=../lib/nlt-common.sh
23+
source "${_SCRIPT_DIR}/../lib/nlt-common.sh"
24+
elif [[ -f "${_SCRIPT_DIR}/../../lib/nlt-common.sh" ]]; then
25+
# shellcheck source=../../lib/nlt-common.sh
26+
source "${_SCRIPT_DIR}/../../lib/nlt-common.sh"
27+
else
28+
echo "错误: 找不到 lib/nlt-common.sh(已检查 ${_SCRIPT_DIR}/../lib 与 ${_SCRIPT_DIR}/../../lib)" >&2
29+
exit 1
30+
fi
2331

2432
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
2533
SSH_CONFIG_PATH="${HOME}/.ssh/config"

scripts/tools/pip-sources/setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55

66
set -e # 遇到错误立即退出
77

8-
_NLT_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../lib" && pwd)"
9-
# shellcheck source=../../lib/nlt-common.sh
8+
_PSDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
if [[ -f "${_PSDIR}/../lib/nlt-common.sh" ]]; then
10+
_NLT_LIB="$(cd "${_PSDIR}/../lib" && pwd)"
11+
elif [[ -f "${_PSDIR}/../../lib/nlt-common.sh" ]]; then
12+
_NLT_LIB="$(cd "${_PSDIR}/../../lib" && pwd)"
13+
else
14+
echo "错误: 找不到 lib/nlt-common.sh(已检查 ${_PSDIR}/../lib 与 ${_PSDIR}/../../lib)" >&2
15+
exit 1
16+
fi
17+
# shellcheck source=../lib/nlt-common.sh
1018
source "${_NLT_LIB}/nlt-common.sh"
1119

1220
# 颜色输出

scripts/tools/python-env/setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55

66
set -e # 遇到错误立即退出
77

8-
_NLT_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../lib" && pwd)"
9-
# shellcheck source=../../lib/nlt-common.sh
8+
_PSDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
if [[ -f "${_PSDIR}/../lib/nlt-common.sh" ]]; then
10+
_NLT_LIB="$(cd "${_PSDIR}/../lib" && pwd)"
11+
elif [[ -f "${_PSDIR}/../../lib/nlt-common.sh" ]]; then
12+
_NLT_LIB="$(cd "${_PSDIR}/../../lib" && pwd)"
13+
else
14+
echo "错误: 找不到 lib/nlt-common.sh(已检查 ${_PSDIR}/../lib 与 ${_PSDIR}/../../lib)" >&2
15+
exit 1
16+
fi
17+
# shellcheck source=../lib/nlt-common.sh
1018
source "${_NLT_LIB}/nlt-common.sh"
1119

1220
# 颜色输出

0 commit comments

Comments
 (0)