Merge "Clean up vpp jenkins scripts & docker dir"
[ci-management.git] / jjb / scripts / packagecloud_push.sh
1 #!/bin/bash
2
3 # Copyright (c) 2020 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 echo "---> jjb/scripts/packagecloud_push.sh"
17
18 set -euxo pipefail
19
20 echo "STARTING PACKAGECLOUD PUSH"
21
22 sleep 10
23
24 FACTER_OS=$(/usr/bin/facter operatingsystem)
25 push_cmd=""
26
27 # PCIO_CO and SILO are Jenkins Global Environment variables defined in
28 # .../ci-management/jenkins-config/global-vars-*.sh
29 if [ -f ~/.packagecloud ]; then
30     case "$FACTER_OS" in
31         Debian)
32             FACTER_LSBNAME=$(/usr/bin/facter lsbdistcodename)
33             DEBS=$(find . -type f -iname '*.deb')
34             push_cmd="package_cloud push ${PCIO_CO}/${STREAM}/debian/${FACTER_LSBNAME}/main/ ${DEBS}"
35             ;;
36         Ubuntu)
37             FACTER_LSBNAME=$(/usr/bin/facter lsbdistcodename)
38             DEBS=$(find . -type f -iname '*.deb')
39             push_cmd="package_cloud push ${PCIO_CO}/${STREAM}/ubuntu/${FACTER_LSBNAME}/main/ ${DEBS}"
40             ;;
41         CentOS)
42             FACTER_OSMAJREL=$(/usr/bin/facter operatingsystemmajrelease)
43             FACTER_ARCH=$(/usr/bin/facter architecture)
44             RPMS=$(find . -type f -iregex '.*/.*\.\(s\)?rpm')
45             push_cmd="package_cloud push ${PCIO_CO}/${STREAM}/el/${FACTER_OSMAJREL}/os/${FACTER_ARCH}/ ${RPMS}"
46             ;;
47         *)
48             echo "ERROR: Unsupported OS '$FACTER_OS'"
49             echo "PACKAGECLOUD PUSH FAILED!"
50             exit 1
51             ;;
52     esac
53     if [ "${SILO,,}" = "sandbox" ] ; then
54         echo "SANDBOX: skipping '$push_cmd'"
55     else
56         $push_cmd
57     fi
58 else
59     echo "ERROR: Missing '~/.packagecloud' for user '$(id)'"
60     echo "PACKAGECLOUD PUSH FAILED!"
61     exit 1
62 fi
63
64 echo "PACKAGECLOUD PUSH COMPLETE"