Refactor OS auto-detection and fix case statements

This commit is contained in:
2024-12-06 09:38:39 -05:00
parent 7d0570daff
commit 5042ae25c3

View File

@@ -18,7 +18,7 @@
# * Be careful with tabs in heredocs # * Be careful with tabs in heredocs
shopt -s extglob shopt -s extglob
declare -g SCRIPT_VERSION="1.4.5" declare -g SCRIPT_VERSION="1.4.6-dev"
declare -g MC_REPO="bullseye" # should match the MC_VERSION declare -g MC_REPO="bullseye" # should match the MC_VERSION
declare -g MC_VERSION="33.0.37" # Do find all replace declare -g MC_VERSION="33.0.37" # Do find all replace
declare -g BOARD_URL="https://yabb.jriver.com/interact/index.php/board,86.0.html" # MC33 declare -g BOARD_URL="https://yabb.jriver.com/interact/index.php/board,86.0.html" # MC33
@@ -288,24 +288,31 @@ init() {
;; ;;
*) *)
err "Auto-detecting distro, this is unreliable and --compat may be required" err "Auto-detecting distro, this is unreliable and --compat may be required"
if command -v dnf &>/dev/null; then for cmd in dnf yum apt-get pacman; do
ID="fedora" if command -v "$cmd" &>/dev/null; then
elif command -v yum &>/dev/null; then case "$cmd" in
ID="centos" dnf) ID="fedora" ;;
COMPAT_SWITCH=1 yum) ID="centos"; COMPAT_SWITCH=1 ;;
elif command -v apt-get &>/dev/null; then apt-get) ID="ubuntu" ;;
ID="ubuntu" pacman) ID="arch" ;;
elif command -v pacman &>/dev/null; then esac
ID="arch" break
else fi
done
if [[ -z $ID ]]; then
err "OS detection failed!" err "OS detection failed!"
ask_ok "Continue with manual installation?" || exit 1 if ask_ok "Continue with manual installation?"; then
debug "Automatically using --install=local for unknown distro" debug "Automatically using --install=local for unknown distro"
ID="unknown" ID="unknown"
REPO_INSTALL_SWITCH=0 REPO_INSTALL_SWITCH=0
BUILD_SWITCH=1 BUILD_SWITCH=1
LOCAL_INSTALL_SWITCH=1 LOCAL_INSTALL_SWITCH=1
else
exit 1
fi
fi fi
;;
esac esac
# Set default targets # Set default targets
@@ -366,6 +373,7 @@ init() {
PKG_UPDATE=(:) PKG_UPDATE=(:)
PKG_QUERY=(:) PKG_QUERY=(:)
PKG_INSTALL_LOCAL() { install_mc_generic; } PKG_INSTALL_LOCAL() { install_mc_generic; }
;;
esac esac
# Don't check for latest MC version if set by user or using --install=repo only # Don't check for latest MC version if set by user or using --install=repo only
@@ -386,12 +394,8 @@ init() {
if [[ -n $USER_MC_VERSION ]]; then if [[ -n $USER_MC_VERSION ]]; then
# Append explicit package version when user provides --mcversion # Append explicit package version when user provides --mcversion
case $ID in case $ID in
fedora|centos|suse) fedora|centos|suse) MC_PKG+="-$MC_VERSION" ;;
MC_PKG+="-$MC_VERSION" debian|ubuntu) MC_PKG+="=$MC_VERSION" ;;
;;
debian|ubuntu)
MC_PKG+="=$MC_VERSION"
;;
esac esac
fi fi