From 978953baa51967fc570727be5218abeaeea485be Mon Sep 17 00:00:00 2001
From: Jorge Camarero Vera <jorge.camarero@cern.ch>
Date: Fri, 21 Apr 2023 17:58:50 +0200
Subject: [PATCH] Replacing all public repostories with cta-release ones as
 these are now

---
 .gitlab-ci.yml                                |  14 +--
 .gitlab/ci/analysis.gitlab-ci.yml             |   5 +-
 .gitlab/ci/build.gitlab-ci.yml                |   1 -
 .gitlab/ci/dockerimage.gitlab-ci.yml          |   4 +-
 .gitlab/ci/tests.gitlab-ci.yml                |   2 -
 ReleaseNotes.md                               |   3 +
 .../ctafrontend/cc7/ci_runner/Dockerfile      |  28 ++---
 .../cc7/etc/yum.repos.d-public/ceph.repo      |   7 --
 .../cc7/etc/yum.repos.d-public}/cta-ceph.repo |   0
 .../cta-eos-citrine-depend.repo               |   0
 .../yum.repos.d-public}/cta-eos-citrine.repo  |   0
 .../cta-eos-diopside-depend.repo              |   0
 .../yum.repos.d-public}/cta-eos-diopside.repo |   0
 .../yum.repos.d-public}/cta-eos-quarkdb.repo  |   0
 .../cta-oracle-instant-client.repo            |   0
 .../etc/yum.repos.d-public}/cta-public.repo   |   0
 .../etc/yum.repos.d-public}/cta-xrootd.repo   |   0
 .../eos-citrine-depend.repo                   |   6 -
 .../etc/yum.repos.d-public/eos-citrine.repo   |   6 -
 .../eos-diopside-depend.repo                  |   6 -
 .../etc/yum.repos.d-public/eos-diopside.repo  |   6 -
 .../etc/yum.repos.d-public/eos-quarkdb.repo   |   6 -
 .../oracle-instant-client.repo                |   7 --
 .../cc7/opt/run/bin}/cta-versionlock          | 113 ++++++++++++------
 .../ctafrontend/cc7/opt/run/bin/ctaeos-mgm.sh |   3 +-
 .../cc7/opt/run/bin/versionlock_tools.sh      |  55 ---------
 cta-release/CMakeLists.txt                    |   4 +-
 cta-release/cta-release.conf                  |   5 +-
 cta.spec.in                                   |   8 +-
 29 files changed, 110 insertions(+), 179 deletions(-)
 delete mode 100644 continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/ceph.repo
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-ceph.repo (100%)
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-eos-citrine-depend.repo (100%)
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-eos-citrine.repo (100%)
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-eos-diopside-depend.repo (100%)
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-eos-diopside.repo (100%)
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-eos-quarkdb.repo (100%)
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-oracle-instant-client.repo (100%)
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-public.repo (100%)
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public}/cta-xrootd.repo (100%)
 delete mode 100644 continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-citrine-depend.repo
 delete mode 100644 continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-citrine.repo
 delete mode 100644 continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-diopside-depend.repo
 delete mode 100644 continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-diopside.repo
 delete mode 100644 continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-quarkdb.repo
 delete mode 100644 continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/oracle-instant-client.repo
 rename {cta-release => continuousintegration/docker/ctafrontend/cc7/opt/run/bin}/cta-versionlock (79%)
 delete mode 100755 continuousintegration/docker/ctafrontend/cc7/opt/run/bin/versionlock_tools.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 21fdfd51fc..907c0391b8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -20,17 +20,8 @@ variables:
 .prepare-xrootd5: &prepare-xrootd5
   - if [[ ${XROOTD_VERSION} -eq 5 ]];
     then echo "Using XRootD version 5";
