LOG_FILE=/root/postinstall-repos.log
[ -n "@NO_SAVE@" ] && LOG_FILE=/dev/null

exec < /dev/tty3 > /dev/tty3
chvt 3
echo "#########################"
echo "# %post repos           #"
echo "#########################"
(
  _el=@EL_MAJOR@
  case "${_el}" in
  8|9|10)
    # Install BaseOS, AppStream and CRB repos from the installation.
    _baseos=@BASEOS@
    _appstream=@APPSTREAM@
    if [ -z "${_baseos}" ] || [ -z "${_appstream}" ]; then
      echo "##################################################################"
      echo "#    Kickstart snippet skipped. Please make sure the required    #"
      echo "# variables are defined and the required packages are installed. #"
      echo "##################################################################"
      echo
      echo "* Required variables:"
      echo "_baseos(${_baseos})"
      echo "_appstream=(${_appstream})"
    else
      _crb=$(echo "${_baseos}" | sed -e 's/BaseOS/CRB/g')
      cat <<EOF > /etc/yum.repos.d/10mt-repos.repo
[10mt-el@EL_MAJOR@-baseos]
name = 10mt BaseOS repo
baseurl = ${_baseos}
enabled = 1
type = rpm
gpgcheck = 0
skip_if_unavailable = True

[10mt-el@EL_MAJOR@-appstream]
name=10mt AppStream repo
baseurl = ${_appstream}
enabled = 1
type = rpm
gpgcheck = 0
skip_if_unavailable = True

[10mt-el@EL_MAJOR@-crb]
name = 10mt CRB repo
baseurl = ${_crb}
enabled = 1
type = rpm
gpgcheck = 0
skip_if_unavailable = True
EOF
    fi
    ;;
  6|7)
    cat <<EOF > /etc/yum.repos.d/10mt-repos.repo
[10mt-el@EL_MAJOR@-server]
name = 10mt Server repo
baseurl = @COMPOSE@/Server/\$basearch/os/
enabled = 1
type = rpm
gpgcheck = 0
skip_if_unavailable = True
EOF
    ;;
  esac
) 2>&1 | tee "${LOG_FILE}"
chvt 1

# vim:set ts=2 sw=2 et:

