feat(deploy): register nx globally via install-nx-cli.sh

Centralize chmod and /usr/local/bin symlinks; install, upgrade, update, and every nx invocation refresh the global nx command.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nexus Deploy
2026-06-06 04:43:00 +08:00
parent 0a7c5ee617
commit 646929ddff
8 changed files with 104 additions and 45 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ curl -fsSL "http://66.154.115.8:3000/admin/Nexus/raw/branch/main/deploy/quick-in
## NX 统一运维菜单
装好后在服务器输入 **`nx`**安装脚本会链到 `/usr/local/bin/nx`):
装好后在服务器任意目录输入 **`nx`**`install` / `update` / 首次运行 `nx` 会自动注册 `/usr/local/bin/nx`):
```bash
nx # 统一菜单:安装 + 一键更新 + 重启 + 日志 + 备份
+7 -2
View File
@@ -69,10 +69,15 @@ curl -fsSL ".../update.sh" | bash -s -- --no-cache
---
## NX 统一菜单
## NX 全局命令
安装 / 升级 / 首次运行 `nx` 会自动注册到 `/usr/local/bin`
```bash
nx # 安装 + 一键更新 + 重启 + 日志 + 备份(原「上帝菜单」已合并
# 手动注册(任意目录可用 nx
NEXUS_ROOT=/opt/nexus bash /opt/nexus/deploy/install-nx-cli.sh
nx # 统一运维菜单
nexus-update # 等同 update.sh
nexus-fresh # 等同 install-nexus-fresh.sh
nexus-install # 等同 quick-install.sh
+2 -20
View File
@@ -120,26 +120,8 @@ load_credentials() {
install_root_commands() {
[[ -d "${NEXUS_ROOT}/deploy" ]] || return 0
chmod +x "${NEXUS_ROOT}/deploy/nx" \
"${NEXUS_ROOT}/deploy/install-nexus-fresh.sh" \
"${NEXUS_ROOT}/deploy/nexus-1panel.sh" \
"${NEXUS_ROOT}/deploy/sync-install-wizard-to-container.sh" \
"${NEXUS_ROOT}/deploy/uninstall-redis-compose.sh" \
"${NEXUS_ROOT}/deploy/uninstall-mysql-compose.sh" \
"${NEXUS_ROOT}/deploy/update.sh" 2>/dev/null || true
ln -sf "${NEXUS_ROOT}/deploy/nx" /usr/local/bin/nx
ln -sf "${NEXUS_ROOT}/deploy/nexus-1panel.sh" /usr/local/bin/nexus-1panel
ln -sf "${NEXUS_ROOT}/deploy/install-nexus-fresh.sh" /usr/local/bin/nexus-fresh
ln -sf "${NEXUS_ROOT}/deploy/quick-install.sh" /usr/local/bin/nexus-install
ln -sf "${NEXUS_ROOT}/deploy/update.sh" /usr/local/bin/nexus-update
ln -sf "${NEXUS_ROOT}/deploy/install-1panel-docker.sh" /usr/local/bin/nexus-1panel-docker 2>/dev/null || true
info "已注册全局命令(root 直接输入即可):"
info " nexus-1panel-docker — 重装服务器(1Panel + Docker + Nexus"
info " nexus-install — 仅 Nexus Dockercurl 入口)"
info " nexus-1panel — 底层 install/upgrade 脚本"
info " nx — 统一运维菜单(安装 + 一键更新 + 重启)"
info " nexus-fresh — 全新安装脚本"
info " nexus-update — 一键更新(pull + 重建镜像)"
NEXUS_ROOT="$NEXUS_ROOT" bash "${NEXUS_ROOT}/deploy/install-nx-cli.sh" || true
info "全局命令: nx · nexus-update · nexus-fresh · nexus-install · nexus-1panel"
}
phase_preflight() {
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# 注册 Nexus 全局 CLI/usr/local/bin)— install / upgrade / nx 均会调用
#
# NEXUS_ROOT=/opt/nexus bash deploy/install-nx-cli.sh
#
set -euo pipefail
NEXUS_ROOT="${NEXUS_ROOT:-/opt/nexus}"
BIN_DIR="${NEXUS_BIN_DIR:-/usr/local/bin}"
DEPLOY="${NEXUS_ROOT}/deploy"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
if [[ ! -d "$DEPLOY" ]]; then
error "未找到 $DEPLOY"
exit 1
fi
if [[ "$(id -u)" -ne 0 ]]; then
warn "非 root:无法写入 $BIN_DIR,请使用 root 执行或: sudo bash $DEPLOY/install-nx-cli.sh"
exit 0
fi
chmod +x \
"$DEPLOY/nx" \
"$DEPLOY/update.sh" \
"$DEPLOY/nexus-1panel.sh" \
"$DEPLOY/install-nexus-fresh.sh" \
"$DEPLOY/quick-install.sh" \
"$DEPLOY/install-1panel-docker.sh" \
"$DEPLOY/upgrade-1panel-docker.sh" \
"$DEPLOY/sync-install-wizard-to-container.sh" \
"$DEPLOY/uninstall-mysql-compose.sh" \
"$DEPLOY/uninstall-redis-compose.sh" \
"$DEPLOY/install-nx-cli.sh" \
2>/dev/null || true
mkdir -p "$BIN_DIR"
link_cli() {
local src="$1" name="$2"
if [[ ! -f "$src" ]]; then
warn "跳过 $name(缺少 $src"
return 0
fi
ln -sf "$src" "${BIN_DIR}/${name}"
}
link_cli "$DEPLOY/nx" nx
link_cli "$DEPLOY/update.sh" nexus-update
link_cli "$DEPLOY/install-nexus-fresh.sh" nexus-fresh
link_cli "$DEPLOY/quick-install.sh" nexus-install
link_cli "$DEPLOY/nexus-1panel.sh" nexus-1panel
link_cli "$DEPLOY/install-1panel-docker.sh" nexus-1panel-docker
if command -v nx >/dev/null 2>&1; then
info "全局命令已就绪: nx → $(readlink -f "$(command -v nx)" 2>/dev/null || command -v nx)"
else
error "nx 未出现在 PATH 中,请确认 $BIN_DIR 在 PATH 内"
exit 1
fi
+4 -2
View File
@@ -608,8 +608,8 @@ verify_health() {
info "浏览器: https://${NEXUS_DOMAIN}/app/"
fi
echo ""
info "运维菜单: nx 或 bash $root/deploy/update.sh"
info " (安装 nx 命令: ln -sf $root/deploy/nx /usr/local/bin/nx)"
NEXUS_ROOT="$root" bash "$root/deploy/install-nx-cli.sh" 2>/dev/null || true
info "运维菜单: nx 或 nexus-update"
check_ports_post "$root"
return 0
fi
@@ -751,6 +751,7 @@ cmd_install() {
ensure_docker
check_ports_preflight "$NEXUS_ROOT"
clone_or_pull
NEXUS_ROOT="$NEXUS_ROOT" bash "$NEXUS_ROOT/deploy/install-nx-cli.sh" 2>/dev/null || true
write_env_prod "$NEXUS_ROOT"
compose_up "$NEXUS_ROOT"
verify_health "$NEXUS_ROOT" "安装"
@@ -808,6 +809,7 @@ cmd_upgrade() {
if [[ "$PRUNE_IMAGES" == true ]]; then
docker image prune -f >/dev/null 2>&1 || true
fi
NEXUS_ROOT="$NEXUS_ROOT" bash "$NEXUS_ROOT/deploy/install-nx-cli.sh" 2>/dev/null || true
verify_health "$NEXUS_ROOT" "升级"
}
+3 -6
View File
@@ -50,12 +50,8 @@ detect_runtime() {
}
install_nx_cli() {
if [[ "$(id -u)" -ne 0 ]]; then
return 0
fi
ln -sf "${NX_DIR}/nx" /usr/local/bin/nx 2>/dev/null || true
ln -sf "${NX_DIR}/update.sh" /usr/local/bin/nexus-update 2>/dev/null || true
chmod +x "${NX_DIR}/nx" "${NX_DIR}/update.sh" 2>/dev/null || true
NEXUS_ROOT="$(cd "${NX_DIR}/.." && pwd)" \
bash "${NX_DIR}/install-nx-cli.sh" 2>/dev/null || true
}
menu_header() {
@@ -350,6 +346,7 @@ EOF
nx_main() {
local sub="${1:-}"
install_nx_cli
load_secrets
case "$sub" in
""|menu|god|ops|admin)
+1 -14
View File
@@ -11,18 +11,5 @@
set -euo pipefail
ROOT="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)"
ensure_cli_executable() {
chmod +x \
"$ROOT/deploy/nx" \
"$ROOT/deploy/update.sh" \
"$ROOT/deploy/nexus-1panel.sh" \
"$ROOT/deploy/install-nexus-fresh.sh" \
2>/dev/null || true
if [[ "$(id -u)" -eq 0 ]]; then
ln -sf "$ROOT/deploy/nx" /usr/local/bin/nx
ln -sf "$ROOT/deploy/update.sh" /usr/local/bin/nexus-update
fi
}
ensure_cli_executable
NEXUS_ROOT="$ROOT" bash "$ROOT/deploy/install-nx-cli.sh" 2>/dev/null || true
exec bash "$ROOT/deploy/nexus-1panel.sh" upgrade "$@"
@@ -0,0 +1,18 @@
# 2026-06-05 — nx 全局 CLI 注册
## 摘要
新增 `deploy/install-nx-cli.sh`,统一 `chmod +x``/usr/local/bin` 符号链接;`install``update``upgrade`、首次 `nx` 均自动调用,确保 `nx` 全局可用。
## 涉及文件
- `deploy/install-nx-cli.sh`(新)
- `deploy/nx``deploy/update.sh``deploy/nexus-1panel.sh``deploy/install-nexus-fresh.sh`
## 服务器
```bash
cd /opt/nexus && git pull
bash deploy/install-nx-cli.sh
which nx && nx --help
```