Skip to content

Commit 98c3084

Browse files
committed
fix: 添加Nginx和htpasswd的安装检查
在启用配置前检查系统是否已安装Nginx和htpasswd工具 当未安装时显示清晰的错误信息和各发行版的安装命令 避免在缺少依赖的情况下继续执行导致失败
1 parent 90ae9ed commit 98c3084

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

config/nginx/enableNginxConf.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ $ErrorActionPreference = 'Stop'
5050
$modulePath = Join-Path $PSScriptRoot 'Manage-NginxConf.psm1'
5151
Import-Module $modulePath -Force
5252

53+
# Check prerequisites
54+
if (-not (Get-Command nginx -ErrorAction SilentlyContinue)) {
55+
Write-Error "错误: 未检测到 Nginx。此脚本需要 Nginx 才能运行。"
56+
Write-Host "请根据您的发行版安装 Nginx:" -ForegroundColor Cyan
57+
Write-Host " Debian/Ubuntu: sudo apt update && sudo apt install -y nginx"
58+
Write-Host " RHEL/CentOS: sudo yum install -y nginx"
59+
Write-Host " Fedora: sudo dnf install -y nginx"
60+
Write-Host " Arch Linux: sudo pacman -Syu nginx"
61+
exit 1
62+
}
63+
64+
if ($BasicUser -and -not (Get-Command htpasswd -ErrorAction SilentlyContinue)) {
65+
Write-Error "错误: 未检测到 htpasswd 工具。Basic Auth 配置需要此工具。"
66+
Write-Host "请根据您的发行版安装工具包:" -ForegroundColor Cyan
67+
Write-Host " Debian/Ubuntu: sudo apt install -y apache2-utils"
68+
Write-Host " RHEL/CentOS: sudo yum install -y httpd-tools"
69+
Write-Host " Fedora: sudo dnf install -y httpd-tools"
70+
Write-Host " Arch Linux: sudo pacman -S apache"
71+
exit 1
72+
}
73+
5374
Write-Output "即将启用配置: $Name"
5475
if (-not $RepoConfPath) {
5576
$RepoConfPath = Join-Path (Join-Path $PSScriptRoot 'sites-available') ("$Name.conf")

0 commit comments

Comments
 (0)