Fix API breakage caused by OS Plugin version scan
[releng/global-jjb.git] / shell / package-listing.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 echo "---> package-listing.sh"
13
14 # Ensure we fail the job if any steps fail
15 set -eu -o pipefail
16
17 set -x # Trace commands for this script to make debugging easier
18
19 OS_FAMILY=$(facter osfamily | tr '[:upper:]' '[:lower:]')
20
21 # Capture the CI WORKSPACE safely in the case that it doesn't exist
22 workspace="${WORKSPACE:-}"
23
24 START_PACKAGES=/tmp/packages_start.txt
25 END_PACKAGES=/tmp/packages_end.txt
26 DIFF_PACKAGES=/tmp/packages_diff.txt
27
28 # Swap to creating END_PACKAGES if we are running in a CI job (determined by if
29 # we have a workspace env) or if the starting packages listing already exists.
30 PACKAGES="${START_PACKAGES}"
31 if ( [ "${workspace}" ] || [ -f "${START_PACKAGES}" ] )
32 then
33     PACKAGES="${END_PACKAGES}"
34 fi
35
36 case "${OS_FAMILY}" in
37     redhat|suse)
38         # RedHat and Suse flavors all use rpm at the package level
39         rpm -qa | sort > "${PACKAGES}"
40     ;;
41     debian)
42         # Debian derived flavors all use dpkg at the package level
43         dpkg -l | grep '^ii' > "${PACKAGES}"
44     ;;
45     *)
46         # nothing to do
47     ;;
48 esac
49
50 if ( [ -f "${START_PACKAGES}" ] && [ -f "${END_PACKAGES}" ] )
51 then
52     diff "${START_PACKAGES}" "${END_PACKAGES}" > "${DIFF_PACKAGES}"
53 fi
54
55 # If running in a Jenkins job, then copy the created files to the archives
56 # location
57 if [ "${workspace}" ]
58 then
59     mkdir -p "${workspace}/archives/"
60     cp -f /tmp/packages_*.txt "${workspace}/archives/"
61 fi