#!/bin/bash
# exnkvers功能: 生成 /etc/os-release-advance 文件

SRC_FILE="/etc/os-release"
TARGET_FILE="/etc/os-release-advance"

# 检查是否为 root 用户
if [ "$EUID" -ne 0 ]; then
    echo "exnkvers must be run as root." >&2
    exit 1
fi

# 检查源文件是否存在
if [ ! -f "$SRC_FILE" ]; then
    echo "Error: $SRC_FILE does not exist." >&2
    exit 1
fi

# 如果目标文件已存在，警告并继续覆盖
if [ -f "$TARGET_FILE" ]; then
    echo "Warning: $TARGET_FILE already exists and will be overwritten." >&2
fi

# 写入新的 os-release-advance 文件
cat > "$TARGET_FILE" <<EOF
NAME="Kylin Linux Advanced Server"
VERSION="V11 (swan26)"
ID="kylin"
VERSION_ID="11.1"
PRETTY_NAME="Kylin Linux Advanced Server V11 SP1 2603"
ANSI_COLOR="0;31"
HOME_URL="https://www.kylinos.cn/"
EOF

# 复制源文件的权限和属主
chmod --reference="$SRC_FILE" "$TARGET_FILE"
chown --reference="$SRC_FILE" "$TARGET_FILE"

echo "Successfully generated $TARGET_FILE"
exit 0
