perf(host-init): skip APT refresh when baseline packages are installed
This commit is contained in:
@@ -29,6 +29,8 @@ curl -fsSL 'https://scripts.example.com/releases/<40位小写Git提交>/install.
|
|||||||
Docker、Headscale、公钥注入和安全配置后续由 Komodo 任务处理。没有 Core API 凭据下发。
|
Docker、Headscale、公钥注入和安全配置后续由 Komodo 任务处理。没有 Core API 凭据下发。
|
||||||
已有身份、配置或二进制不符时停止,不自动替换身份。源文件可直接 bash install.sh --help。
|
已有身份、配置或二进制不符时停止,不自动替换身份。源文件可直接 bash install.sh --help。
|
||||||
|
|
||||||
|
`host-init.sh` 先检查基础包安装状态,仅在缺包时更新 APT 索引并补齐缺失包;已有完整基线的重跑不会无条件访问软件源。Docker 固定包仍须在执行前准备,构建与资源导入单独计时。
|
||||||
|
|
||||||
## Headscale 接入
|
## Headscale 接入
|
||||||
|
|
||||||
`tailscale.sh` 使用显式版本、已准备的本地 DEB、SHA-256、HTTPS 控制端和节点名称。首次接入还需 root 所有、0600 权限的短期单次授权 key 文件;执行后清除临时 key 文件。既有 Running 节点直接复核身份,不需要新 key。
|
`tailscale.sh` 使用显式版本、已准备的本地 DEB、SHA-256、HTTPS 控制端和节点名称。首次接入还需 root 所有、0600 权限的短期单次授权 key 文件;执行后清除临时 key 文件。既有 Running 节点直接复核身份,不需要新 key。
|
||||||
|
|||||||
17
host-init.sh
17
host-init.sh
@@ -3,6 +3,20 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
export LC_ALL=C
|
export LC_ALL=C
|
||||||
fail() { printf 'ERROR: %s\n' "$*" >&2; return 1; }
|
fail() { printf 'ERROR: %s\n' "$*" >&2; return 1; }
|
||||||
|
ensure_baseline_packages() {
|
||||||
|
local package missing=()
|
||||||
|
for package in ca-certificates curl jq git openssl openssh-client iproute2; do
|
||||||
|
if [[ $(dpkg-query -W -f='${db:Status-Status}' "$package" 2>/dev/null) != installed ]]; then
|
||||||
|
missing+=("$package")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if ((${#missing[@]})); then
|
||||||
|
apt-get -o DPkg::Lock::Timeout=60 update
|
||||||
|
apt-get -o DPkg::Lock::Timeout=60 install -y --no-install-recommends "${missing[@]}"
|
||||||
|
else
|
||||||
|
echo 'Baseline packages already installed; APT refresh skipped.'
|
||||||
|
fi
|
||||||
|
}
|
||||||
check_existing_binding() {
|
check_existing_binding() {
|
||||||
local state_dir=$1 expected=$2 bound=''
|
local state_dir=$1 expected=$2 bound=''
|
||||||
local binding="$state_dir/binding"
|
local binding="$state_dir/binding"
|
||||||
@@ -59,8 +73,7 @@ main() {
|
|||||||
umask 077
|
umask 077
|
||||||
exec 9>>/run/lock/platform-host-init.lock; flock -n 9 || { fail 'Host initialization is already running'; return 1; }
|
exec 9>>/run/lock/platform-host-init.lock; flock -n 9 || { fail 'Host initialization is already running'; return 1; }
|
||||||
check_existing_binding /var/lib/platform-bootstrap "$name"
|
check_existing_binding /var/lib/platform-bootstrap "$name"
|
||||||
apt-get -o DPkg::Lock::Timeout=60 update
|
ensure_baseline_packages
|
||||||
apt-get -o DPkg::Lock::Timeout=60 install -y --no-install-recommends ca-certificates curl jq git openssl openssh-client iproute2
|
|
||||||
if ((${#debs[@]})); then apt-get -o DPkg::Lock::Timeout=60 install -y "${debs[@]}"; fi
|
if ((${#debs[@]})); then apt-get -o DPkg::Lock::Timeout=60 install -y "${debs[@]}"; fi
|
||||||
hostnamectl set-hostname "$name"
|
hostnamectl set-hostname "$name"
|
||||||
if [[ -n "$public_key" ]]; then
|
if [[ -n "$public_key" ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user