Last active
March 6, 2023 15:09
-
-
Save sayan3296/464a95332b4a9df98516fd595f52d8fd to your computer and use it in GitHub Desktop.
Get RPM name for a repo along with arifact name on filesystem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NAME="$1" | |
if [ -z "$NAME" ] | |
then | |
echo 'Please pass a valid repository name with quotes. Refer the "hammer repository list" output for the names'. | |
exit 0; | |
fi | |
echo "COPY(select main.id,root.name,main.relative_path from katello_root_repositories root left JOIN katello_repositories main on main.root_id=root.id where main.library_instance_id is null and root.name = '$NAME') TO STDOUT WITH CSV;" | su - postgres -c "psql foreman" > /tmp/library_repos.txt | |
IFS=$'\n';for repo in $(cat /tmp/library_repos.txt) | |
do | |
REPO_PATH=`echo $repo | cut -d, -f3` | |
echo "COPY(select cpa.relative_path,ca.file from core_distribution as core_d RIGHT JOIN core_publication as cp ON core_d.publication_id=cp.pulp_id LEFT JOIN core_publishedartifact as cpa ON cp.pulp_id=cpa.publication_id LEFT JOIN core_contentartifact as core_ca ON core_ca.pulp_id=cpa.content_artifact_id LEFT JOIN core_artifact as ca ON ca.pulp_id=core_ca.artifact_id where core_d.base_path = '$REPO_PATH' and cpa.relative_path like '%Packages/%' order by core_d.base_path) TO STDOUT WITH CSV" | su - postgres -c "psql pulpcore" > /tmp/rpm_list.txt | |
IFS=$'\n';for map in $(cat /tmp/rpm_list.txt) | |
do | |
RPM_NAME=$(echo $map | cut -d, -f1 | awk -F'/' '{print $NF}') | |
FILE="/var/lib/pulp/media/$(echo $map | cut -d, -f2)" | |
if [ $FILE == "/var/lib/pulp/media/" ] | |
then | |
STAT="Not-Downloaded" | |
else | |
test -e $FILE && echo "$RPM_NAME,$FILE" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: