#!/bin/sh

ALT_COMMON_REPO_PATH="/etc/apt/sources.list.d/alt-common-els.list"

create_alt_common_repo() {
    OS_CODENAME=$(grep '^VERSION_CODENAME=' /etc/os-release | cut -d'=' -f2 | sed -e 's@"@@g')
    OS_VER=$(grep '^VERSION_ID=' /etc/os-release | cut -d'=' -f2 | sed -e 's@"@@g')
    OS_NAME=$(grep '^ID=' /etc/os-release | cut -d'=' -f2 | sed -e 's@"@@g')

    mkdir -p "$(dirname "$ALT_COMMON_REPO_PATH")"

    cat <<EOF > "$ALT_COMMON_REPO_PATH"
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb [arch=amd64] https://repo.alt.tuxcare.com/alt-common/deb/${OS_NAME}/${OS_VER}/stable ${OS_CODENAME} main
EOF

    chmod 644 "$ALT_COMMON_REPO_PATH"
}

create_alt_common_repo