CSIT-1362: migrate package download scripts for hc2vpp jobs
[csit.git] / resources / tools / scripts / download_hc_build_pkgs.sh
1 #!/bin/bash
2
3 # Copyright (c) 2019 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 set -ex
17
18 STREAM=$1
19 OS=$2
20
21 # Figure out what system we are running on
22 if [[ -f /etc/os-release ]];then
23     source /etc/os-release
24 else
25     echo "Cannot determine OS version"
26     exit 1
27 fi
28 echo "----- OS INFO -----"
29 echo DISTRIB_ID: ${ID}
30 echo DISTRIB_RELEASE: ${VERSION_ID}
31 echo DISTRIB_CODENAME: ${VERSION_CODENAME}
32 echo DISTRIB_DESCRIPTION: ${PRETTY_NAME}
33
34 VERSION=`../vpp-version`
35 JVPP_VERSION=`../jvpp-version`
36 VPP_DEB_NEW_ARTIFACTS="vpp libvppinfra vpp-plugin-core vpp-api-java"
37 VPP_DEB_ARTIFACTS="vpp vpp-lib vpp-plugins vpp-api-java"
38 VPP_RPM_ARTIFACTS="vpp vpp-lib vpp-plugins vpp-api-java"
39 IGNORE_DEPS=""
40 # Check OS and stream to set correct packages
41 if [[ "$ID" == "centos" ]]; then
42     VPP_ARTIFACTS=${VPP_RPM_ARTIFACTS}
43 elif [[ "$ID" == "ubuntu" ]]; then
44     if [[ "1807 1810 1901" =~ .*$STREAM.* ]]; then
45         VPP_ARTIFACTS=${VPP_DEB_ARTIFACTS}
46         IGNORE_DEPS="vpp,vpp-lib,vpp-plugins"
47     else
48         VPP_ARTIFACTS=${VPP_DEB_NEW_ARTIFACTS}
49         IGNORE_DEPS="vpp,libvppinfra,vpp-plugin-core"
50     fi
51 fi
52 VPP_DEB_PACKAGES=""
53 VPP_RPM_PACKAGES=""
54 for ART in ${VPP_ARTIFACTS}; do
55     if [[ "${VERSION}" != 'RELEASE' ]]; then
56         if [[ "$ART" == "vpp-api-java" ]]; then
57             VPP_DEB_PACKAGES="$VPP_DEB_PACKAGES $ART=$JVPP_VERSION"
58             VPP_RPM_PACKAGES="$VPP_RPM_PACKAGES $ART-$JVPP_VERSION"
59         else
60             VPP_DEB_PACKAGES="$VPP_DEB_PACKAGES $ART=$VERSION"
61             VPP_RPM_PACKAGES="$VPP_RPM_PACKAGES $ART-$VERSION"
62         fi
63     else
64         VPP_DEB_PACKAGES="$VPP_DEB_PACKAGES $ART"
65         VPP_RPM_PACKAGES="$VPP_RPM_PACKAGES $ART"
66     fi
67 done
68
69 echo "----- DOWNLOADING PACKAGES -----"
70 REPO_URL="https://packagecloud.io/fdio/${STREAM}"
71 echo "REPO_URL: ${REPO_URL}"
72 if [[ "$ID" == "ubuntu" ]]; then
73     if [[ -f /etc/apt/sources.list.d/99fd.io.list ]];then
74         echo "Deleting: /etc/apt/sources.list.d/99fd.io.list"
75         sudo rm /etc/apt/sources.list.d/99fd.io.list
76     fi
77     curl -s https://packagecloud.io/install/repositories/fdio/${STREAM}/script.deb.sh | sudo bash
78     apt-get download ${VPP_DEB_PACKAGES} || true
79 elif [[ "$ID" == "centos" ]]; then
80     if [[ -f /etc/yum.repos.d/fdio-master.repo ]]; then
81         echo "Deleting: /etc/yum.repos.d/fdio-master.repo"
82         sudo rm /etc/yum.repos.d/fdio-master.repo
83     fi
84     curl -s https://packagecloud.io/install/repositories/fdio/${STREAM}/script.rpm.sh | sudo bash
85     sudo yum -y install --downloadonly --downloaddir=./ ${VPP_RPM_PACKAGES} || true
86 fi
87 # TODO(CSIT-994): reenable NSH
88 # NSH_GROUP="io.fd.nsh_sfc"
89 # NSH_ARTIFACTS="vpp-nsh-plugin"
90
91 # install vpp-api-java, this extracts jvpp .jar files into usr/share/java
92 if [[ "${OS}" == "centos7" ]]; then
93     sudo rpm --nodeps --install vpp-api-java*
94 else
95     sudo dpkg --ignore-depends=${IGNORE_DEPS} --install vpp-api-java*
96 fi
97
98 # install jvpp jars into maven repo, so that maven picks them up when building hc2vpp
99 version=`../jvpp/version`
100
101 current_dir=`pwd`
102 cd /usr/share/java
103
104 for item in jvpp*.jar; do
105     # Example filename: jvpp-registry-19.04.jar
106     # ArtifactId = jvpp-registry
107     # Version = 19.04 or 19.04-SNAPSHOT
108     basefile=$(basename -s .jar "$item")
109     artifactId=$(echo "$basefile" | cut -d '-' -f 1-2)
110     mvn install:install-file -Dfile=${item} -DgroupId=io.fd.vpp -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=jar -Dmaven.repo.local=/tmp/r -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r
111 done
112
113 # vpp-api-package is no longer necessary, breaks the installation of other packages that follow in next steps
114 if [[ "${OS}" == "centos7" ]]; then
115     sudo yum remove "*vpp-api-java*"
116 else
117     sudo apt remove "*vpp-api-java*"
118 fi
119
120 cd ${current_dir}