From 07c25024b9f37c85f4c05e2a56b819f1c3443de2 Mon Sep 17 00:00:00 2001 From: huaxin Date: Fri, 27 Nov 2026 00:24:48 -0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=90=8C=E6=AD=A5=E5=B9=B6=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E6=89=93=E5=8C=85=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commit.sh | 3 +++ compress_and_upload_files.sh | 46 ++++++++++++++++++++++++++++++++++-- files_download.txt | 2 +- sync.sh | 4 ++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/commit.sh b/commit.sh index 3746544..e017b7c 100755 --- a/commit.sh +++ b/commit.sh @@ -1,2 +1,5 @@ +#!/bin/bash +set -euo pipefail + ./sync.sh ./compress_and_upload_files.sh \ No newline at end of file diff --git a/compress_and_upload_files.sh b/compress_and_upload_files.sh index ae415ba..c4211ee 100755 --- a/compress_and_upload_files.sh +++ b/compress_and_upload_files.sh @@ -3,10 +3,10 @@ # 压缩并上传files目录到七牛云 # 需要环境变量: QINIU_ACCESS_KEY, QINIU_SECRET_KEY -set -e +set -euo pipefail # 检查环境变量 -if [[ -z "$QINIU_ACCESS_KEY" ]] || [[ -z "$QINIU_SECRET_KEY" ]]; then +if [[ -z "${QINIU_ACCESS_KEY:-}" ]] || [[ -z "${QINIU_SECRET_KEY:-}" ]]; then echo "错误: 请设置环境变量 QINIU_ACCESS_KEY 和 QINIU_SECRET_KEY" exit 1 fi @@ -17,6 +17,48 @@ if [[ ! -d "files" ]]; then exit 1 fi +# 打包前静态校验: 解析 playbooks/site.yml 中所有未注释的 ../files/... 引用并确认本地存在 +PLAYBOOK_PATH="playbooks/site.yml" +if [[ ! -f "$PLAYBOOK_PATH" ]]; then + echo "错误: $PLAYBOOK_PATH 不存在" + exit 1 +fi + +echo "正在校验 $PLAYBOOK_PATH 引用的本地文件完整性..." +REFERENCED_FILES=() +while IFS= read -r ref_path; do + if [[ -n "$ref_path" ]]; then + REFERENCED_FILES+=("$ref_path") + fi +done < <(sed 's/#.*$//' "$PLAYBOOK_PATH" | grep -Eo '\.\./files/[^[:space:]"'\'']+' | sed 's|^\.\./||' | sort -u) + +if [[ ${#REFERENCED_FILES[@]} -eq 0 ]]; then + echo "错误: 未能从 $PLAYBOOK_PATH 解析出任何 ../files/ 引用" + exit 1 +fi + +MISSING_FILES=() +for rel_path in "${REFERENCED_FILES[@]}"; do + if [[ "$rel_path" == */ ]]; then + if [[ ! -d "$rel_path" ]]; then + MISSING_FILES+=("$rel_path") + fi + else + if [[ ! -e "$rel_path" ]]; then + MISSING_FILES+=("$rel_path") + fi + fi +done + +if [[ ${#MISSING_FILES[@]} -gt 0 ]]; then + echo "错误: 以下被 $PLAYBOOK_PATH 引用的文件或目录在本地缺失,已中止打包上传:" + for missing in "${MISSING_FILES[@]}"; do + echo " - $missing" + done + exit 1 +fi +echo "校验通过: 已确认 ${#REFERENCED_FILES[@]} 处 $PLAYBOOK_PATH 活跃引用文件均存在。" + # 生成带时间戳的文件名 TIMESTAMP=$(date +"%Y%m%d_%H%M%S") ARCHIVE_NAME="files_${TIMESTAMP}.tar.xz" diff --git a/files_download.txt b/files_download.txt index f7cf3a8..7f44b6b 100644 --- a/files_download.txt +++ b/files_download.txt @@ -1 +1 @@ -http://xplayer-ota.pureroad.cn/files_20261126_170113.tar.xz +http://xplayer-ota.pureroad.cn/files_20261127_002252.tar.xz diff --git a/sync.sh b/sync.sh index 72c3502..d78dfe9 100755 --- a/sync.sh +++ b/sync.sh @@ -1,3 +1,6 @@ +#!/bin/bash +set -euo pipefail + mkdir -p files rsync am60-ts:/etc/ssh/sshd_config files/sshd_config rsync am60-ts:/root/.ssh/authorized_keys files/authorized_keys @@ -14,6 +17,7 @@ rsync am60-ts:/usr/local/bin/server files/server rsync am60-ts:/usr/bin/ota files/ota rsync -avz am60-ts:/etc/apt/sources.list.d ./files/ rsync am60-ts:/etc/modprobe.d/snd-aloop.conf files/snd-aloop.conf +rsync -avz am60-ts:/etc/modprobe.d/99-snd-usb-audio-index.conf ./files/99-snd-usb-audio-index.conf rsync am60-ts:/etc/systemd/system/camilladsp.service files/camilladsp.service rsync am60-ts:/usr/lib/systemd/system/bluetooth.service files/bluetooth.service rsync am60-ts:/etc/udev/rules.d/99-usb-auto-mount.rules files/99-usb-auto-mount.rules