-      sed -i 's/define xrootdVersion 1:4.12.4-1/define xrootdVersion 1:5.4.2-1/' cta.spec.in;
-      repodir=$(mktemp -d)
-      awk '/cta-ci-xroot\]/{ n=NR+5 } NR==n{ $0="enabled=0" }1'
-        continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d/cta-ci.repo > ${repodir}/cta-ci.repo
-        && mv ${repodir}/cta-ci.repo continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d/cta-ci.repo;
-      awk '/cta-ci-xrootd5/{ n=NR+5 } NR==n{ $0="enabled=1" }1'
-        continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d/cta-ci.repo > ${repodir}/cta-ci.repo
-        && mv ${repodir}/cta-ci.repo continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d/cta-ci.repo;
-      . ./continuousintegration/docker/ctafrontend/cc7/opt/run/bin/versionlock_tools.sh
-        continuousintegration/docker/ctafrontend/cc7/etc/yum/pluginconf.d/versionlock.list
-        && versionlock_xrootd_4_disable && versionlock_xrootd_5_enable;
+      ./continuousintegration/docker/ctafrontend/cc7/opt/run/bin/cta-versionlock --file ./continuousintegration/docker/ctafrontend/cc7/etc/yum/pluginconf.d/versionlock.list config xrootd5;
+      yum-config-manager --enable cta-ci-xrootd5;
     else echo "Using XRootD version 4";
     fi
 
@@ -54,6 +45,7 @@ default:
   before_script:
     - export CTA_BUILD_ID=${CI_PIPELINE_ID}git${CI_COMMIT_SHA:0:8}
     - echo "Exporting CTA_BUILD_ID=${CTA_BUILD_ID}"
