Files
PropertyDeployment/domain-name/init.sh
2025-12-09 20:22:03 +08:00

62 lines
1.6 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
ENV_FILE=".env"
MAIN_COMPOSE_FILE="docker-compose.yml"
# 检查 .env 文件
if [ ! -f "$ENV_FILE" ]; then
echo "错误:当前目录下未找到 $ENV_FILE 文件。"
exit 1
fi
echo "正在从 $ENV_FILE 读取环境变量..."
SSL_USE=$(grep -v '^$' "$ENV_FILE" | grep -v '^#' | grep '^SSL_USE=' | sed 's/^SSL_USE=//' | sed 's/["'\''"]//g')
if [ -z "$SSL_USE" ]; then
echo "错误:未找到有效的 SSL_USE 配置。"
exit 1
fi
echo "成功读取 SSL_USE: $SSL_USE"
# 创建宿主机目录
if [ ! -d "$SSL_USE" ]; then
echo "宿主机目录 $SSL_USE 不存在,正在创建..."
mkdir -p "$SSL_USE" || { echo "错误:无法创建目录,请检查权限。"; exit 1; }
fi
echo "正在创建 volumes 子目录..."
mkdir -p \
"${SSL_USE}/certbot-www" \
"${SSL_USE}/certbot-conf" \
"${SSL_USE}/apply-nginx-log" \
"${SSL_USE}/proxy-nginx-log"
echo "🎉 所有 volumes 子目录创建完成!"
# 是否赋权
read -p "是否需要为目录 $SSL_USE 及其子目录赋予当前用户权限?(y/n, 默认: y): " response
response=${response:-y}
if [[ "$response" =~ ^[Yy]$ ]]; then
echo "正在赋予权限..."
sudo chown -R "$(whoami):$(whoami)" "$SSL_USE"
echo "✅ 权限调整完成!"
else
echo " 已跳过权限调整。"
fi
# 启动主 docker-compose
if [ ! -f "$MAIN_COMPOSE_FILE" ]; then
echo "⚠️ 警告:未找到 $MAIN_COMPOSE_FILE,跳过启动步骤。"
else
echo "正在执行docker-compose -f $MAIN_COMPOSE_FILE up -d"
docker-compose -f "$MAIN_COMPOSE_FILE" up -d
echo "🚀 主服务已启动!"
fi
echo -e "\n🎉 所有操作已完成。"