Skip to content

Commit 5dfee05

Browse files
authored
fix: 修复多工具链环境下包格式检测误判,优先基于发行版识别 (#8)
- 重构 scripts/package.sh 的 detect_package_format(),优先读取 /etc/os-release 识别发行版(Fedora/RHEL → rpm,Debian/Ubuntu → deb, Arch → pacman),工具链探测降级为 fallback - 重构 scripts/install-package.sh 的安装逻辑,新增 detect_install_format() 同样优先基于发行版判断,避免非 Debian 分支系统上安装了 dpkg 导致误用 deb 格式
1 parent 604c011 commit 5dfee05

2 files changed

Lines changed: 52 additions & 8 deletions

File tree

‎scripts/install-package.sh‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,38 @@ install_pacman() {
4747
sudo pacman -U --noconfirm "$artifact"
4848
}
4949

50-
main() {
51-
if command -v dpkg >/dev/null 2>&1 && install_deb; then
52-
return 0
53-
fi
54-
if install_rpm; then
55-
return 0
50+
detect_install_format() {
51+
if [ -f /etc/os-release ]; then
52+
local id id_like
53+
. /etc/os-release
54+
id_like="${ID_LIKE:-$ID}"
55+
case "$ID $id_like" in
56+
*fedora*|*rhel*|*centos*|*rocky*|*alma*|*suse*) echo "rpm"; return 0 ;;
57+
*debian*|*ubuntu*|*mint*) echo "deb"; return 0 ;;
58+
*arch*|*manjaro*) echo "pacman"; return 0 ;;
59+
esac
5660
fi
57-
if install_pacman; then
58-
return 0
61+
# Fallback
62+
if command -v dpkg >/dev/null 2>&1; then echo "deb"
63+
elif command -v rpm >/dev/null 2>&1; then echo "rpm"
64+
elif command -v pacman >/dev/null 2>&1; then echo "pacman"
5965
fi
66+
}
67+
68+
main() {
69+
local fmt
70+
fmt="$(detect_install_format)"
71+
72+
case "$fmt" in
73+
deb) install_deb && return 0 ;;
74+
rpm) install_rpm && return 0 ;;
75+
pacman) install_pacman && return 0 ;;
76+
esac
77+
78+
# Ultimate fallback: try all in order
79+
if install_rpm; then return 0; fi
80+
if install_deb; then return 0; fi
81+
if install_pacman; then return 0; fi
6082

6183
error "No installable package artifact found in dist/. Run make package first."
6284
}

‎scripts/package.sh‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
77
. "$REPO_DIR/scripts/lib/common.sh"
88

99
detect_package_format() {
10+
# 1. 优先基于发行版识别(/etc/os-release 是 systemd/Linux 标准规范)
11+
if [ -f /etc/os-release ]; then
12+
local id id_like
13+
. /etc/os-release
14+
id_like="${ID_LIKE:-$ID}"
15+
case "$ID $id_like" in
16+
*fedora*|*rhel*|*centos*|*rocky*|*alma*|*suse*)
17+
if command -v rpmbuild >/dev/null 2>&1; then
18+
echo "rpm"; return 0
19+
fi ;;
20+
*debian*|*ubuntu*|*mint*)
21+
if command -v dpkg-deb >/dev/null 2>&1 && command -v dpkg >/dev/null 2>&1; then
22+
echo "deb"; return 0
23+
fi ;;
24+
*arch*|*manjaro*)
25+
if command -v makepkg >/dev/null 2>&1; then
26+
echo "pacman"; return 0
27+
fi ;;
28+
esac
29+
fi
30+
31+
# 2. Fallback: 无法通过发行版判断时探测工具链
1032
if command -v dpkg-deb >/dev/null 2>&1 && command -v dpkg >/dev/null 2>&1; then
1133
echo "deb"
1234
elif command -v rpmbuild >/dev/null 2>&1; then

0 commit comments

Comments
 (0)