@@ -297,10 +297,20 @@ get_installed_archlinux_packages() {
297297 fi
298298}
299299
300+ get_installed_gentoo_packages () {
301+ if check_command_exists qkeyword ; then
302+ gentoo_package_arch=$( qkeyword -A)
303+ fi
304+ if check_command_exists qlist ; then
305+ qlist -Ic -F " '%{PN}' '%{SLOT}' '%{PV}' REL'%{PR}' '${gentoo_package_arch} ' 'gentoo' '%{CAT}' '%{REPO}'" | sed -e " s/REL'r/'/g" >> " ${tmpfile_pkg} "
306+ fi
307+ }
308+
300309get_packages () {
301310 get_installed_rpm_packages
302311 get_installed_deb_packages
303312 get_installed_archlinux_packages
313+ get_installed_gentoo_packages
304314}
305315
306316get_modules () {
@@ -346,7 +356,9 @@ get_host_data() {
346356 os=" ${PRETTY_NAME} "
347357 elif [ " ${ID} " == " arch" ] ; then
348358 os=" ${NAME} "
349- elif [[ " ${ID} " =~ " suse" ]] ; then
359+ elif [ " ${ID} " == " gentoo" ] ; then
360+ os=" ${PRETTY_NAME} ${VERSION_ID} "
361+ elif [[ " ${ID_LIKE} " =~ " suse" ]] ; then
350362 os=" ${PRETTY_NAME} "
351363 elif [ " ${ID} " == " astra" ] ; then
352364 os=" ${NAME} $( cat /etc/astra_version) "
@@ -386,6 +398,9 @@ get_host_data() {
386398 fi
387399 done
388400 fi
401+ if [ ! -z " ${CPE_NAME} " ] ; then
402+ os=" ${os} [${CPE_NAME} ]"
403+ fi
389404 if ${verbose} ; then
390405 echo " Kernel: ${host_kernel} "
391406 echo " Arch: ${host_arch} "
@@ -452,7 +467,7 @@ get_repos() {
452467 fi
453468 # replace this with a dedicated awk or simple python script?
454469 yum_repolist=$( yum repolist enabled --verbose 2> /dev/null | sed -e " s/:\? *([0-9]\+ more)$//g" -e " s/ ([0-9]\+$//g" -e " s/:\? more)$//g" -e " s/'//g" -e " s/%/%%/g" )
455- for i in $( echo " ${yum_repolist} " | awk ' { if ($1=="Repo-id") {printf "' " '" ' "; for (i=3; i<NF; i++) printf $i " "; printf $NF"' " '" ' "} if ($1=="Repo-name") {printf "' " '" ' "; for (i=3; i<NF; i++) printf $i " "; printf $NF"' " ${host_arch} '" ' "} if ($1=="Repo-mirrors" || $1=="Repo-metalink: ") {printf "' " '" ' "; for (i=3; i<NF; i++) printf $i " "; printf $NF"' " '" ' "} if ($1=="Repo-baseurl" || $1=="Repo-baseurl:") { url=1; comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "' " '" ' "out"' " '" ' "; } else { if (url==1) { if ($1==":") { comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "' " '" ' "out"' " '" ' "; } else {url=0; print "";} } } }' | sed -e " s/\/'/'/g" | sed -e " s/ ' /' /" ) ; do
470+ for i in $( echo " ${yum_repolist} " | awk ' { if ($1=="Repo-id") {printf "' " '" ' "; for (i=3; i<NF; i++) printf $i " "; printf $NF"' " '" ' "} if ($1=="Repo-name") {printf "' " '" ' "; for (i=3; i<NF; i++) printf $i " "; printf $NF"' " ${host_arch} '" ' "} if ($1=="Repo-mirrors" || $1=="Repo-metalink") {printf "' " '" ' "; for (i=3; i<NF; i++) printf $i " "; printf $NF"' " '" ' "} if ($1=="Repo-baseurl" || $1=="Repo-baseurl:") { url=1; comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "' " '" ' "out"' " '" ' "; } else { if (url==1) { if ($1==":") { comma=match($NF,","); if (comma) out=substr($NF,1,comma-1); else out=$NF; printf "' " '" ' "out"' " '" ' "; } else {url=0; print "";} } } }' | sed -e " s/\/'/'/g" | sed -e " s/ ' /' /" ) ; do
456471 full_id=$( echo ${i} | cut -d \' -f 2)
457472 id=$( echo ${i} | cut -d \' -f 2 | cut -d \/ -f 1)
458473 name=$( echo ${i} | cut -d \' -f 4)
@@ -463,7 +478,7 @@ get_repos() {
463478 if [ " ${priority} " == " " ] ; then
464479 priority=99
465480 fi
466- redhat_repo=$( echo ${i} | grep -e " https://.*/XMLRPC.*\|https://cdn.redhat.com/.*" )
481+ redhat_repo=$( echo ${i} | grep -e " https://.*/XMLRPC.*\|https://cdn[-[a-z]*]* .redhat.com/.*" )
467482 if [ ${?} == 0 ] || ${local_updates} ; then
468483 if ${verbose} ; then
469484 echo " Finding updates locally for ${id} "
@@ -473,7 +488,7 @@ get_repos() {
473488 if [ ! -z ${CPE_NAME} ] ; then
474489 id=" ${CPE_NAME} -${id} "
475490 fi
476- j=$( echo ${i} | sed -e " s#'${full_id} ' '${name} '#'${name} ' '${id} ' '${priority} '#" )
491+ j=$( echo ${i} | sed -e " s#'${full_id} ' '${name} '#'${name} ' '${id} ' '${priority} '#" | sed -e " s/'\[/'/g " -e " s/\]'/'/g " )
477492 echo " 'rpm' ${j} " >> " ${tmpfile_rep} "
478493 unset priority
479494 done
@@ -484,7 +499,8 @@ get_repos() {
484499 if ${verbose} ; then
485500 echo ' Finding apt repos...'
486501 fi
487- IFS=${FULL_IFS} read -r osname shortversion <<< $( echo " ${os} " | awk ' {print $1,$2}' | cut -d . -f 1,2)
502+ osname=$( echo ${os} | cut -d " " -f 1)
503+ shortversion=${VERSION_ID}
488504 repo_string=" 'deb\' \'${osname} ${shortversion} ${host_arch} repo at"
489505 repos=$( apt-cache policy | grep -v Translation | grep -E " ^ *[0-9]{1,5}" | grep -E " mirror\+file|http(s)?:" | sed -e " s/^ *//g" -e " s/ *$//g" | cut -d " " -f 1,2,3,4)
490506 non_mirror_repos=$( echo " ${repos} " | grep -Ev " mirror\+file" )
@@ -510,11 +526,11 @@ get_repos() {
510526 echo ' Finding zypper repos...'
511527 fi
512528 if [ $( zypper -q --no-refresh lr --details | head -n 1 | grep Keep) ] ; then
513- zypper_lr_cols=" 2,3,8,10 "
529+ zypper_lr_cols=' {print "${os}" $3 "|" $2 "|" $8 "|" $10} '
514530 else
515- zypper_lr_cols=" 2,3,7,9 "
531+ zypper_lr_cols=' {print "${os}" $3 "|" $2 "|" $7 "|" $9} '
516532 fi
517- for i in $( zypper -q --no-refresh lr -E -u --details | grep -v ^$ | tail -n +3 | cut -d " |" -f ${zypper_lr_cols} | sed -e " s/ *|/ ${host_arch} |/" -e " s/\?[a-zA-Z0-9_-]* *$//" -e " s/^ /'/g" -e " s/ *| */' '/g" -e " s/ *$/'/g" ) ; do
533+ for i in $( zypper -q --no-refresh lr -E -u --details | grep -v ^$ | tail -n +3 | awk -F " |" " ${zypper_lr_cols} " | sed -e " s/\$ {os}/ ${PRETTY_NAME} / " -e " s/ *|/ ${host_arch} |/" -e " s/\?[a-zA-Z0-9_-]* *$//" -e " s/^/'/g" -e " s/ *| */' '/g" -e " s/ *$/'/g" ) ; do
518534 echo \' rpm\' ${i} >> " ${tmpfile_rep} "
519535 id=$( echo ${i} | cut -d \' -f 4)
520536 suse_repo=$( echo ${i} | grep -e " https://updates.suse.com/.*" )
@@ -557,6 +573,56 @@ get_repos() {
557573 done
558574 fi
559575
576+ # Gentoo
577+ if [[ " ${os} " =~ " Gentoo" ]] ; then
578+ if [ ${verbose} == 1 ] ; then
579+ echo ' Finding portage repos...'
580+ fi
581+ declare -A repo_info
582+ repos_output=$( portageq repos_config /)
583+ repo_name=" "
584+ priority=" "
585+ sync_uri=" "
586+
587+ while IFS= read -r line; do
588+ # if the line starts with a section header (e.g., [gentoo], [guru]), it's the repo name
589+ if [[ " ${line} " =~ ^\[ (.* )\] ]]; then
590+ # if we already have a repo_name, save the previous entry
591+ if [[ -n " ${repo_name} " && -n " ${sync_uri} " ]]; then
592+ repo_info[" ${repo_name} " ]=" ${priority} ,${sync_uri} "
593+ fi
594+ # else start new repo parsing, resetting vars
595+ repo_name=" ${BASH_REMATCH[1]} "
596+ priority=" "
597+ sync_uri=" "
598+ fi
599+
600+ # if the line contains "priority", extract the value, 0 if it doesnt exist
601+ if [[ " ${line} " =~ " priority" ]]; then
602+ priority=$( echo " ${line} " | cut -d' =' -f2 | xargs)
603+ fi
604+
605+ # if the line contains "sync-uri", extract the value
606+ if [[ " ${line} " =~ " sync-uri" ]]; then
607+ sync_uri=$( echo " ${line} " | cut -d' =' -f2 | xargs)
608+ fi
609+ done <<< " ${repos_output}"
610+
611+ # save the last repository entry if it's available
612+ if [[ -n " ${repo_name} " && -n " ${sync_uri} " ]]; then
613+ repo_info[" ${repo_name} " ]=" ${priority} ,${sync_uri} "
614+ fi
615+
616+ for repo in " ${! repo_info[@]} " ; do
617+ priority=$( echo ${repo_info[$repo]} | cut -d' ,' -f1)
618+ sync_uri=$( echo ${repo_info[$repo]} | cut -d' ,' -f2)
619+ if [ " ${priority} " == " " ] ; then
620+ priority=0
621+ fi
622+ echo " 'gentoo' 'Gentoo Linux ${repo} Repo ${host_arch} ' '${repo} ' '${priority} ' '${sync_uri} '" >> " ${tmpfile_rep} "
623+ done
624+ fi
625+
560626 IFS=${FULL_IFS}
561627
562628 sed -i -e ' /^$/d' " ${tmpfile_rep} "
@@ -629,10 +695,11 @@ post_data() {
629695}
630696
631697if ! check_command_exists which || \
698+ ! check_command_exists awk || \
632699 ! check_command_exists mktemp || \
633700 ! check_command_exists curl || \
634701 ! check_command_exists flock ; then
635- echo " which, mktemp, flock or curl was not found, exiting."
702+ echo " which, awk, mktemp, flock or curl was not found, exiting."
636703 exit 1
637704fi
638705
0 commit comments