fix(install): make setup failures explicit and atomic

Installer pipelines masked dependency and download failures, causing
false success messages and unsafe config replacement.

Atomic updates and current upstream installers keep failures visible.
This commit is contained in:
Frank Qing
2026-07-15 00:16:33 +08:00
parent 9641876d43
commit 76395923ce
14 changed files with 350 additions and 432 deletions
+62 -46
View File
@@ -1,7 +1,6 @@
#!/bin/bash
# Save the original working directory
ORIGINAL_DIR="$(pwd)"
set -euo pipefail
# Function to detect the operating system
detect_os() {
@@ -15,50 +14,71 @@ detect_os() {
fi
}
run_as_root() {
if (( EUID == 0 )); then
"$@"
elif command -v sudo &> /dev/null; then
sudo "$@"
else
echo "Error: sudo is required to install unzip." >&2
exit 1
fi
}
install_unzip() {
command -v unzip &> /dev/null && return
echo "Installing required dependency: unzip"
case $(detect_os) in
ubuntu|debian)
run_as_root apt-get update
run_as_root apt-get install -y unzip
;;
fedora)
run_as_root dnf install -y unzip
;;
centos|rhel)
if command -v dnf &> /dev/null; then
run_as_root dnf install -y unzip
else
run_as_root yum install -y unzip
fi
;;
arch|manjaro)
run_as_root pacman -S --needed --noconfirm unzip
;;
*)
echo "Error: unzip is required. Install it with your package manager and retry." >&2
exit 1
;;
esac
}
# Install fnm (Fast Node Manager) if it is not already installed
if command -v fnm &> /dev/null; then
echo -e "fnm is already installed\n"
fnm --version
else
echo -e "Installing fnm (Fast Node Manager)\n"
os=$(detect_os)
case $os in
macos)
# Try homebrew first on macOS
if command -v brew &> /dev/null; then
echo "Installing fnm via Homebrew..."
brew install fnm
else
echo "Installing fnm via official installer..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
fi
;;
ubuntu|debian)
# Use the official installer for Linux
echo "Installing fnm via official installer..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
;;
fedora|centos|rhel)
# Use the official installer for RHEL-based distros
echo "Installing fnm via official installer..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
;;
arch|manjaro)
# Use the official installer for Arch-based distros
echo "Installing fnm via official installer..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
;;
*)
echo "Using official installer for unknown OS..."
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/install/fnm.sh | bash
;;
esac
# Load fnm for the remainder of this script
export PATH="$HOME/.local/share/fnm:$PATH"
eval "$(fnm env --use-on-cd)"
os=$(detect_os)
if [[ "$os" == "macos" ]] && command -v brew &> /dev/null; then
echo "Installing fnm via Homebrew..."
brew install fnm
else
install_unzip
install_dir="${XDG_DATA_HOME:-$HOME/.local/share}/fnm"
installer_args=(--install-dir "$install_dir" --skip-shell)
[[ "$os" == "macos" ]] && installer_args+=(--force-install)
echo "Installing fnm via official installer..."
curl -fsSL https://fnm.vercel.app/install | bash -s -- "${installer_args[@]}"
export PATH="$install_dir:$PATH"
fi
command -v fnm &> /dev/null
eval "$(fnm env --use-on-cd --shell bash)"
fi
# OPTIONAL: Install the latest LTS version of Node.js
@@ -69,17 +89,13 @@ fi
# fnm default lts-latest
# Apply the fnm zsh configuration patch (downloads zshrc/fnm.zsh to ~/.config/zshrc/fnm.zsh)
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s fnm
curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s -- fnm
echo -e "\nfnm installation completed!"
echo -e "To start using fnm, restart your terminal or run: source ~/.zshrc"
echo -e "\nUseful fnm commands:"
echo -e " fnm install --lts # Install latest LTS Node.js"
echo -e " fnm install 18 # Install Node.js v18"
echo -e " fnm use 18 # Use Node.js v18"
echo -e " fnm default 18 # Set Node.js v18 as default"
echo -e " fnm use lts-latest # Use the latest LTS release"
echo -e " fnm default lts-latest # Set the latest LTS as default"
echo -e " fnm list # List installed versions"
echo -e " fnm list-remote # List available versions"
# Restore original working directory
cd "$ORIGINAL_DIR"