#!/bin/bash

# 获取国家代码
echo "正在检测服务器地理位置..."
country=$(curl -s https://ipinfo.io/country)

if [ "$country" = "CN" ]; then
    echo "检测到服务器位于中国大陆，使用中科大镜像源..."
    cat > /etc/apt/sources.list << 'EOF'
deb http://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src http://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb http://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src http://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

deb http://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src http://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
EOF

else
    echo "检测到服务器位于国外，使用 Debian 官方源..."
    cat > /etc/apt/sources.list << 'EOF'
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware

deb http://deb.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware

deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
EOF
fi

# 更新系统
echo "正在更新软件源与系统..."
apt update
apt upgrade -y
apt full-upgrade -y
apt dist-upgrade -y

# 显示系统版本信息
echo "系统信息如下："
cat /etc/os-release
