Merge branch '17218-repository-update'
[arvados-dev.git] / jenkins / testing_to_stable_publish_packages.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 testing repo to the prod repo (#11572 and #11878)
7 # Parameters (both are mandatory):
8 #   --packages list of packages, comma separated, to move from dev_repo_dir to prod_repo_dir
9 #   --distros  list of distros, comma separated, to which to publish packages
10
11 RPM_REPO_BASE_DIR="/var/www/rpm.arvados.org"
12
13 ###  MAIN  ####################################################################
14 [ $# -lt 2 ] && {
15   echo "usage: "
16   echo "    $0 --distros <distroA,distroB,...,distroN> --packages <packageA,packageB,...,packageN>"
17   echo "    (both parameters are mandatory)"
18   echo ""
19   exit 1
20 }
21
22 # Parse options
23 while [ ${#} -gt 0 ]; do
24     case ${1} in
25         --packages)   packages="$2";    shift 2 ;;
26         --distros)    distros="$2";     shift 2 ;;
27         *)            echo "$0: Unrecognized option: $1" >&2; exit 1;
28     esac
29 done
30
31 # Make sure the variables are set or provide an example of how to use them
32 if [ -z "${packages}" ]; then
33   echo "You must provide a comma-separated list of packages to publish, ie."
34   echo "* Debian: --packages=arvados-ws_0.1.20170906144951.22418ed6e-1_amd64.deb,keep-exercise_*,*170906144951*"
35   echo "* Centos: --packages=arvados-ws_0.1.20170906144951.22418ed6e-1.x86_64.rpm,keep-exercise_0.1.20170906144951.22418ed6e-1.x86_64.rpm,crunch-dispatch-local_0.1.20170906144951.22418ed6e-1.x86_64.rpm"
36   exit 254
37 fi
38 if [ -z "${distros}" ]; then
39   echo "You must provide a space-separated list of LSB distribution codenames to which you want to publish to, ie."
40   echo "* Debian: --distros=jessie,xenial,stretch,etc."
41   echo "* Centos: --distros=centos7,etc."
42   exit 255
43 fi
44
45 DIST_LIST=$(echo ${distros} | sed s/,/' '/g |tr '[:upper:]' '[:lower:]')
46 PACKAGES=$(echo ${packages} | sed s/,/' '/g)
47
48 if ( echo ${DIST_LIST} |grep -q centos ); then
49   for DISTNAME in ${DIST_LIST}; do 
50     case ${DISTNAME} in
51       'centos7')
52         DIST_DIR_TEST='7/testing/x86_64'
53         DIST_DIR_PROD='7/os/x86_64'
54       ;;
55       *)
56         echo "Only centos7 is accepted right now"
57         exit 253
58       ;;
59     esac
60     cd ${RPM_REPO_BASE_DIR}
61     mkdir -p ${RPM_REPO_BASE_DIR}/CentOS/${DIST_DIR_PROD}
62     echo "Copying packages ..."
63     for P in ${PACKAGES}; do
64       cp ${RPM_REPO_BASE_DIR}/CentOS/${DIST_DIR_TEST}/${P} ${RPM_REPO_BASE_DIR}/CentOS/${DIST_DIR_PROD}/
65       if [ $? -ne 0 ]; then
66         FAILED_PACKAGES="${FAILED_PACKAGES} ${P}"
67       fi
68     done
69     echo "Recreating repo CentOS/${DIST_DIR_PROD} ..."
70     createrepo ${RPM_REPO_BASE_DIR}/CentOS/${DIST_DIR_PROD}
71   done
72 else
73   for DISTNAME in ${DIST_LIST}; do
74     ADDED=()
75     echo "Copying packages ..."
76     for P in ${PACKAGES}; do
77       aptly repo copy ${DISTNAME}-testing ${DISTNAME} $(basename ${P})
78     done
79     echo "Publishing ${DISTNAME} repository..."
80     aptly publish update ${DISTNAME} filesystem:${DISTNAME}:
81   done
82 fi
83
84 if [ "${FAILED_PACKAGES}" != "" ]; then
85   echo "PACKAGES THAT FAILED TO PUBLISH"
86   echo "${FAILED_PACKAGES}"
87 else
88   echo "All packages published correctly"
89 fi