#!/bin/bash
# -----------------------------------------------------------------------------
# Add openSUSE science repository
#
# Copyright (C) 2021-2023 OpenCFD Ltd.
# SPDX-License-Identifier: (GPL-3.0+)
#
# Usage
#     curl -s https://dl.openfoam.com/add-science-repo.sh | sudo bash
#     wget -q -O - https://dl.openfoam.com/add-science-repo.sh | sudo bash
# -----------------------------------------------------------------------------
# Repo locations:
# - 15.4/
# - openSUSE_Leap_15.3/
# - openSUSE_Leap_Tumbleweed/
# - SLE_15_SP3/
#
# Repo name, location
repo_name="science"
zypp_repo_file="/etc/zypp/repos.d/${repo_name}.repo"
repo_url='http://download.opensuse.org/repositories/science/$releasever/'

# Older name
repo_url0='http://download.opensuse.org/repositories/science/openSUSE_Leap_$releasever/'

if [ -f "/etc/os-release" ]
then
    . /etc/os-release || true
    case "$CPE_NAME" in
    (*leap:15.3 | *tumbleweed*)
        repo_url="$repo_url0"
    ;;
    esac
fi

if [ -f "$zypp_repo_file" ]
then
    echo "The '$repo_name' repo already exists - no need to add."
else
    zypper -n addrepo --refresh --gpgcheck $repo_url "$repo_name"
fi

# Update
echo -n "Running zypper refresh ${repo_name}... "
zypper -n --gpg-auto-import-keys refresh "$repo_name"

echo "$zypp_repo_file"
echo
echo "The repository is setup! You can now install packages."

# ---------------------------------------------------------------------------
