-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpulp3_repo_list.sh
More file actions
executable file
·189 lines (148 loc) · 6.6 KB
/
pulp3_repo_list.sh
File metadata and controls
executable file
·189 lines (148 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
#
# License ......: GPL
# Developer ....: Waldirio M Pinheiro <waldirio@gmail.com> | <waldirio@redhat.com>
# Date .........: 02/24/2022
# Purpose ......: To extract the information from Postgres regarding to pulp3 (repos, content views, packages)
#
STD_FILE="/var/log/pulp3_content_info.log"
REPORT_FILE="/var/log/pulp3_report_info.log"
TEMP_FILE="/var/tmp/pulp3_report_tmpdata.txt"
> $STD_FILE
> $REPORT_FILE
> $TEMP_FILE
main()
{
echo "select base_path,pulp_created,pulp_last_updated from core_distribution" | su - postgres -c "psql pulpcore" >> $STD_FILE
echo "" >> $STD_FILE
path_of_repos=$(echo "select base_path from core_distribution" | su - postgres -c "psql pulpcore" | sed '1,2d' | grep -v ^$ | grep -v ^\( | sed -e 's/^ //g')
for b in $path_of_repos
do
echo - $b >> $STD_FILE
echo "select core_d.base_path,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 = '$b' order by core_d.base_path" | su - postgres -c "psql pulpcore" >> $STD_FILE
echo >> $STD_FILE
echo >> $STD_FILE
echo >> $STD_FILE
echo >> $STD_FILE
done
}
basic_info()
{
echo "#######################" >> $REPORT_FILE
echo "Basic Pulp3 Information" >> $REPORT_FILE
echo "#######################" >> $REPORT_FILE
echo "" >> $REPORT_FILE
org_name=$(cat $STD_FILE | grep "^- " | cut -d/ -f1 | sed -e 's/^- //g' | sort -u)
lifecycle_name=$(cat $STD_FILE | grep "^- " | cut -d/ -f2 | sed -e 's/^- //g' | sort -u)
cv_name=$(cat $STD_FILE | grep "^- " | cut -d/ -f3 | sed -e 's/^- //g' | grep -v -E '(^content$|^custom$)'| sort -u)
echo "# Organization(s):" >> $REPORT_FILE
echo "------------------" >> $REPORT_FILE
echo "$org_name" | xargs echo | sed 's/ / , /g' >> $REPORT_FILE
echo >> $REPORT_FILE
echo "# LifeCycle(s):" >> $REPORT_FILE
echo "---------------" >> $REPORT_FILE
echo "$lifecycle_name" | xargs echo | sed 's/ / , /g' >> $REPORT_FILE
echo >> $REPORT_FILE
echo "# Content View(s):" >> $REPORT_FILE
echo "------------------" >> $REPORT_FILE
echo "$cv_name" | xargs echo | sed 's/ / , /g' >> $REPORT_FILE
echo >> $REPORT_FILE
echo >> $REPORT_FILE
echo >> $REPORT_FILE
}
detailed_repo_info()
{
echo "#######################################" >> $REPORT_FILE
echo "Presentation of Individual Repositories" >> $REPORT_FILE
echo "#######################################" >> $REPORT_FILE
echo "" >> $REPORT_FILE
repo_list=$(cat $STD_FILE | grep "^- " | sed -e 's/^- //g')
echo -e "Repo_Path\tRPM_Count_in_Metadata\tRPM_Count_in_DB" >> $TEMP_FILE
echo -e "---------\t---------------------\t---------------\n" >> $TEMP_FILE
for b in $repo_list
do
PULP_PATH="/var/lib/pulp/media"
# Adding space after $b to match the exact repo path
number_of_packages=$(cat $STD_FILE 2>/dev/null | grep "$b " | grep .rpm | wc -l)
repomd_artifact=$(cat $STD_FILE 2>/dev/null | grep "$b " | grep repomd.xml | awk '{print $NF}')
primary_file=$(cat $PULP_PATH/$repomd_artifact 2>/dev/null | grep primary.xml | cut -d\" -f2)
primary_file_artifact=$(cat $STD_FILE 2>/dev/null | grep "$b " | grep "$primary_file" | awk '{print $NF}')
number_of_packages_metadata=$(zcat $PULP_PATH/$primary_file_artifact 2>/dev/null | grep -o "packages=\"".* | cut -d\" -f2)
echo -e "**$b\t$number_of_packages_metadata\t$number_of_packages"
done >> $TEMP_FILE
cat $TEMP_FILE | column -t >> $REPORT_FILE
rm -f $TEMP_FILE
echo -e "\n\n\n" >> $REPORT_FILE
}
general_cv_info()
{
echo "#####################################################" >> $REPORT_FILE
echo "Presentation of Content View / Composite Content View" >> $REPORT_FILE
echo "#####################################################" >> $REPORT_FILE
echo "" >> $REPORT_FILE
org_name=$(cat $STD_FILE | grep "^- " | cut -d/ -f1 | sed -e 's/^- //g' | sort -u)
lifecycle_name=$(cat $STD_FILE | grep "^- " | cut -d/ -f2 | sed -e 's/^- //g' | sort -u)
cv_name=$(cat $STD_FILE | grep "^- " | cut -d/ -f3 | sed -e 's/^- //g' | grep -v -E '(^content$|^custom$)'| sort -u)
echo -e "Organization\tLifeCycle\tContent_View\tRPM_Count_in_Metadata\tRPM_Count_in_DB" >> $TEMP_FILE
echo -e "------------\t---------\t------------\t---------------------\t---------------" >> $TEMP_FILE
for org in $org_name
do
for lfc in $lifecycle_name
do
for cv in $cv_name
do
full_filter="$org/$lfc/$cv/"
count_entry=$(grep -A2 "$full_filter" $REPORT_FILE | wc -l)
if [ $count_entry -ne 0 ]; then
## $2 is RPM_Count_in_Metadata and $3 is RPM_Count_in_DB for each value matched by $full_filter
total_cv_metadata=$(grep "^\*\*" $REPORT_FILE | grep "$full_filter" | awk '{print $2}' | grep -v "^$" | paste -s -d+ | bc)
total_cv_DB=$(grep "^\*\*" $REPORT_FILE | grep "$full_filter" | awk '{print $3}' | grep -v "^$" | paste -s -d+ | bc)
echo -e "$org\t$lfc\t$cv\t$total_cv_metadata\t$total_cv_DB"
fi
done
done
done >> $TEMP_FILE
# New for to check the default organization view
for org in $org_name
do
total_cv_metadata=$(grep "^\*\*" $REPORT_FILE | egrep "($org/Library/content/)|($org/Library/custom/)" | awk '{print $2}' | grep -v "^$" | paste -s -d+ | bc)
total_cv_DB=$(grep "^\*\*" $REPORT_FILE | egrep "($org/Library/content/)|($org/Library/custom/)" | awk '{print $3}' | grep -v "^$" | paste -s -d+ | bc)
echo -e "$org\tLibrary\tDefaultOrganizationView\t$total_cv_metadata\t$total_cv_DB"
done >> $TEMP_FILE
cat $TEMP_FILE | column -t >> $REPORT_FILE
rm -f $TEMP_FILE
echo -e "\n\n\n" >> $REPORT_FILE
}
adding_timestamp()
{
echo "###############################################" >> $REPORT_FILE
echo "Repositories Creation date and Last Update time" >> $REPORT_FILE
echo "###############################################" >> $REPORT_FILE
echo "" >> $REPORT_FILE
# just to keep the format and space in the beggining of the line
IFS=$'\n'
for line in $(cat $STD_FILE)
do
check=$(echo $line | grep -E '(.*\)$)' | wc -l)
if [ $check -eq 1 ]; then
break
else
echo $line >> $REPORT_FILE
fi
done
unset IFS
echo -e "\n------ End of Report ------" >> $REPORT_FILE
}
final()
{
echo "Please, upload to Red Hat the files in a sequence:"
echo " - $STD_FILE"
echo " - $REPORT_FILE"
}
# Execute All in sequence
main
basic_info
detailed_repo_info
general_cv_info
adding_timestamp
final