0c35917e731ace052e14ba1a65678989ece08660
[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 START_PACKAGES=/tmp/packages_start.txt
22 END_PACKAGES=/tmp/packages_end.txt
23 DIFF_PACKAGES=/tmp/packages_diff.txt
24
25 # This script may be run during system boot, if that is true then there will be
26 # a starting_packages file. We will want to create a diff if we have a starting
27 # packages file
28 PACKAGES="${START_PACKAGES}"
29 if [ -f "${PACKAGES}" ]
30 then
31     PACKAGES="${END_PACKAGES}"
32     CREATEDIFF=1
33 fi
34
35 case "${OS_FAMILY}" in
36     redhat|suse)
37         # RedHat and Suse flavors all use rpm at the package level
38         rpm -qa | sort > "${PACKAGES}"
39     ;;
40     debian)
41         # Debian derived flavors all use dpkg at the package level
42         dpkg -l | grep '^ii' > "${PACKAGES}"
43     ;;
44     *)
45         # nothing to do
46     ;;
47 esac
48
49 if [ "${CREATEDIFF}" ]
50 then
51     diff "${START_PACKAGES}" "${END_PACKAGES}" > "${DIFF_PACKAGES}"
52 fi
53
54 # If running in a Jenkins job, then copy the created files to the archives
55 # location
56 if [ "${WORKSPACE}" ]
57 then
58     mkdir -p "${WORKSPACE}/archives/"
59     cp -f /tmp/packages_*.txt "${WORKSPACE}/archives/"
60 fi