#!/bin/bash

# 获取操作系统的 ID
distro_id=$(grep -w ID /etc/os-release | cut -d= -f2 | tr -d '"')

# 定义 repo 文件路径
repo_file_path="/etc/yum.repos.d/idste-AppStream.repo"

# 生成 repo 文件
echo "Creating repo file at $repo_file_path..."
cat <<EOF | sudo tee "$repo_file_path" > /dev/null
[IDsteAppStream]
name=IDste Group Server - AppStream
baseurl=http://mirrors.idste.org/rpm/$distro_id/\$releasever/\$basearch
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ANOLIS
gpgcheck=0

[IDsteCommonStream]
name=IDste Group Server - AppStream
baseurl=http://mirrors.idste.org/rpm/common/\$basearch
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ANOLIS
gpgcheck=0
EOF

# 检查生成的文件内容
echo "Repo file content:"
cat "$repo_file_path"

# 更新缓存
echo "Cleaning and updating cache..."
sudo yum clean all
sudo yum makecache

echo "Repo file created and cache refreshed."
