# This file is part of BOINC.
# http://boinc.berkeley.edu
# Copyright (C) 2023 University of California
#
# BOINC is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# BOINC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with BOINC.  If not, see <http://www.gnu.org/licenses/>.

# example build usage:
# LINUX: export BUILDKIT_PROGRESS=plain
# WINDOWS: set BUILDKIT_PROGRESS=plain
# docker build -t jammy-boinc --build-arg PACKAGE=boinc-linux-client --build-arg VERSION=1.0.0-1 -f ./Dockerfile .

ARG DISTRO=opensuse/leap
ARG RELEASE=15.5

FROM $DISTRO:$RELEASE

# All args are cleared after a FROM instruction
ARG RELEASE=15.5

ARG REPOBASE=https://boinc.berkeley.edu/dl/linux
ARG REPOTYPE=stable
ARG PACKAGE=boinc-linux-client
ARG VERSION=7.23.0-1
ARG REPOKEY=boinc.gpg

USER root

WORKDIR /root

RUN bash -c 'zypper -n update && zypper install -y wget expect'

RUN printf '#!/bin/bash -xe \n\
cd /etc/zypp/repos.d \n\
VARIANT=$(echo $RELEASE | sed -e "s|\.|_|\") \n\
wget $REPOBASE/$REPOTYPE/suse$VARIANT/boinc-${REPOTYPE}-suse${VARIANT}.repo \n\
' > update.sh

RUN bash -c 'cat update.sh'

RUN bash -x update.sh

RUN bash -c 'expect -c 'spawn zypper --gpg-auto-import-keys update; expect "Continue? [yes/no] (no)"; send "yes\r"; interact'

RUN bash -c 'zypper search -v $PACKAGE'

RUN bash -c 'zypper -y install $PACKAGE=$VERSION'
