From 7afc468082718eb20db903b99cf800de64844486 Mon Sep 17 00:00:00 2001
From: Pierre Boutillier <pierre.boutillier@ens-lyon.org>
Date: Wed, 27 Jun 2018 23:49:57 +0200
Subject: [PATCH] Opam: fixup required opam_version

---
 scripts/ci/create_docker_image.opam.sh         |  2 +-
 .../ci/create_opam_repository.tezos_deps.sh    | 18 ++++++++++++------
 scripts/version.sh                             |  2 +-
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/scripts/ci/create_docker_image.opam.sh b/scripts/ci/create_docker_image.opam.sh
index 2273ffeeb..011408bf6 100755
--- a/scripts/ci/create_docker_image.opam.sh
+++ b/scripts/ci/create_docker_image.opam.sh
@@ -79,7 +79,7 @@ RUN mkdir ~/.ssh && \
 
 RUN opam install --switch=/home/opam/tezos --yes opam-depext
 
-ENTRYPOINT [ "opam", "exec", "--" ]
+ENTRYPOINT [ "opam", "exec", "--set-switch", "--switch=/home/opam/tezos", "--" ]
 CMD [ "/bin/bash" ]
 EOF
 
diff --git a/scripts/ci/create_opam_repository.tezos_deps.sh b/scripts/ci/create_opam_repository.tezos_deps.sh
index 162b1d8eb..a49e8cebc 100755
--- a/scripts/ci/create_opam_repository.tezos_deps.sh
+++ b/scripts/ci/create_opam_repository.tezos_deps.sh
@@ -50,9 +50,15 @@ done
 # inline some of the test and doc dependencies.
 extra_packages="depext alcotest-lwt ocp-indent odoc ounit crowbar"
 
-git clone $opam_repository_url "$tmp_dir/opam-repository-master"
-git -C "$tmp_dir"/opam-repository-master reset --hard $opam_repository_tag
-rm -rf "$tmp_dir"/opam-repository-master/.git
+if ! [ -f "$build_dir"/opam-repository-$opam_repository_tag.tar.gz ]; then
+    echo
+    echo "### Fetching opam-repository-$opam_repository_tag.tar.gz ..."
+    echo
+    mkdir -p "$build_dir"
+    wget -O "$build_dir"/opam-repository-$opam_repository_tag.tgz \
+         https://gitlab.com/tezos/opam-repository/-/archive/$opam_repository_tag/opam-repository-$opam_repository_tag.tar.gz
+fi
+tar -C "$tmp_dir" -xzf "$build_dir"/opam-repository-$opam_repository_tag.tgz
 
 ## HACK: Once opam2 is released, we should use the `ocaml/opam` image
 ## instead of this custom installation of ocaml and opam.
@@ -67,15 +73,15 @@ echo
 cat <<EOF > "$tmp_dir"/Dockerfile
 FROM alpine:3.7
 ENV PACKAGER "Tezos <ci@tezos.com>"
-COPY opam-repository-master opam-repository-master
+COPY opam-repository-$opam_repository_tag opam-repository-$opam_repository_tag
 COPY opam /usr/local/bin/opam
 RUN apk add --no-cache ocaml build-base m4 tar xz bzip2 curl perl rsync
-RUN opam init --disable-sandboxing --no-setup --yes default ./opam-repository-master
+RUN opam init --disable-sandboxing --no-setup --yes default ./opam-repository-$opam_repository_tag
 RUN opam install --yes opam-bundle
 COPY opam-repository-tezos opam-repository-tezos
 RUN opam bundle --yes --output="tezos_bundle-$ocaml_version-$opam_repository_tag" \
                 --repository=opam-repository-tezos \
-                --repository=opam-repository-master \
+                --repository=opam-repository-$opam_repository_tag \
                 --ocaml=$ocaml_version \
                 $packages $extra_packages
 EOF
diff --git a/scripts/version.sh b/scripts/version.sh
index 3f105306a..9e6e1f6fd 100644
--- a/scripts/version.sh
+++ b/scripts/version.sh
@@ -6,7 +6,7 @@
 alpine_version=3.6
 ocaml_version=4.06.1
 hidapi_version=0.8.0_rc1
-opam_version=2.0.0~rc
+opam_version=2.0.0~rc3
 opam_tag=2.0.0-rc3
 opam_repository_tag=7db0db5dc53de44d1a0190b1310aa225e04df9ef
 opam_repository_url=https://gitlab.com/tezos/opam-repository.git