11#! /bin/bash
2+ # Copyright (c) Microsoft Corporation.
3+ # Licensed under the MIT License.
4+
5+ sodiff_script_error=false
6+ while getopts " r:f:v:o:e:" opt; do
7+ case $opt in
8+ r) rpms_folder=" $OPTARG " ;;
9+ f) repo_file_path=" $OPTARG " ;;
10+ v) mariner_version=" $OPTARG " ;;
11+ o) sodiff_out_dir=" $OPTARG " ;;
12+ e) sodiff_script_error=" $OPTARG " ;;
13+ esac
14+ done
15+
16+ if [[ -z " $rpms_folder " ]]; then
17+ echo " INVALID ARGUMENT: RPMS_FOLDER is empty. It can be specified via the -r command line option."
18+ exit 1
19+ fi
220
3- # Required binaries:
4- # rpm and dnf
21+ if [[ -z " $repo_file_path " ]]; then
22+ echo " INVALID ARGUMENT: REPO_FILE_PATH is empty. It can be specified via the -f command line option."
23+ exit 1
24+ fi
525
6- rpms_folder=" $1 "
7- repo_file_path=" $2 "
8- mariner_version=" $3 "
9- sodiff_out_dir=" $4 "
26+ if [[ -z " $mariner_version " ]]; then
27+ echo " INVALID ARGUMENT: MARINER_VERSION is empty. It can be specified via the -v command line option."
28+ exit 1
29+ fi
30+
31+ if [[ -z " $sodiff_out_dir " ]]; then
32+ echo " INVALID ARGUMENT: SODIFF_OUT_DIR is empty. It can be specified via the -o command line option."
33+ exit 1
34+ fi
1035sodiff_log_file=" ${sodiff_out_dir} /sodiff.log"
1136
1237# Setup output dir
@@ -16,22 +41,26 @@ mkdir -p "$sodiff_out_dir"
1641
1742common_options=" -c $repo_file_path --releasever $mariner_version "
1843
19- DNF_COMMAND =dnf
44+ dnf_command =dnf
2045# Cache RPM metadata
21- > /dev/null dnf $common_options -y makecache
46+ > /dev/null $dnf_command $common_options -y makecache
2247
2348# Get packages from stdin
2449pkgs=` cat`
50+ echo " $pkgs "
2551
2652for rpmpackage in $pkgs ; do
53+ package_debuginfo=$( echo " $rpmpackage " | rev | cut -f3 -d' -' | rev)
54+ if [[ " $package_debuginfo " == " debuginfo" ]]; then
55+ continue
56+ fi
2757 package_path=$( find " $rpms_folder " -name " $rpmpackage " -type f)
2858 package_provides=` 2> /dev/null rpm -qP " $package_path " | grep -E ' [.]so[(.]' `
2959 echo " Processing ${rpmpackage} ..."
3060 echo " .so's provided: $package_provides "
3161 for sofile in $package_provides ; do
3262 # Query local metadata for provides
33- sos_found=$( 2> /dev/null $DNF_COMMAND repoquery $common_options --whatprovides $sofile | wc -l )
34- echo " Number of .so files found: $sos_found "
63+ sos_found=$( 2> /dev/null $dnf_command repoquery $common_options --whatprovides $sofile | wc -l )
3564 if [ " $sos_found " -eq 0 ] ; then
3665 # SO file not found, meaning this might be a new .SO
3766 # or a new version of a preexisting .SO.
@@ -41,14 +70,13 @@ for rpmpackage in $pkgs; do
4170 sofile_no_ver=$( echo " $sofile " | sed -E ' s/[.]so[(.].+/.so/' )
4271
4372 # check for generic .so in the repo
44- sos_found=$( 2> /dev/null $DNF_COMMAND repoquery $common_options --whatprovides " ${sofile_no_ver} *" | wc -l )
45- echo " Number of non-versioned .so files found: $sos_found "
73+ sos_found=$( 2> /dev/null $dnf_command repoquery $common_options --whatprovides " ${sofile_no_ver} *" | wc -l )
4674 if ! [ " $sos_found " -eq 0 ] ; then
4775 # Generic version of SO was found.
4876 # This means it's a new version of a preexisting SO.
4977 # Log which packages depend on this functionality
5078 echo " Packages that require $sofile_no_ver :"
51- 2> /dev/null $DNF_COMMAND repoquery $common_options -s --whatrequires " ${sofile_no_ver} *" | sed -E ' s/[.][^.]+[.]src[.]rpm//' | tee " $sodiff_out_dir " /" require_${sofile} "
79+ 2> /dev/null $dnf_command repoquery $common_options -s --whatrequires " ${sofile_no_ver} *" | sed -E ' s/[.][^.]+[.]src[.]rpm//' | tee " $sodiff_out_dir " /" require_${sofile} "
5280 fi
5381 fi
5482 done
5886# Obtain a list of unique packages to be updated
59872> /dev/null cat " $sodiff_out_dir " /require* | sort -u > " $sodiff_out_dir " /sodiff-intermediate-summary.txt
6088
61- rm " $sodiff_out_dir " /require*
89+ rm -f " $sodiff_out_dir " /require*
6290touch " $sodiff_out_dir " /sodiff-summary.txt
6391
6492# Remove packages that have been dash-rolled already.
@@ -86,6 +114,9 @@ echo "######################"
86114if [[ $pkgsFound -gt 0 ]]; then
87115 echo " The Following Packages Are in Need of an Update:"
88116 cat " $sodiff_out_dir " /sodiff-summary.txt
117+ if [[ " $sodiff_script_error " -eq " true" ]]; then
118+ exit 1
119+ fi
89120else
90121 echo " No Packages with Conflicting .so Files Found."
91122fi
0 commit comments