+    - cp -f continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d/*.repo /etc/yum.repos.d/
     - test -n "${CI_COMMIT_TAG}" && export TAG_VERSION=$(echo ${CI_COMMIT_TAG} | sed -e 's/^v//;s/-.*$//')
     - test -n "${CI_COMMIT_TAG}" && export TAG_RELEASE=$(echo ${CI_COMMIT_TAG} | sed -e 's/^[^-]*-//')
     - major_version=$(echo ${TAG_VERSION} | cut -d. -f1)
diff --git a/.gitlab/ci/analysis.gitlab-ci.yml b/.gitlab/ci/analysis.gitlab-ci.yml
index 626ee47599..7362293789 100644
--- a/.gitlab/ci/analysis.gitlab-ci.yml
+++ b/.gitlab/ci/analysis.gitlab-ci.yml
@@ -5,6 +5,8 @@ cppcheck:
   image:
     name: neszt/cppcheck-docker
     entrypoint: ["/usr/bin/env"]
+  before_script:
+    - ''
   script:
     - cppcheck --xml --force --enable=warning,performance --inline-suppr --suppressions-list=.cppcheck-suppressions.txt . 2> cppcheck_out.xml
   artifacts:
@@ -19,9 +21,10 @@ cppcheck_report:
     - tags
   stage: analysis:report
   image: centos:7
-  script:
+  before_script:
     - yum -y install python3-pip
     - python3 -m pip install -U cppcheck_codequality
+  script:
     - cppcheck-codequality --input-file=cppcheck_out.xml --output-file=cppcheck.json
     - if cat cppcheck_out.xml | grep -q "<error\s"; then echo "ERRORS have been detected"; exit 1; fi;
   artifacts:
diff --git a/.gitlab/ci/build.gitlab-ci.yml b/.gitlab/ci/build.gitlab-ci.yml
index 94e4bfeddc..f8958d59ab 100644
--- a/.gitlab/ci/build.gitlab-ci.yml
+++ b/.gitlab/ci/build.gitlab-ci.yml
@@ -29,7 +29,6 @@
   extends:
     - .cta_build
   script:
-    - cp -f continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d/*.repo /etc/yum.repos.d/
     - yum install -y devtoolset-8 cmake3 make rpm-build
     - yum -y install yum-plugin-priorities yum-plugin-versionlock
     - yum install -y git
diff --git a/.gitlab/ci/dockerimage.gitlab-ci.yml b/.gitlab/ci/dockerimage.gitlab-ci.yml
index 1a6f64714d..b1a9c4d76b 100644
--- a/.gitlab/ci/dockerimage.gitlab-ci.yml
+++ b/.gitlab/ci/dockerimage.gitlab-ci.yml
@@ -6,8 +6,10 @@ ctageneric_docker:
     name: gitlab-registry.cern.ch/ci-tools/docker-image-builder
     entrypoint: [""]
   retry: 1
+  before_script:
+    - export CTA_BUILD_ID=${CI_PIPELINE_ID}git${CI_COMMIT_SHA:0:8}
   script:
     - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"${DOCKER_LOGIN_USERNAME}\",\"password\":\"${DOCKER_LOGIN_PASSWORD}\"}}}" > /kaniko/.docker/config.json
     - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $DOCKERFILE --destination ${CI_REGISTRY}/cta/ctageneric:${CTA_BUILD_ID}
   variables:
-    DOCKERFILE: continuousintegration/docker/ctafrontend/cc7/ci_runner/Dockerfile
\ No newline at end of file
+    DOCKERFILE: continuousintegration/docker/ctafrontend/cc7/ci_runner/Dockerfile
diff --git a/.gitlab/ci/tests.gitlab-ci.yml b/.gitlab/ci/tests.gitlab-ci.yml
index 00846d546e..dcaf2a91c6 100644
--- a/.gitlab/ci/tests.gitlab-ci.yml
+++ b/.gitlab/ci/tests.gitlab-ci.yml
@@ -16,7 +16,6 @@ cta_valgrind:
     CTAREPODIR: /tmp/repo
   image: gitlab-registry.cern.ch/linuxsupport/cc7-base
   script:
-    - cp -f continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d/* /etc/yum.repos.d/
     - yum -y install yum-plugin-priorities createrepo
     - cp -f continuousintegration/docker/ctafrontend/cc7/etc/yum/pluginconf.d/versionlock.list /etc/yum/pluginconf.d/
     - mkdir -p ${CTAREPODIR}; cp -r build_rpm/RPM ${CTAREPODIR}
@@ -34,7 +33,6 @@ dbunittests_postgresql:
     CTAREPODIR: /tmp/repo
   image: gitlab-registry.cern.ch/linuxsupport/cc7-base
   script:
-    - cp -f continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d/* /etc/yum.repos.d/
     - yum -y install yum-plugin-priorities createrepo
     - cp -f continuousintegration/docker/ctafrontend/cc7/etc/yum/pluginconf.d/versionlock.list /etc/yum/pluginconf.d/
     - mkdir -p ${CTAREPODIR}; cp -r build_rpm/RPM ${CTAREPODIR}
diff --git a/ReleaseNotes.md b/ReleaseNotes.md
index 942502a0bb..5817632350 100644
--- a/ReleaseNotes.md
+++ b/ReleaseNotes.md
@@ -6,6 +6,9 @@
 ### Bug Fixes
 - cta/CTA#259 - cta-rmcd should not exit if /dev/sg0 is missing
 
+### Continuous Integration
+- cta/CTA#262 - Manage CI repositories with `cta-release` code
+
 # v4.8.7-1
 
 ### Features
diff --git a/continuousintegration/docker/ctafrontend/cc7/ci_runner/Dockerfile b/continuousintegration/docker/ctafrontend/cc7/ci_runner/Dockerfile
index 8731c0ddac..1b99431816 100644
--- a/continuousintegration/docker/ctafrontend/cc7/ci_runner/Dockerfile
+++ b/continuousintegration/docker/ctafrontend/cc7/ci_runner/Dockerfile
@@ -27,6 +27,9 @@ ENV ORCHESTRATIONDIR="continuousintegration/orchestration/pods" \
 # Manage repos before running yum
 ADD ${BASEDIR}/etc /etc
 
+# Add orchestration run scripts locally
+ADD ${BASEDIR}/opt /opt
+
 RUN yum install -y \
       yum-plugin-downloadonly \
       yum-plugin-priorities \
@@ -52,25 +55,10 @@ ADD build_rpm/RPM ${CTAREPODIR}
 
 # Populate local repository and enable it
 RUN yum-config-manager --enable epel --setopt="epel.priority=4" \
-  && \
-    yum install --downloadonly --downloaddir=${CTAREPODIR}/RPMS/x86_64 \
-      xrootd-client \
-      xrootd-debuginfo \
-      xrootd-server \
   && \
     createrepo ${CTAREPODIR} \
   && \
     echo -e "[cta-artifacts]\nname=CTA artifacts\nbaseurl=file://${CTAREPODIR}\ngpgcheck=0\nenabled=1\npriority=2" > /etc/yum.repos.d/cta-artifacts.repo \
-  && \
-    # Install needed packages
-    #RUN yum -y install cta-frontend cta-debuginfo cgdb less psmisc lynx strace ltrace
-    # add cta-cli to get already some RPMs installed
-    yum -y install cgdb \
-      less \
-      psmisc \
-      lynx \
-      strace \
-      ltrace \
   && \
     yum clean all \
   && \
@@ -81,15 +69,15 @@ RUN yum-config-manager --enable epel --setopt="epel.priority=4" \
 # Check that CTA packages are in container (from previous artifacts)
 RUN find ${CTAREPODIR}/RPMS/x86_64 | grep cta-taped && echo "cta-taped rpm is present: artifacts seems OK" || (echo "cta-taped rpm was not added from previously built artifact: this is a gitlab issue that must be investigated" 1>&2; exit 1)
 
-# Check that xrootd packages are in container (downloaded from ci-repo)
-RUN find ${CTAREPODIR}/RPMS/x86_64 | grep xrootd-server && echo "xrootd-server rpm is present: CI repos seem OK" || (echo "xrootd-server rpm was not downloaded from CI configured repos: this must be investigated" 1>&2; exit 1)
+# Check if we need to enable cta-ci-xrootd5 repository
+RUN if find ${CTAREPODIR}/RPMS/x86_64 | grep cta-taped-5; then \
+  /opt/run/bin/cta-versionlock --file /etc/yum/pluginconf.d/versionlock.list config xrootd5; \
+  yum-config-manager --enable cta-ci-xrootd5; \
+fi
 
 # Add pod specific configuration
 ADD ${BASEDIR}/config ${LOCALORCHESTRATIONDIR}
 
-# Add orchestration run scripts locally
-ADD ${BASEDIR}/opt /opt
-
 # Docker image run setup
 ADD ${BASEDIR}/run.sh /
 
diff --git a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/ceph.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/ceph.repo
deleted file mode 100644
index 05dee16cb7..0000000000
--- a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/ceph.repo
+++ /dev/null
@@ -1,7 +0,0 @@
-[ceph]
-name=Ceph
-baseurl=https://download.ceph.com/rpm-15.2.15/el7/x86_64/
-gpgkey=file:///etc/pki/rpm-gpg/RPM-ASC-KEY-ceph
-gpgcheck=1
-enabled=1
-priority=1
diff --git a/cta-release/cta-ceph.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-ceph.repo
similarity index 100%
rename from cta-release/cta-ceph.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-ceph.repo
diff --git a/cta-release/cta-eos-citrine-depend.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-citrine-depend.repo
similarity index 100%
rename from cta-release/cta-eos-citrine-depend.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-citrine-depend.repo
diff --git a/cta-release/cta-eos-citrine.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-citrine.repo
similarity index 100%
rename from cta-release/cta-eos-citrine.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-citrine.repo
diff --git a/cta-release/cta-eos-diopside-depend.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-diopside-depend.repo
similarity index 100%
rename from cta-release/cta-eos-diopside-depend.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-diopside-depend.repo
diff --git a/cta-release/cta-eos-diopside.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-diopside.repo
similarity index 100%
rename from cta-release/cta-eos-diopside.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-diopside.repo
diff --git a/cta-release/cta-eos-quarkdb.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-quarkdb.repo
similarity index 100%
rename from cta-release/cta-eos-quarkdb.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-eos-quarkdb.repo
diff --git a/cta-release/cta-oracle-instant-client.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-oracle-instant-client.repo
similarity index 100%
rename from cta-release/cta-oracle-instant-client.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-oracle-instant-client.repo
diff --git a/cta-release/cta-public.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-public.repo
similarity index 100%
rename from cta-release/cta-public.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-public.repo
diff --git a/cta-release/cta-xrootd.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-xrootd.repo
similarity index 100%
rename from cta-release/cta-xrootd.repo
rename to continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/cta-xrootd.repo
diff --git a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-citrine-depend.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-citrine-depend.repo
deleted file mode 100644
index a4b81e9512..0000000000
--- a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-citrine-depend.repo
+++ /dev/null
@@ -1,6 +0,0 @@
-[eos-citrine-depend]
-name=EOS Citrine depend
-baseurl=http://storage-ci.web.cern.ch/storage-ci/eos/citrine-depend/el-7/x86_64/
-priority=4
-gpgcheck=0
-enabled=1
diff --git a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-citrine.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-citrine.repo
deleted file mode 100644
index 2db2d0a702..0000000000
--- a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-citrine.repo
+++ /dev/null
@@ -1,6 +0,0 @@
-[eos-citrine]
-name=EOS Citrine
-baseurl=https://storage-ci.web.cern.ch/storage-ci/eos/citrine/tag/testing/el-7/x86_64/
-priority=4
-gpgcheck=0
-enabled=1
diff --git a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-diopside-depend.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-diopside-depend.repo
deleted file mode 100644
index 9bf1004a29..0000000000
--- a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-diopside-depend.repo
+++ /dev/null
@@ -1,6 +0,0 @@
-[eos-diopside-depend]
-name=EOS Diopside depend
-baseurl=http://storage-ci.web.cern.ch/storage-ci/eos/diopside-depend/el-7/x86_64/
-priority=4
-gpgcheck=0
-enabled=0
diff --git a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-diopside.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-diopside.repo
deleted file mode 100644
index 2930dc4a39..0000000000
--- a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-diopside.repo
+++ /dev/null
@@ -1,6 +0,0 @@
-[eos-diopside]
-name=EOS Diopside
-baseurl=https://storage-ci.web.cern.ch/storage-ci/eos/diopside/tag/testing/el-7/x86_64/
-priority=4
-gpgcheck=0
-enabled=0
diff --git a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-quarkdb.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-quarkdb.repo
deleted file mode 100644
index 4c6f3a8583..0000000000
--- a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/eos-quarkdb.repo
+++ /dev/null
@@ -1,6 +0,0 @@
-[eos-quarkdb]
-name=EOS QuarkDB Repository
-baseurl=http://storage-ci.web.cern.ch/storage-ci/quarkdb/tag/el7/x86_64/
-gpgcheck=0
-enabled=0
-priority=5
diff --git a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/oracle-instant-client.repo b/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/oracle-instant-client.repo
deleted file mode 100644
index 5fff107bcf..0000000000
--- a/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/oracle-instant-client.repo
+++ /dev/null
@@ -1,7 +0,0 @@
-[oracle-instant-client]
-name=Oracle instant client
-baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/
-gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
-gpgcheck=1
-enabled=1
-priority=1
diff --git a/cta-release/cta-versionlock b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/cta-versionlock
similarity index 79%
rename from cta-release/cta-versionlock
rename to continuousintegration/docker/ctafrontend/cc7/opt/run/bin/cta-versionlock
index 7e5f0f5884..c5e9261e78 100755
--- a/cta-release/cta-versionlock
+++ b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/cta-versionlock
@@ -1,37 +1,41 @@
 #!/usr/bin/python
 
+from collections import defaultdict
+from rpmUtils.miscutils import splitFilename
+import argparse
+import json
 import os.path
-import sys
 import re
-import json
 import rpm
-from rpmUtils.miscutils import splitFilename
-from collections import defaultdict
+import sys
 import yum
 
 conf_file = '/etc/cta/cta-release.conf'
 
 vfiles = {
-  'cta': '/etc/yum/pluginconf.d/versionlock.cta', 
+  'cta': '/etc/yum/pluginconf.d/versionlock.cta',
   'yum': '/etc/yum/pluginconf.d/versionlock.list'
 }
-actions = ('help', 'check', 'apply', 'forceupdate', 'checkpkg', 'remove', 'config')
+versionlock_file = '/etc/yum/pluginconf.d/versionlock.cta'
+actions = ('check', 'apply', 'forceupdate', 'checkpkg', 'remove')
+configs = ('eos4', 'eos5', 'xrootd4', 'xrootd5')
 retcode = 0
 jsonoutput = False
 no_vlock = '/etc/cta.novlock'
 eos_version=0
+xrootd_version=0
 
 try:
   FileNotFoundError
 except NameError:
   FileNotFoundError = IOError
 
-
 def usage():
   print("\n%s: command line tool to manage cta packages versionlock\n \
 \n \
 usage: %s help|check|apply|forceupdate|checkpkg|remove [--json]\n \
        %s config eos4|eos5 [--json]\n \
+       %s config xrootd4|xrootd5 [--json]\n \
   help: print this message\n \
   check: show consistency of versionlock.list with cta versionlock requirements\n \
   apply: add cta versions to versionlock.list\n \
@@ -39,6 +43,7 @@ usage: %s help|check|apply|forceupdate|checkpkg|remove [--json]\n \
   checkpkg: check consistency between installed packages and cta versionlock requirements\n \
   remove: remove all cta packages and dependencies from versionlock.list\n \
   config eos4|eos5: select EOS version\n \
+  config xrootd4|xrootd5: select XRootD version\n \
   [--json]: format output in json\n \
   \n \
   to prevent cta-versionlock to alter versionlock.list create a %s file.\n \
@@ -53,6 +58,15 @@ yb.preconf.debuglevel = 0
 yb.preconf.errorlevel = 0
 repos_all = [repo.id for repo in yb.repos.findRepos("cta-*")]
 
+# if path doesn't exist, create it
+if not os.path.exists(os.path.dirname(conf_file)):
+  os.makedirs(os.path.dirname(conf_file))
+# If file doesn't exists, create a new file
+if not os.path.isfile(conf_file):
+  with open(conf_file, 'w') as f:
+    print("Creating new config file %s" % conf_file)
+    cta_conf_json = {'eos_major_version': 4, 'xrootd_major_version': 4, 'cta_major_version': 4}
+    f.write(json.dumps(cta_conf_json))
 with open(conf_file) as f:
   cta_conf_json = json.load(f)
 
@@ -72,10 +86,6 @@ def get_repo_set_for_cta_version(cta_major_version):
   else:
     raise RuntimeError("Unknown CTA major version '%s'." % cta_major_version)
 
-repos_selected = set()
-repos_selected |= get_repo_set_for_cta_version(cta_conf_json["cta_major_version"])
-repos_selected |= get_repo_set_for_eos_version(cta_conf_json["eos_major_version"])
-
 def switch_repos(repo_id_list, enable):
   for repo_id in repo_id_list:
     yb.repos.enableRepo(repo_id) if enable else yb.repos.disableRepo(repo_id)
@@ -224,52 +234,81 @@ def clearVfile(pkglist):
     f.write(content)
     f.truncate()
 
+# Write previous statements but using argparse
+parser = argparse.ArgumentParser(description='Manage CTA dependencies')
+subparsers = parser.add_subparsers(dest='command')
+config_parser = subparsers.add_parser('config')
+config_parser.add_argument('config_name', choices=configs, help='Name of the configuration file')
+for action in actions:
+  subparsers.add_parser(action)
+parser.add_argument('--file', help='use yum versionlock file')
+parser.add_argument('--json', action='store_true', help='output in json format')
+args = parser.parse_args()
+
+# Parse config
+if args.command == 'config':
+  if args.config_name == 'eos4':
+    eos_version = 4
+  elif args.config_name == 'eos5':
+    eos_version = 5
+  elif args.config_name == 'xrootd4':
+    xrootd_version = 4
+  elif args.config_name == 'xrootd5':
+    xrootd_version = 5
+
+if args.json:
+  jsonoutput = True
+
+if args.file:
+  versionlock_file = args.file
+  print("Using yum versionlock file: %s" % versionlock_file)  
 
 # check arguments
-if not 2 <= len(sys.argv) <= 4:
-  usage()
-
-for arg in sys.argv[1:]:
-  if arg == '--json':
-    jsonoutput = True
-  elif arg == 'eos4':
-    eos_version=4
-  elif arg == 'eos5':
-    eos_version=5
-  elif arg in actions:
-    action = arg
-  else:
-    print("Error: option %s is not valid" % sys.argv[1])
+if (args.command == 'check'):
+  if (eos_version and xrootd_version):
+    print("Error: cannot check both EOS and XRootD versions")
+    usage()
+  elif (not eos_version and not xrootd_version):
+    print("Error: no EOS or XRootD version was provided")
     usage()
 
-if (action == 'help'):
-  usage()
-
-if not eos_version and (action == 'config'):
+if (not eos_version and not xrootd_version)  and (action == 'config'):
   print("Error: no EOS version was provided")
   usage()
 
 message = defaultdict(dict)
 
-if (action == 'config'):
+if (args.command == 'config'):
   if eos_version is 4:
     message['title'] = "Enabling EOS-4 dependencies"
     cta_conf_json["eos_major_version"] = 4
-    switch_packages(vfiles['cta'], "EOS-4", True)
-    switch_packages(vfiles['cta'], "EOS-5", False)
+    switch_packages(versionlock_file, "EOS-4", True)
+    switch_packages(versionlock_file, "EOS-5", False)
   elif eos_version is 5:
     message['title'] = "Enabling EOS-5 dependencies"
     cta_conf_json["eos_major_version"] = 5
-    switch_packages(vfiles['cta'], "EOS-4", False)
-    switch_packages(vfiles['cta'], "EOS-5", True)
-  repos_selected = set()
-  repos_selected | get_repo_set_for_cta_version(cta_conf_json["cta_major_version"])
-  repos_selected |= get_repo_set_for_eos_version(cta_conf_json["eos_major_version"])
+    switch_packages(versionlock_file, "EOS-4", False)
+    switch_packages(versionlock_file, "EOS-5", True)
+  if xrootd_version is 4:
+    message['title'] = "Enabling XROOTD-4 dependencies"
+    cta_conf_json["xrootd_major_version"] = 4
+    switch_packages(versionlock_file, "XROOTD-4", True)
+    switch_packages(versionlock_file, "XROOTD-5", False)
+  elif xrootd_version is 5:
+    message['title'] = "Enabling XROOTD-5 dependencies"
+    cta_conf_json["xrootd_major_version"] = 5
+    switch_packages(versionlock_file, "XROOTD-4", False)
+    switch_packages(versionlock_file, "XROOTD-5", True)
+
   # Update value in config file
   with open(conf_file, "w") as f:
     f.write(json.dumps(cta_conf_json))
   _exit()
 
+repos_selected = set()
+repos_selected |= get_repo_set_for_cta_version(cta_conf_json["cta_major_version"])
+repos_selected |= get_repo_set_for_eos_version(cta_conf_json["eos_major_version"])
+
 # check if CTA packages exist in versionlock.list (ignore arch)
 versions = readVer(vfiles)
 versionlock = checkVfile(versions['cta'])
diff --git a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/ctaeos-mgm.sh b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/ctaeos-mgm.sh
index 5b96c979df..2c0984c049 100755
--- a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/ctaeos-mgm.sh
+++ b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/ctaeos-mgm.sh
@@ -25,8 +25,7 @@ if [ ! -e /etc/buildtreeRunner ]; then
 
   if test -f "/etc/config/eos/eos5"; then
     # Switch to EOS-5 versionlock
-    versionlock_eos_4_disable
-    versionlock_eos_5_enable
+    /opt/run/bin/cta-versionlock --file /etc/yum/pluginconf.d/versionlock.list config eos5
 
     yum-config-manager --disable eos-citrine-commit
     yum-config-manager --disable eos-citrine-depend
diff --git a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/versionlock_tools.sh b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/versionlock_tools.sh
deleted file mode 100755
index 93b28a31c4..0000000000
--- a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/versionlock_tools.sh
+++ /dev/null
@@ -1,55 +0,0 @@
- #!/bin/bash
-
-# @project      The CERN Tape Archive (CTA)
-# @copyright    Copyright © 2022 CERN
-# @license      This program is free software, distributed under the terms of the GNU General Public
-#               Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can
-#               redistribute it and/or modify it under the terms of the GPL Version 3, or (at your
-#               option) any later version.
-#
-#               This program 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 General Public License for more details.
-#
-#               In applying this licence, CERN does not waive the privileges and immunities
-#               granted to it by virtue of its status as an Intergovernmental Organization or
-#               submit itself to any jurisdiction.
-
-
-VERSIONLOCK_LIST=/etc/yum/pluginconf.d/versionlock.list
-
-if [ ! -z $1 ]
-then VERSIONLOCK_LIST=$1
-fi
-
-versionlock_eos_4_disable () {
-  sed  -i '/#*\s*EOS-4-START/,/#*\s*EOS-4-END/{/#*\s*EOS-4/!{s/^[^#]/#/g}}' $VERSIONLOCK_LIST
-}
-
-versionlock_eos_4_enable () {
-  sed  -i '/#*\s*EOS-4-START/,/#*\s*EOS-4-END/{/#*\s*EOS-4/!{s/^#//g}}' $VERSIONLOCK_LIST
-}
-
-versionlock_eos_5_disable () {
-  sed  -i '/#*\s*EOS-5-START/,/#*\s*EOS-5-END/{/#*\s*EOS-5/!{s/^[^#]/#/g}}' $VERSIONLOCK_LIST
-}
-
-versionlock_eos_5_enable () {
-  sed  -i '/#*\s*EOS-5-START/,/#*\s*EOS-5-END/{/#*\s*EOS-5/!{s/^#//g}}' $VERSIONLOCK_LIST
-}
-
-versionlock_xrootd_4_disable () {
-  sed  -i '/#*\s*XROOTD-4-START/,/#*\s*XROOTD-4-END/{/#*\s*XROOTD-4/!{s/^[^#]/#/g}}' $VERSIONLOCK_LIST
-}
-
-versionlock_xrootd_4_enable () {
-  sed  -i '/#*\s*XROOTD-4-START/,/#*\s*XROOTD-4-END/{/#*\s*XROOTD-4/!{s/^#//g}}' $VERSIONLOCK_LIST
-}
-
-versionlock_xrootd_5_disable () {
-  sed  -i '/#*\s*XROOTD-5-START/,/#*\s*XROOTD-5-END/{/#*\s*XROOTD-5/!{s/^[^#]/#/g}}' $VERSIONLOCK_LIST
-}
-
-versionlock_xrootd_5_enable () {
-  sed  -i '/#*\s*XROOTD-5-START/,/#*\s*XROOTD-5-END/{/#*\s*XROOTD-5/!{s/^#//g}}' $VERSIONLOCK_LIST
-}
diff --git a/cta-release/CMakeLists.txt b/cta-release/CMakeLists.txt
index 3b0ce4ffbb..374560a4c7 100644
--- a/cta-release/CMakeLists.txt
+++ b/cta-release/CMakeLists.txt
@@ -86,7 +86,7 @@ file(GENERATE OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/versionlock.cta CONTENT "${CTAV
 
 # Repos files
 file (GLOB REPO_FILES
-  "${CMAKE_CURRENT_SOURCE_DIR}/*.repo"
+  "${CMAKE_SOURCE_DIR}/continuousintegration/docker/ctafrontend/cc7/etc/yum.repos.d-public/*.repo"
 )
 
 # Signing keys
@@ -103,5 +103,5 @@ install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/versionlock.cta
   DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/yum/pluginconf.d)
 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-release.conf
   DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/cta)
-install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-versionlock
+install (FILES ${CMAKE_SOURCE_DIR}/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/cta-versionlock
   DESTINATION usr/${CMAKE_INSTALL_BINDIR})
diff --git a/cta-release/cta-release.conf b/cta-release/cta-release.conf
index 291c56ddf9..afa5a9d3dc 100644
--- a/cta-release/cta-release.conf
+++ b/cta-release/cta-release.conf
@@ -1,3 +1,4 @@
 {
-   "eos_major_version": 4
-}
\ No newline at end of file
+  "eos_major_version": 4,
+  "xrootd_major_version": 4
+}
diff --git a/cta.spec.in b/cta.spec.in
index d56ac49f9a..e07289736a 100644
--- a/cta.spec.in
+++ b/cta.spec.in
@@ -44,8 +44,14 @@ BuildRequires: cmake3 >= 3.17 redhat-rpm-config
 
 # The CTA client is the only component of CTA that can be compiled on both SLC6
 # and C77, therefore only the packages it depends on are required for SLC6
-%define radosVersion 2:15.2.15
+
+%if "%{ctaVersion}" == "4"
 %define xrootdVersion 1:4.12.4-1
+%else
+%define xrootdVersion 1:5.4.2-1
+%endif
+
+%define radosVersion 2:15.2.15
 BuildRequires: xrootd-client-devel  >= %{xrootdVersion}
 BuildRequires: xrootd-devel         >= %{xrootdVersion}
 BuildRequires: xrootd-server-devel  >= %{xrootdVersion}
-- 
GitLab