Support optional Ubuntu system bootstrap

This commit is contained in:
武阳
2026-05-07 12:05:41 +08:00
parent fd70af4d56
commit d42e024ccd
3 changed files with 69 additions and 3 deletions
+27 -1
View File
@@ -14,15 +14,18 @@ USER_SYSTEMD_DIR="${HOME}/.config/systemd/user"
BRANCH=""
FORCE=0
SKIP_GIT=0
BOOTSTRAP_SYSTEM=0
usage() {
cat <<EOF
Usage: bash scripts/deploy-ubuntu.sh [branch] [--force] [--skip-git]
Usage: bash scripts/deploy-ubuntu.sh [branch] [--force] [--skip-git] [--bootstrap-system]
Options:
branch 要部署的 git 分支;不传则使用当前分支
--force 使用 git reset --hard origin/<branch> 覆盖本地改动
--skip-git 跳过 git 拉取,只部署当前工作区
--bootstrap-system
首次安装时使用 sudo 安装 Ubuntu 系统依赖,应用仍部署在用户目录
EOF
}
@@ -36,6 +39,10 @@ while [[ $# -gt 0 ]]; do
SKIP_GIT=1
shift
;;
--bootstrap-system)
BOOTSTRAP_SYSTEM=1
shift
;;
-h|--help)
usage
exit 0
@@ -73,6 +80,24 @@ require_command() {
fi
}
bootstrap_system_packages() {
if [[ "${BOOTSTRAP_SYSTEM}" != "1" ]]; then
return
fi
require_command sudo "首次安装系统依赖需要 sudo。"
if ! command -v apt-get >/dev/null 2>&1; then
warn "未发现 apt-get,跳过系统依赖安装。请手工安装 git、curl、pyenv、Node.js、npm 和 Python 编译依赖。"
return
fi
log "首次初始化 Ubuntu 系统依赖"
sudo apt-get update
sudo apt-get install -y \
git curl ca-certificates build-essential \
libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \
libffi-dev liblzma-dev libncursesw5-dev xz-utils tk-dev \
systemd
}
prompt_value() {
local var_name="$1"
local prompt="$2"
@@ -260,6 +285,7 @@ health_check() {
main() {
log "ZK Data Agent Ubuntu 部署"
bootstrap_system_packages
update_git
ensure_env_file
ensure_python
+11 -2
View File
@@ -7,10 +7,11 @@ REPO="${REPO:-git@git.n.xiaomi.com:wuyang6/zk-data-agent.git}"
BRANCH="${BRANCH:-main}"
APP_DIR="${APP_DIR:-${HOME}/zk-data-agent}"
FORCE=0
BOOTSTRAP_SYSTEM="${BOOTSTRAP_SYSTEM:-0}"
usage() {
cat <<EOF
Usage: bash install-from-git.sh [--repo REPO] [--branch BRANCH] [--dir APP_DIR] [--force]
Usage: bash install-from-git.sh [--repo REPO] [--branch BRANCH] [--dir APP_DIR] [--force] [--bootstrap-system]
EOF
}
@@ -32,6 +33,10 @@ while [[ $# -gt 0 ]]; do
FORCE=1
shift
;;
--bootstrap-system)
BOOTSTRAP_SYSTEM=1
shift
;;
-h|--help)
usage
exit 0
@@ -63,4 +68,8 @@ else
cd "${APP_DIR}"
fi
bash scripts/deploy-ubuntu.sh "${BRANCH}" --skip-git
deploy_args=("${BRANCH}" "--skip-git")
if [[ "${BOOTSTRAP_SYSTEM}" == "1" ]]; then
deploy_args+=("--bootstrap-system")
fi
bash scripts/deploy-ubuntu.sh "${deploy_args[@]}"