diff --git a/passwall.sh b/passwall.sh index 50686a4..e9f1488 100755 --- a/passwall.sh +++ b/passwall.sh @@ -27,6 +27,31 @@ need_cmd() { command -v "$1" >/dev/null 2>&1 || die "缺少命令: $1" } +pkg_installed() { + pkg="$1" + opkg status "$pkg" 2>/dev/null | grep -q '^Status: install ' +} + +install_if_missing_from_dir() { + pkg="$1" + dir="$2" + + if pkg_installed "$pkg"; then + log "依赖检查: $pkg 已安装,跳过" + return 0 + fi + + log "依赖检查: $pkg 未安装,开始下载并安装" + ipk_path="$(download_pkg_from_dir "$pkg" "$dir")" || die "下载 $pkg 失败,请检查 ${dir} 构建是否完整,或稍后重试。" + + if opkg install "$ipk_path"; then + log "依赖安装: $pkg 安装完成" + return 0 + fi + + die "$pkg 安装失败,请执行 opkg update 后重试,或检查第三方源冲突。" +} + refresh_luci() { rm -rf /tmp/luci-* /tmp/.luci* /tmp/etc/config/ucitrack /var/run/luci-indexcache 2>/dev/null || true if [ -x /etc/init.d/rpcd ]; then @@ -154,10 +179,13 @@ OLD_VER="$(opkg status luci-app-passwall 2>/dev/null | sed -n 's/^Version: //p' log "当前已安装版本: ${OLD_VER:-not installed}" log "按接近手动 IPK 的方式安装 / 更新 PassWall" +install_if_missing_from_dir chinadns-ng passwall_packages +install_if_missing_from_dir dns2socks passwall_packages + MAIN_IPK="$(download_pkg_from_dir luci-app-passwall passwall_luci)" || die "下载 luci-app-passwall 失败,请检查当前系统版本/架构是否存在对应构建,或稍后重试。" -LANG_IPK="$(download_pkg_from_dir luci-i18n-passwall-zh-cn passwall_luci)" || die "下载 luci-i18n-passwall-zh-cn 失败,请稍后重试。" +LANG_IPK="" -if ! opkg install "$MAIN_IPK" "$LANG_IPK"; then +if ! opkg install "$MAIN_IPK"; then cat >&2 </dev/null | grep -q 'passwall\.zh-cn\.lmo'; then + log "语言包检查: 主包已内置 zh-cn,跳过独立安装 luci-i18n-passwall-zh-cn" +elif pkg_installed luci-i18n-passwall-zh-cn; then + log "语言包检查: luci-i18n-passwall-zh-cn 已安装,跳过" +else + log "语言包检查: luci-i18n-passwall-zh-cn 未安装,开始下载并安装" + [ -n "$LANG_IPK" ] || LANG_IPK="$(download_pkg_from_dir luci-i18n-passwall-zh-cn passwall_luci)" || die "下载 luci-i18n-passwall-zh-cn 失败,请稍后重试。" + if ! opkg install "$LANG_IPK"; then + cat >&2 </dev/null 2>&1 || die "缺少命令: $1" } +pkg_installed() { + pkg="$1" + opkg status "$pkg" 2>/dev/null | grep -q '^Status: install ' +} + +install_if_missing_from_dir() { + pkg="$1" + dir="$2" + + if pkg_installed "$pkg"; then + log "依赖检查: $pkg 已安装,跳过" + return 0 + fi + + log "依赖检查: $pkg 未安装,开始下载并安装" + ipk_path="$(download_pkg_from_dir "$pkg" "$dir")" || die "下载 $pkg 失败,请检查 ${dir} 构建是否完整,或稍后重试。" + + if opkg install "$ipk_path"; then + log "依赖安装: $pkg 安装完成" + return 0 + fi + + die "$pkg 安装失败,请执行 opkg update 后重试,或检查第三方源冲突。" +} + refresh_luci() { rm -rf /tmp/luci-* /tmp/.luci* /tmp/etc/config/ucitrack /var/run/luci-indexcache 2>/dev/null || true if [ -x /etc/init.d/rpcd ]; then @@ -154,15 +179,18 @@ OLD_VER="$(opkg status luci-app-passwall2 2>/dev/null | sed -n 's/^Version: //p' log "当前已安装版本: ${OLD_VER:-not installed}" log "按接近手动 IPK 的方式安装 / 更新 PassWall2" +install_if_missing_from_dir tcping passwall_packages +install_if_missing_from_dir geoview passwall_packages + MAIN_IPK="$(download_pkg_from_dir luci-app-passwall2 passwall2)" || die "下载 luci-app-passwall2 失败,请检查当前系统版本/架构是否存在对应构建,或稍后重试。" -LANG_IPK="$(download_pkg_from_dir luci-i18n-passwall2-zh-cn passwall2)" || die "下载 luci-i18n-passwall2-zh-cn 失败,请稍后重试。" +LANG_IPK="" -if ! opkg install "$MAIN_IPK" "$LANG_IPK"; then +if ! opkg install "$MAIN_IPK"; then cat >&2 </dev/null | grep -q 'passwall2\.zh-cn\.lmo'; then + log "语言包检查: 主包已内置 zh-cn,跳过独立安装 luci-i18n-passwall2-zh-cn" +elif pkg_installed luci-i18n-passwall2-zh-cn; then + log "语言包检查: luci-i18n-passwall2-zh-cn 已安装,跳过" +else + [ -n "$LANG_IPK" ] || LANG_IPK="$(download_pkg_from_dir luci-i18n-passwall2-zh-cn passwall2)" || die "下载 luci-i18n-passwall2-zh-cn 失败,请稍后重试。" + if ! opkg install "$LANG_IPK"; then + cat >&2 <