cleaning up detections, removing explicit package manager tests and instead simply show the presence of the repos.

this is mainly to cleanly handle cases where either apt or rpm systems may be running the other package manager.
This commit is contained in:
inxi-svn 2012-12-22 03:54:43 +00:00
parent a768fc0669
commit be56b3af55

53
inxi
View file

@ -3,7 +3,7 @@
#### Script Name: inxi
#### version: 1.8.24
#### Date: December 6 2012
#### Patch Number: 05-b1
#### Patch Number: 06-b1
########################################################################
#### SPECIAL THANKS
########################################################################
@ -191,7 +191,6 @@ LINE_MAX_IRC='105'
PS_COUNT=5
PS_THROTTLED=''
REPO_DATA=''
REPO_FILE_ID=''
### primary data array holders ## usage: 'A_<var>'
A_ALSA_DATA=''
@ -6020,25 +6019,15 @@ get_repo_data()
local apt_file='/etc/apt/sources.list' yum_repo_dir='/etc/yum.repos.d/' yum_conf='/etc/yum.conf'
local pacman_conf='/etc/pacman.conf' pacman_repo_dir='/etc/pacman.d/' pisi_dir='/etc/pisi/'
## note: a fringe case was discovered where repo files were in /etc/apt/sources.list.d for yum
# so handling more explicitly the actual repo file id. Note that apt-get can be run in rpm distros
# using apt-rpm package
if [[ -n $( type -p apt-get ) ]];then
repo_type='apt'
elif [[ -n $( type -p yum ) ]];then
repo_type='yum'
elif [[ -n $( type -p pisi ) ]];then
repo_type='pisi'
elif [[ -n $( type -p pacman ) ]];then
repo_type='pacman'
fi
# apt - debian, buntus
# apt - debian, buntus, also sometimes some yum/rpm repos may create apt repos here as well
if [[ -f $apt_file || -d $apt_file.d ]];then
REPO_DATA="$( grep -Esv '(^[[:space:]]*$|^[[:space:]]*#)' $apt_file $apt_file.d/*.list )"
REPO_FILE_ID="$repo_type sources"
REPO_DATA="$( grep -Esv '(^[[:space:]]*$|^[[:space:]]*#)' $apt_file $apt_file.d/*.list | sed -r 's/^(.*)/apt sources:\1/' )"
fi
# yum - fedora, redhat, centos, etc. Note that rpmforge for some odd reason places its yum repos
# in /etc/apt/sources.list.d/
# yum - fedora, redhat, centos, etc. Note that rpmforge also may create apt sources
# in /etc/apt/sources.list.d/. Therefore rather than trying to assume what package manager is
# actually running, inxi will merely note the existence of each repo type for apt/yum.
# Also, in rpm, you can install apt-rpm for the apt-get command, so it's not good to check for
# only the commands in terms of selecting which repos to show.
if [[ -d $yum_repo_dir || -f $yum_conf ]];then
# older redhats put their yum data in /etc/yum.conf
for repo_file in $( ls $yum_repo_dir*.repo $yum_conf 2>/dev/null )
@ -6046,7 +6035,7 @@ get_repo_data()
repo_data_working="$( gawk -v repoFile=$repo_file '
# construct the string for the print function to work with, file name: data
function print_line( fileName, repoId, repoUrl ){
print fileName ":" repoId repoUrl
print "yum repos:" fileName ":" repoId repoUrl
}
BEGIN {
FS="\n"
@ -6109,10 +6098,9 @@ $repo_data_working"
repo_data_working=''
fi
done
REPO_FILE_ID="$repo_type repos"
# pacman - archlinux, going to assume that pisi and arch/pacman don't have the above issue
# pacman - archlinux, going to assume that pisi and arch/pacman don't have the above issue with apt/yum
# pisi - pardus
elif [[ -d $pisi_dir && $repo_type == 'pisi' ]];then
elif [[ -d $pisi_dir && -n $( type -p pisi ) ]];then
REPO_DATA="$( pisi list-repo )"
# now we need to create the structure: repo info: repo path
# we do that by looping through the lines of the output and then
@ -6128,14 +6116,13 @@ $repo_data_working"
print $0
}' <<< $repo_line )
if [[ -n $( grep '://' <<< $repo_line ) ]];then
repo_data_working="$repo_data_working:$repo_line\n"
repo_data_working="pisi repos:$repo_data_working:$repo_line\n"
else
repo_data_working="$repo_data_working$repo_line"
fi
done <<< "$REPO_DATA"
# echo and execute the line breaks inserted
REPO_DATA="$( echo -e $repo_data_working )"
REPO_FILE_ID="$repo_type repos"
elif [[ -f $pacman_conf ]];then
# get list of mirror include files, trim white space off ends
repo_data_working="$( gawk '
@ -6162,7 +6149,7 @@ $repo_data_working"
}
/^[[:space:]]*Server/ {
sub(/^[[:space:]]+|[[:space:]]+$/,"",$2)
print repoFile ":" $2 "\\n"
print "pacman repo servers:" repoFile ":" $2 "\\n"
}
' $repo_file )"
else
@ -6171,7 +6158,6 @@ $repo_data_working"
done
# execute line breaks
REPO_DATA="$( echo -e $repo_data_working2 )"
REPO_FILE_ID="$repo_type repo servers"
fi
eval $LOGFE
}
@ -8573,7 +8559,7 @@ print_repo_data()
{
eval $LOGFS
local repo_count=0 repo_line='' file_name='' file_content='' file_name_holder=''
local repo_full='' b_print_next_line='false'
local repo_full='' b_print_next_line='false' repo_type=''
get_repo_data
@ -8582,8 +8568,9 @@ print_repo_data()
while read repo_line
do
(( repo_count++ ))
file_name=$( cut -d ':' -f 1 <<< $repo_line )
file_content=$( cut -d ':' -f 2-6 <<< $repo_line )
repo_type=$( cut -d ':' -f 1 <<< $repo_line )
file_name=$( cut -d ':' -f 2 <<< $repo_line )
file_content=$( cut -d ':' -f 3-7 <<< $repo_line )
# this will dump unwanted white space line starters. Some irc channels
# use bots that show page title for urls, so need to break the url by adding
# a white space.
@ -8594,10 +8581,10 @@ print_repo_data()
fi
# check file name, if different, update the holder for print out
if [[ $file_name != $file_name_holder ]];then
if [[ $REPO_FILE_ID != 'pisi repo' ]];then
repo_full="${C1}Active $REPO_FILE_ID in file:${C2} $file_name"
if [[ $repo_type != 'pisi repo' ]];then
repo_full="${C1}Active $repo_type in file:${C2} $file_name"
else
repo_full="${C1}$REPO_FILE_ID:${C2} $file_name"
repo_full="${C1}$repo_type:${C2} $file_name"
fi
file_name_holder=$file_name
b_print_next_line='true'