Files
claw/scripts/secure-updates@tx-ubuntu-ubuntu.sh
fukunee 30918f4642 Add Nginx deny config and server hardening scripts
Add new nginx/deny.conf to block unmatched hosts and explicitly close
fukun.net. Remove Photoview icon hijacking, add client_max_body_size.

Add scripts for deep inspection, disk monitoring, firewall setup,
Gitea port confinement, and security updates.
2026-05-28 10:51:36 +08:00

78 lines
2.2 KiB
Bash

#!/usr/bin/env bash
# ============================================================
# secure-updates@tx-ubuntu-ubuntu.sh
# 安装安全更新,升级后验证关键服务
# ============================================================
set -e
C_YELLOW='\033[1;33m'
C_GREEN='\033[1;32m'
C_RED='\033[1;31m'
C_CYAN='\033[1;36m'
C_RESET='\033[0m'
section() { echo -e "\n${C_CYAN}━━━ $1 ━━━${C_RESET}"; }
ok() { echo -e " ${C_GREEN}✓${C_RESET} $1"; }
warn() { echo -e " ${C_YELLOW}⚠${C_RESET} $1"; }
bad() { echo -e " ${C_RED}✗${C_RESET} $1"; }
section "1. 刷新包列表"
sudo apt update -qq 2>&1 | tail -1
ok "apt update 完成"
section "2. 安全更新列表"
echo " 待升级安全包:"
sudo apt list --upgradable 2>/dev/null | grep -i security
echo ""
echo " 全部可升级包数量: $(sudo apt list --upgradable 2>/dev/null | tail -n +2 | wc -l)"
section "3. 安装安全更新"
# 仅升级与安全公告相关的包(不加 --dist-upgrade,避免大范围变更)
sudo apt-get install -y --only-upgrade \
bind9-dnsutils \
bind9-host \
bind9-libs \
libarchive13t64 \
libgnutls30t64 2>&1 | grep -E '(Setting up|upgraded|newly installed)' || true
ok "安全包升级完成"
section "4. 验证关键服务"
check_svc() {
if systemctl is-active --quiet $1 2>/dev/null; then
ok "$1: active"
else
bad "$1: 未运行!"
fi
}
check_svc nginx
check_svc docker
check_svc gitea
check_svc fail2ban
echo ""
echo " 探活:"
for url in http://localhost:80 http://localhost:8080 http://localhost:8000 https://git.fukun.net; do
code=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 3 "$url" 2>/dev/null || echo "000")
if [ "$code" = "200" ] || [ "$code" = "301" ] || [ "$code" = "302" ]; then
ok "$url → $code"
else
bad "$url → $code"
fi
done
# Docker 容器
echo ""
if sudo docker ps --format '{{.Names}} {{.Status}}' 2>/dev/null | grep -q vaultwarden; then
ok "vaultwarden 容器运行中"
else
bad "vaultwarden 容器异常"
fi
section "5. 升级后状态"
echo " 剩余可升级包: $(sudo apt list --upgradable 2>/dev/null | tail -n +2 | wc -l)"
echo ""
echo -e "${C_GREEN}===== 安全更新完成 =====${C_RESET}"