diff --git a/README.md b/README.md index 82987d8..74c4561 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ cd clash-for-linux ```bash opkg update -opkg install bash curl tar gzip coreutils-readlink unzip +opkg install bash curl tar gzip coreutils-readlink coreutils-install coreutils-nohup unzip ``` 安装与手动管理: diff --git a/scripts/core/common.sh b/scripts/core/common.sh index de0bd08..bf383dd 100644 --- a/scripts/core/common.sh +++ b/scripts/core/common.sh @@ -1209,7 +1209,7 @@ is_openwrt() { } openwrt_dependency_hint() { - echo "opkg update && opkg install bash curl tar gzip coreutils-readlink unzip" + echo "opkg update && opkg install bash curl tar gzip coreutils-readlink coreutils-install coreutils-nohup unzip" } openwrt_project_dir_is_persistent() { @@ -1240,7 +1240,7 @@ ensure_openwrt_install_supported() { ;; esac - for command_name in bash curl tar gzip readlink unzip; do + for command_name in bash curl tar gzip readlink install nohup unzip; do if ! command -v "$command_name" >/dev/null 2>&1; then missing="${missing}${missing:+ }$command_name" fi diff --git a/scripts/dev/check-openwrt-dependencies.sh b/scripts/dev/check-openwrt-dependencies.sh new file mode 100755 index 0000000..1aeaa9c --- /dev/null +++ b/scripts/dev/check-openwrt-dependencies.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +set -euo pipefail + +PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" + +source "$PROJECT_DIR/scripts/core/common.sh" + +tmp_dir="$(mktemp -d)" +trap 'rm -rf "$tmp_dir"' EXIT + +openwrt_root="$tmp_dir/openwrt" +fake_bin="$tmp_dir/bin" +mkdir -p "$openwrt_root/etc" "$fake_bin" +: > "$openwrt_root/etc/openwrt_release" + +link_command() { + local command_name="$1" + local command_path + + command_path="$(command -v "$command_name")" + ln -s "$command_path" "$fake_bin/$command_name" +} + +for command_name in bash curl tar gzip readlink unzip; do + link_command "$command_name" +done + +output_file="$tmp_dir/missing-dependencies.out" +set +e +( + export CLASH_OPENWRT_ROOT="$openwrt_root" + export CLASH_TEST_UNAME_M="aarch64" + PATH="$fake_bin" + ensure_openwrt_install_supported +) > "$output_file" 2>&1 +status=$? +set -e + +if [ "$status" -eq 0 ]; then + echo "not ok - OpenWrt preflight should reject missing install and nohup commands" >&2 + exit 1 +fi + +if ! grep -Fq "OpenWrt 缺少依赖命令:install nohup" "$output_file"; then + echo "not ok - OpenWrt preflight did not report install and nohup together" >&2 + cat "$output_file" >&2 + exit 1 +fi + +if ! grep -Fq "coreutils-install coreutils-nohup" "$output_file"; then + echo "not ok - OpenWrt dependency hint omitted install/nohup packages" >&2 + cat "$output_file" >&2 + exit 1 +fi + +echo "ok - OpenWrt preflight reports install and nohup packages before downloads" + +link_command install +link_command nohup + +( + export CLASH_OPENWRT_ROOT="$openwrt_root" + export CLASH_TEST_UNAME_M="aarch64" + PATH="$fake_bin" + ensure_openwrt_install_supported +) + +echo "ok - OpenWrt preflight accepts the complete dependency set"