File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -7,6 +7,28 @@ REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
77. " $REPO_DIR /scripts/lib/common.sh"
88
99detect_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
You can’t perform that action at this time.
0 commit comments