more code cleanup

This commit is contained in:
inxi-svn 2008-10-28 02:07:37 +00:00
parent 28be7483ec
commit fa66c967b5

113
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 0.1.2 #### version: 0.1.3
#### Date: October 27 2008 #### Date: October 27 2008
######################################################################## ########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif #### inxi is a fork of infobash, the original bash sys info script by locsmif
@ -243,6 +243,7 @@ mkbans()
cscheme() cscheme()
{ {
local I SCOLORS CLCODES local I SCOLORS CLCODES
if [[ $1 -ge ${#SCHEMES[@]} ]] if [[ $1 -ge ${#SCHEMES[@]} ]]
then then
set -- 1 set -- 1
@ -254,7 +255,7 @@ cscheme()
else else
CLCODES=($IRCCL) CLCODES=($IRCCL)
fi fi
for ((I=0;I<${#COLORS[@]};I++)) for (( I=0; I < ${#COLORS[@]}; I++ ))
do do
eval "${COLORS[I]}=\"${CLCODES[I]}\"" eval "${COLORS[I]}=\"${CLCODES[I]}\""
done done
@ -366,24 +367,28 @@ roots()
*perl*) *perl*)
unset IRCV # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client unset IRCV # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
getcmdline $PPID getcmdline $PPID
for ((I=0; I<=$CMDLMAX; I++)); do for ((I=0; I<=$CMDLMAX; I++))
do
case ${CMDL[I]} in case ${CMDL[I]} in
*dsirc*) *dsirc*)
IRC="KSirc" IRC="KSirc"
# Dynamic runpath detection is too complex with KSirc, because KSirc is started from # Dynamic runpath detection is too complex with KSirc, because KSirc is started from
# kdeinit. /proc/<pid of the grandparent of this process>/exe is a link to /usr/bin/kdeinit # kdeinit. /proc/<pid of the grandparent of this process>/exe is a link to /usr/bin/kdeinit
# with one parameter which contains parameters separated by spaces(??), first param being KSirc. # with one parameter which contains parameters separated by spaces(??), first param being KSirc.
# Then, KSirc runs dsirc as the perl irc script and wraps around it. When /exec is executed, # Then, KSirc runs dsirc as the perl irc script and wraps around it. When /exec is executed,
# dsirc is the program that runs infobash, therefore that is the parent process that we see. # dsirc is the program that runs infobash, therefore that is the parent process that we see.
# You can imagine how hosed I am if I try to make infobash find out dynamically with which path # You can imagine how hosed I am if I try to make infobash find out dynamically with which path
# KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material. # KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material.
# (KSirc sucks anyway ;) # (KSirc sucks anyway ;)
IRCV=" $(ksirc -v | gawk '/KSirc:/ { print $2; exit }')" IRCV=" $(ksirc -v | gawk '/KSirc:/ { print $2; exit }')"
break break
;; ;;
esac esac
done done
[[ -z $IRCV ]] && IRC="Unknown Perl client" if [[ -z $IRCV ]]
then
IRC="Unknown Perl client"
fi
;; ;;
*bash*|*sh*) *bash*|*sh*)
unset IRCV unset IRCV
@ -405,7 +410,7 @@ roots()
} }
# Get the parameters # Get the parameters
getparams() get_parameters()
{ {
if [[ -z $1 ]] if [[ -z $1 ]]
then then
@ -456,7 +461,10 @@ getparams()
;; ;;
*) *)
echo "$1" | grep -q '^[0-9][0-9]\?$' || error 3 "$1" echo "$1" | grep -q '^[0-9][0-9]\?$' || error 3 "$1"
((CSCHEME)) || cscheme "$1" if ! ((CSCHEME))
then
cscheme "$1"
fi
;; ;;
esac esac
shift shift
@ -541,7 +549,7 @@ then
fi fi
# "$@" passes every parameter seperately quoted, "$*" passes all parameters as one quoted parameter. # "$@" passes every parameter seperately quoted, "$*" passes all parameters as one quoted parameter.
getparams "$@" get_parameters "$@"
# If no colorscheme was set in the parameter handling routine, then set the default scheme # If no colorscheme was set in the parameter handling routine, then set the default scheme
if ! ((CSCHEME)) if ! ((CSCHEME))
@ -560,10 +568,10 @@ cd /etc; DISTGLOB=(*[-_]{release,version})
cd "$OLDPWD" cd "$OLDPWD"
shopt -u nullglob shopt -u nullglob
if ((${#DISTGLOB[@]} == 1)) if (( ${#DISTGLOB[@]} == 1 ))
then then
DISTFILE="${DISTGLOB}" DISTFILE="${DISTGLOB}"
elif ((${#DISTGLOB[@]} > 1)) elif (( ${#DISTGLOB[@]} > 1 ))
then then
for I in $DIST_DERIV $DIST_MAIN for I in $DIST_DERIV $DIST_MAIN
do do
@ -579,16 +587,16 @@ then
fi fi
if [ -n "$DISTFILE" -a -s /etc/$DISTFILE -a " $DIST_BLIST " != *" $DISTFILE "* ] if [ -n "$DISTFILE" -a -s /etc/$DISTFILE -a " $DIST_BLIST " != *" $DISTFILE "* ]
then then
DISTRO=$(eat "/etc/$DISTFILE") DISTRO=$( eat "/etc/$DISTFILE" )
else else
# Debian pure should fall through here # Debian pure should fall through here
DISTFILE="issue" DISTFILE="issue"
DISTRO=$(gawk 'BEGIN { RS="" } { gsub(/\\[a-z]/,""); gsub(/ [ ]+/," "); gsub(/^ +| +$/,""); print }' "/etc/${DISTFILE}") DISTRO=$( gawk 'BEGIN { RS="" } { gsub(/\\[a-z]/,""); gsub(/ [ ]+/," "); gsub(/^ +| +$/,""); print }' "/etc/${DISTFILE}" )
fi fi
((${#DISTRO} > 80 && ! CRAP)) && DISTRO="${RED}/etc/${DISTFILE} corrupted, use --crap to override${NORMAL}" ((${#DISTRO} > 80 && ! CRAP)) && DISTRO="${RED}/etc/${DISTFILE} corrupted, use --crap to override${NORMAL}"
: ${DISTRO:=Unknown distro o_O} : ${DISTRO:=Unknown distro o_O}
OSKERN=$(uname -a | gawk '{print $1,$3,$(NF-1)}') OSKERN=$( uname -a | gawk '{print $1,$3,$(NF-1)}' )
IFS=$'\n' IFS=$'\n'
CPU=($(gawk -F': ' ' CPU=($(gawk -F': ' '
@ -639,8 +647,8 @@ for ((I=0;I<${#CPU[@]}-1;I++))
do do
IFS=","; CPUTMP=(${CPU[I]}); IFS="$OIFS" IFS=","; CPUTMP=(${CPU[I]}); IFS="$OIFS"
unset CPU[I] unset CPU[I]
CPUTMP[0]=$(sanitize NORMALBANS "${CPUTMP[0]}") CPUTMP[0]=$( sanitize NORMALBANS "${CPUTMP[0]}" )
CPUTMP[0]=$(sanitize CPUBANS "${CPUTMP[0]}") CPUTMP[0]=$( sanitize CPUBANS "${CPUTMP[0]}" )
# I use all these loops so I can easily extend the cpu array created in the awk script above with more fields per cpu. # I use all these loops so I can easily extend the cpu array created in the awk script above with more fields per cpu.
for (( J=0; J<${#CPUTMP[@]}; J++ )) for (( J=0; J<${#CPUTMP[@]}; J++ ))
do do
@ -657,7 +665,7 @@ if echo "${CPU[@]}" | grep -qi 'dual\|triple\|quad'
then then
NOCPUCOUNT=1 NOCPUCOUNT=1
else else
case $((${#CPU[@]}-1)) in case $(( ${#CPU[@]}-1 )) in
2) 2)
CPU2="Dual" CPU2="Dual"
;; ;;
@ -681,8 +689,8 @@ CPUTMP=(${CPU[0]})
IFS="$OIFS" IFS="$OIFS"
# For the short line # For the short line
CPUMODEL="${CPU2}${CPU2+ }${CPUTMP[0]}" # clocked at [${CPU[${#CPU[@]}-1]}]" # old CPU2 CPUMODEL="${CPU2}${CPU2+ }${CPUTMP[0]}" # clocked at [${CPU[${#CPU[@]}-1]}]" # old CPU2
CPUCLOCK="${CPU[${#CPU[@]}-1]}" # old CPU3 CPUCLOCK="${CPU[${#CPU[@]}-1]}" # old CPU3
CPUFLAGS="${CPUTMP[3]}" # old CPU4 CPUFLAGS="${CPUTMP[3]}" # old CPU4
# nx = AMD stack protection extensions # nx = AMD stack protection extensions
# lm = Intel 64bit extensions # lm = Intel 64bit extensions
# sse, sse2, pni = sse1,2,3 gfx extensions # sse, sse2, pni = sse1,2,3 gfx extensions
@ -715,7 +723,10 @@ END {
') ')
#grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' ')) #grep -oE '\<(nx|lm|sse[0-9]?|pni|svm|vmx)\>' | tr '\n' ' '))
[[ -z $CPUFLAGS ]] && CPUFLAGS="-" if [[ -z $CPUFLAGS ]]
then
CPUFLAGS="-"
fi
for I in /proc/ide/ide*/hd* for I in /proc/ide/ide*/hd*
do do
@ -754,9 +765,11 @@ then
} }
} }
} }
' /proc/scsi/scsi)); IFS="$OIFS" ' /proc/scsi/scsi))
IFS="$OIFS"
for ((I=0;I<${#THDD[@]};I++)); do for (( I=0; I < ${#THDD[@]}; I++ ))
do
HDDMOD="${HDDMOD}${HDDMOD+,}${THDD[I]}" HDDMOD="${HDDMOD}${HDDMOD+,}${THDD[I]}"
done done
fi fi
@ -767,7 +780,7 @@ then
HDDCAP1="$((CAP/2))" HDDCAP1="$((CAP/2))"
fi fi
# See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below # See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below
HDDCAP2=$(gawk '$1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {size+=$3} END {printf("%d\n",size)}' /proc/partitions) HDDCAP2=$( gawk '$1 ~ /^(3|22|33|8)$/ && $2 % 16 == 0 {size+=$3} END {printf("%d\n",size)}' /proc/partitions )
##say "HDDCAP1=\"$HDDCAP1\" HDDCAP2=\"$HDDCAP2"" ; exit ##say "HDDCAP1=\"$HDDCAP1\" HDDCAP2=\"$HDDCAP2"" ; exit
HDD=0 HDD=0
@ -809,11 +822,11 @@ END {
printf("%.1f/%.1fMB\n", used/1024, tot/1024) printf("%.1f/%.1fMB\n", used/1024, tot/1024)
}' /proc/meminfo) }' /proc/meminfo)
PROC="$(($(ps aux | wc -l)-1))" PROC="$(( $( ps aux | wc -l ) - 1 ))"
UPT=$(uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }') UPT=$( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }' )
IFS=$'\n' IFS=$'\n'
GFX=($(echo "$LSPCI" | gawk -F': ' '/VGA compatible controller/ { print $NF }')) GFX=($( echo "$LSPCI" | gawk -F': ' '/VGA compatible controller/ { print $NF }' ))
IFS="$OIFS" IFS="$OIFS"
for (( I=0; I < ${#GFX[@]}; I++ )) for (( I=0; I < ${#GFX[@]}; I++ ))
do do
@ -954,13 +967,15 @@ then
for ((I=1;I<${#CPU[@]}-1;I++)) for ((I=1;I<${#CPU[@]}-1;I++))
do do
IFS=","; CPUTMP=(${CPU[I]}); IFS="$OIFS" IFS=","
CPUTMP=(${CPU[I]})
IFS="$OIFS"
LNCPU=$( printf "${C1}%-${INDENT}s${C2} %s" " " "($((I+1))) ${CPUTMP[0]}" ) LNCPU=$( printf "${C1}%-${INDENT}s${C2} %s" " " "($((I+1))) ${CPUTMP[0]}" )
if [[ $VBL -ge 3 ]] if [[ $VBL -ge 3 ]]
then then
LNCPU=$(printf "%s${C2} %s %s ${C1}%s${CN}%s${C2} %s ${CN}%s" "$LNCPU" "${CPUTMP[2]}" "cache" "flags" "(" "$CPUFLAGS" ")") LNCPU=$( printf "%s${C2} %s %s ${C1}%s${CN}%s${C2} %s ${CN}%s" "$LNCPU" "${CPUTMP[2]}" "cache" "flags" "(" "$CPUFLAGS" ")" )
fi fi
LNCPU=$(printf "%s ${C1}%s${C2} ${CN}%s${C2} %s ${CN}%s" "$LNCPU" "clocked at" "[" "${CPUTMP[1]} MHz" "]") LNCPU=$( printf "%s ${C1}%s${C2} ${CN}%s${C2} %s ${CN}%s" "$LNCPU" "clocked at" "[" "${CPUTMP[1]} MHz" "]" )
say "$LNCPU" say "$LNCPU"
if [[ $I -gt 10 ]] if [[ $I -gt 10 ]]
then then
@ -981,14 +996,14 @@ then
I=1 I=1
while [[ -n ${GFX[I]} && $I -le 3 ]] while [[ -n ${GFX[I]} && $I -le 3 ]]
do do
LNGFX=$(printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}") LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}" )
say "$LNGFX" say "$LNGFX"
((I++)) (( I++ ))
done done
if [[ $VBL -ge 2 ]] if [[ $VBL -ge 2 ]]
then then
IFS=$'\n' LNNET=($(echo "$LSPCI" | gawk ' IFS=$'\n' LNNET=($( echo "$LSPCI" | gawk '
BEGIN { IGNORECASE=1 } BEGIN { IGNORECASE=1 }
/^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ { /^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ {
nic=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0) nic=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
@ -1047,26 +1062,26 @@ then
if ((X)) && ! ((MESA)) if ((X)) && ! ((MESA))
then then
LNLAST="${LNLAST}$(echo -ne " | ${C1}GLX Renderer${C2} ${GLXR}${CN} | ${C1}GLX Version${C2} ${GLXV}${CN}")" LNLAST="${LNLAST}$( echo -ne " | ${C1}GLX Renderer${C2} ${GLXR}${CN} | ${C1}GLX Version${C2} ${GLXV}${CN}" )"
if ((CRAP)) if ((CRAP))
then then
LNLAST="${LNLAST}$(echo -ne " | ${C1}Direct rendering${C2} ${GLXDR}${CN}")" LNLAST="${LNLAST}$( echo -ne " | ${C1}Direct rendering${C2} ${GLXDR}${CN}" )"
fi fi
fi fi
if [[ $RUNLVL ]] if [[ $RUNLVL ]]
then then
LNLAST="${LNLAST}$(echo -ne " | ${C1}Runlevel${C2} ${RUNLVL}${CN}")" LNLAST="${LNLAST}$( echo -ne " | ${C1}Runlevel${C2} ${RUNLVL}${CN}" )"
fi fi
if ((SHOWIRC)) if ((SHOWIRC))
then then
LNLAST="${LNLAST}$(echo -ne " | ${C1}Client${C2} ${IRC}${IRCV}${CN}")" LNLAST="${LNLAST}$( echo -ne " | ${C1}Client${C2} ${IRC}${IRCV}${CN}" )"
fi fi
LNLAST="${LNLAST}$(echo -ne " | ${C1}${MY_VERSION}")" LNLAST="${LNLAST}$( echo -ne " | ${C1}${MY_VERSION}" )"
if ((SCHEME)) if ((SCHEME))
then then
LNLAST="${LNLAST}$(echo -ne "${NORMAL}")" LNLAST="${LNLAST}$( echo -ne "${NORMAL}" )"
fi fi
say "$LNLAST" say "$LNLAST"
else # (IF VBL > 1 ... ELSE) else # (IF VBL > 1 ... ELSE)