Skip to content

Instantly share code, notes, and snippets.

@sayan3296
Last active February 7, 2023 11:31
Show Gist options
  • Save sayan3296/61a4d3efc1ba6a2f817dc6bc94b0dc14 to your computer and use it in GitHub Desktop.
Save sayan3296/61a4d3efc1ba6a2f817dc6bc94b0dc14 to your computer and use it in GitHub Desktop.
Find package information from published version of the CVs across all environment
#!/bin/bash
# Criteria:
# Expected Column of the report:
#
# CV, CV Version, Lifecycle, Latest Kernel Package in the version
#
# Considerations:
#
# We will only choose those CV versions that have any lifecycle promoted to it.
# If a version of CV does not have kernel package at all, The result will be blank or NIL
## Setting basic vars
ORG_ID='1'
TMPFILE='/tmp/basic_info'
REPORT_OUT='/tmp/cv_info.csv'
LOOKUP=$1
if [ -z $LOOKUP ]
then
echo -e "
Usage: $0 <package name>
Example: $0 kernel
"
exit 1
fi
## Collecting the primary data
hammer --csv --csv-separator="|" --no-headers content-view version list --organization-id=$ORG_ID | awk -F'|' '$5 != "\"\""{print}' > $TMPFILE
## Setting up report headers
echo -e "\n-------------------,----------,---------------" > $REPORT_OUT
echo "CV_Name_and_Version,Lifecycles,Package_Details" >> $REPORT_OUT
echo "-------------------,----------,---------------" >> $REPORT_OUT
## Package search and report data processing starts here
echo "The search for $LOOKUP package has started in all the CV and CCV versions. Please be patient."
IFS=$'\n\b'
for i in $(cat $TMPFILE)
do
CV=$(echo $i | awk -F'|' '$2 !~ "Export-" && $2 !~ "Default Organization View"{print $2}')
CVV_ID=$(echo $i | awk -F'|' '$2 !~ "Export-" && $2 !~ "Default Organization View"{print $1}')
LCE=$(echo $i | awk -F'|' '$2 !~ "Export-" && $2 !~ "Default Organization View"{print $5}' | sed 's/,/ \&/g')
if [ ! -z $CVV_ID ]
then
PKG=$(hammer --no-headers package list --search "name = $LOOKUP" --content-view-version-id=$CVV_ID --packages-restrict-latest true --organization-id=$ORG_ID --fields filename)
if [ -z "$PKG" ]
then
PKG="`echo $LOOKUP`_not_found"
fi
echo -e "$CV,$LCE,$PKG" >> $REPORT_OUT
fi
done
## Creating a blank line at the end
echo -e "\n" >> $REPORT_OUT
## Information sent to user
echo -e "
Script execution has been completed. Please refer to $REPORT_OUT file for the result.
The data can be printed in a tabular format using this command as well without the quotes i.e. 'cat $REPORT_OUT | column -s, -t' .
"
@sayan3296
Copy link
Author

A Ruby\Rails based solution is also present but will work on the Katello shipped with Satellite 6.12 and above i.e.

https://gist.github.com/parthaa/4d03017a0f68ca69375f5d436d108025?permalink_comment_id=4461543#gistcomment-4461543

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment