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