Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ required_commands=(
chown
wget
tar
xz
stat
useradd
usermod
Expand Down Expand Up @@ -497,6 +498,29 @@ version_specific_rules() {
fi
}

# Install system packages needed to extract Node.js .tar.xz archives (e.g. xz-utils on Debian).
install_system_dependencies() {
if command -v xz >/dev/null 2>&1; then
return 0
fi

cprint cyan "Installing missing system dependency: xz..."
if [[ -x "$(command -v apt-get)" ]]; then
apt-get update -y && apt-get install -y xz-utils
elif [[ -x "$(command -v dnf)" ]]; then
dnf install -y xz
elif [[ -x "$(command -v yum)" ]]; then
yum install -y xz
elif [[ -x "$(command -v pacman)" ]]; then
pacman -S --noconfirm --needed xz
elif [[ -x "$(command -v zypper)" ]]; then
zypper --non-interactive install xz
else
cprint yellow "Could not detect a package manager; please install xz (xz-utils) manually."
return 0
fi
}

# Check if all required commands are available
check_required_commands() {
local missing=0
Expand Down Expand Up @@ -1366,7 +1390,8 @@ main() {

# To be moved to a master pre check function.
safe_run resolve_node_arch "Failed to resolve Node.js architecture"


safe_run install_system_dependencies "Failed to install system dependencies"
safe_run check_required_commands "Missing required system commands"

safe_run check_node_installed "Failed to detect Node.js or npm at expected path. Node.js will be installed."
Expand Down
27 changes: 26 additions & 1 deletion setup_cn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ required_commands=(
chown
wget
tar
xz
stat
useradd
usermod
Expand Down Expand Up @@ -494,6 +495,29 @@ version_specific_rules() {
fi
}

# 安装解压 Node.js .tar.xz 所需的系统依赖(Debian 上为 xz-utils)
install_system_dependencies() {
if command -v xz >/dev/null 2>&1; then
return 0
fi

cprint cyan "正在安装缺失的系统依赖: xz..."
if [[ -x "$(command -v apt-get)" ]]; then
apt-get update -y && apt-get install -y xz-utils
elif [[ -x "$(command -v dnf)" ]]; then
dnf install -y xz
elif [[ -x "$(command -v yum)" ]]; then
yum install -y xz
elif [[ -x "$(command -v pacman)" ]]; then
pacman -S --noconfirm --needed xz
elif [[ -x "$(command -v zypper)" ]]; then
zypper --non-interactive install xz
else
cprint yellow "未能检测到软件包管理器,请手动安装 xz(xz-utils)。"
return 0
fi
}

# 检查是否所有需要的命令都可用
check_required_commands() {
local missing=0
Expand Down Expand Up @@ -1364,7 +1388,8 @@ main() {

# 移动到master预检查功能
safe_run resolve_node_arch "解析 Node.js 架构失败"


safe_run install_system_dependencies "安装系统依赖失败"
safe_run check_required_commands "缺少必要的系统命令"

safe_run check_node_installed "未在预期目录检测到可用的 Node.js 或 npm,将安装 Node.js。"
Expand Down