Files
script/nginx/note.sugarscat.cn/deploy.sh
40e62f975b refactor: 将目录结构从 www 重命名为 nginx
- 将 default、git、note 目录下的 README.md 文件从 www目录移动到 nginx 目录
- 更新文件内容中的下载路径,从 www 改为 nginx- 修改 note 目录下的 deploy.sh 脚本执行路径
2025-03-15 19:47:07 +08:00

54 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 开启严格模式
set -e
# 定义变量
REPO_URL="https://git.sugarscat.cn/me/note"
TARGET_DIR="/var/www/note"
DIST_DIR=".vitepress/dist"
TEMP_DIR=$(mktemp -d) # 生成临时目录
# 清理临时目录的函数(在脚本退出时执行)
cleanup() {
rm -rf "$TEMP_DIR"
}
trap cleanup EXIT
echo "开始下载最新构建产物..."
curl -L -o "$TEMP_DIR/artifact.zip" "$REPO_URL/-/jobs/artifacts/main/download?job=build"
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "下载失败,请检查网络连接或重新尝试。"
exit 1
fi
# 检查 unzip 是否可用,不可用时自动安装
if ! command -v unzip &> /dev/null; then
echo "unzip 未安装,开始安装 ···"
if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y unzip
elif command -v yum &> /dev/null; then
sudo yum install -y unzip
else
echo "无法安装 unzip请手动安装。"
exit 1
fi
fi
echo "解压文件..."
unzip -q "$TEMP_DIR/artifact.zip" -d "$TEMP_DIR"
# 确保目标目录存在
sudo mkdir -p "$TARGET_DIR"
echo "清空目标目录..."
sudo rm -rf "$TARGET_DIR"/*
echo "移动文件到目标目录..."
sudo mv "$TEMP_DIR/$DIST_DIR"/* "$TARGET_DIR"
echo "部署完成!"