Simplify PACKAGE_LIST sed line
[arvados-dev.git] / jenkins / upload_packages_testing_to_stable.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 # This script publishes packages from our dev repo to the prod repo (#11572)
7 # Parameters: list of packages, space separated, to move from *-testing to *
8 # under /var/lib/freight/apt/ in host public.curoverse.com
9
10 set -x
11
12 APT_REPO_SERVER="apt.arvados.org"
13 RPM_REPO_SERVER="rpm.arvados.org"
14
15 DEBUG=1
16 SSH_PORT=2222
17 ECODE=0
18
19 # Convert package list into a regex for publising
20 # Make sure the variables are set or provide an example of how to use them
21 if [ -z "${PACKAGES_TO_PUBLISH}" ]; then
22   echo "You must provide a list of packages to publish, as obtained with https://dev.arvados.org/projects/ops/wiki/Updating_clusters#Gathering-package-versions."
23   exit 254
24 fi
25 if [ -z "${LSB_DISTRIB_CODENAMES}" ]; then
26   echo "You must provide a space-separated list of LSB distribution codenames to which you want to publish to, ie."
27   echo "* Debian: jessie, xenial, stretch, etc."
28   echo "* Centos: centos7 (the only one currently supported.)"
29   exit 255
30 fi
31
32 # Sanitize the vars in a way suitable to be used by the remote 'publish_packages.sh' script
33 # Just to make copying a single line, and not having to loop over it
34 PACKAGES_LIST=$(echo ${PACKAGES_TO_PUBLISH} | sed 's/versions://g; s/\([a-z-]*\):[[:blank:]]*\([0-9.-]*\)/\1*\2*,/g; s/[[:blank:]]//g; s/,$//g;')
35
36 DISTROS=$(echo "${LSB_DISTRIB_CODENAMES}"|sed s/[[:space:]]/,/g |tr '[:upper:]' '[:lower:]')
37
38 if ( echo ${LSB_DISTRIB_CODENAMES} |grep -q centos ); then
39   REPO_SERVER=${RPM_REPO_SERVER}
40 else
41   REPO_SERVER=${APT_REPO_SERVER}
42 fi
43
44 REMOTE_CMD="/usr/local/bin/testing_to_stable_publish_packages.sh --distros ${DISTROS} --packages ${PACKAGES_LIST}"
45
46 # Now we execute it remotely
47 TMP_FILE=`mktemp`
48
49 ssh -t \
50     -l jenkinsapt \
51     -p $SSH_PORT \
52     -o "StrictHostKeyChecking no" \
53     -o "ConnectTimeout 5" \
54     ${REPO_SERVER} \
55     "${REMOTE_CMD}" | tee ${TMP_FILE}
56 ECODE=$?
57
58 grep -q "FAILED TO PUBLISH" ${TMP_FILE}
59 if [ $? -eq 0 ]; then
60   ECODE=1
61 fi
62 rm -f ${TMP_FILE}
63 exit ${ECODE}