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
########################################################################
#### Script Name: inxi
#### version: 0.1.2
#### version: 0.1.3
#### Date: October 27 2008
########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif
@ -243,6 +243,7 @@ mkbans()
cscheme()
{
local I SCOLORS CLCODES
if [[ $1 -ge ${#SCHEMES[@]} ]]
then
set -- 1
@ -254,7 +255,7 @@ cscheme()
else
CLCODES=($IRCCL)
fi
for ((I=0;I<${#COLORS[@]};I++))
for (( I=0; I < ${#COLORS[@]}; I++ ))
do
eval "${COLORS[I]}=\"${CLCODES[I]}\""
done
@ -366,24 +367,28 @@ roots()
*perl*)
unset IRCV # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
getcmdline $PPID
for ((I=0; I<=$CMDLMAX; I++)); do
for ((I=0; I<=$CMDLMAX; I++))
do
case ${CMDL[I]} in
*dsirc*)
IRC="KSirc"
# 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
# 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,
# 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
# KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material.
# (KSirc sucks anyway ;)
IRCV=" $(ksirc -v | gawk '/KSirc:/ { print $2; exit }')"
break
;;
*dsirc*)
IRC="KSirc"
# 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
# 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,
# 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
# KSirc was run by browsing up the process tree in /proc. That alone is straightjacket material.
# (KSirc sucks anyway ;)
IRCV=" $(ksirc -v | gawk '/KSirc:/ { print $2; exit }')"
break
;;
esac
done
[[ -z $IRCV ]] && IRC="Unknown Perl client"
if [[ -z $IRCV ]]
then
IRC="Unknown Perl client"
fi
;;
*bash*|*sh*)
unset IRCV
@ -405,7 +410,7 @@ roots()
}
# Get the parameters
getparams()
get_parameters()
{
if [[ -z $1 ]]
then
@ -456,7 +461,10 @@ getparams()
;;
*)
echo "$1" | grep -q '^[0-9][0-9]\?$' || error 3 "$1"
((CSCHEME)) || cscheme "$1"
if ! ((CSCHEME))
then
cscheme "$1"
fi
;;
esac
shift
@ -541,7 +549,7 @@ then
fi
# "$@" 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 ! ((CSCHEME))
@ -560,10 +568,10 @@ cd /etc; DISTGLOB=(*[-_]{release,version})
cd "$OLDPWD"
shopt -u nullglob
if ((${#DISTGLOB[@]} == 1))
if (( ${#DISTGLOB[@]} == 1 ))
then
DISTFILE="${DISTGLOB}"
elif ((${#DISTGLOB[@]} > 1))
elif (( ${#DISTGLOB[@]} > 1 ))
then
for I in $DIST_DERIV $DIST_MAIN
do
@ -579,16 +587,16 @@ then
fi
if [ -n "$DISTFILE" -a -s /etc/$DISTFILE -a " $DIST_BLIST " != *" $DISTFILE "* ]
then
DISTRO=$(eat "/etc/$DISTFILE")
DISTRO=$( eat "/etc/$DISTFILE" )
else
# Debian pure should fall through here
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
((${#DISTRO} > 80 && ! CRAP)) && DISTRO="${RED}/etc/${DISTFILE} corrupted, use --crap to override${NORMAL}"
: ${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'
CPU=($(gawk -F': ' '
@ -639,8 +647,8 @@ for ((I=0;I<${#CPU[@]}-1;I++))
do
IFS=","; CPUTMP=(${CPU[I]}); IFS="$OIFS"
unset CPU[I]
CPUTMP[0]=$(sanitize NORMALBANS "${CPUTMP[0]}")
CPUTMP[0]=$(sanitize CPUBANS "${CPUTMP[0]}")
CPUTMP[0]=$( sanitize NORMALBANS "${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.
for (( J=0; J<${#CPUTMP[@]}; J++ ))
do
@ -657,7 +665,7 @@ if echo "${CPU[@]}" | grep -qi 'dual\|triple\|quad'
then
NOCPUCOUNT=1
else
case $((${#CPU[@]}-1)) in
case $(( ${#CPU[@]}-1 )) in
2)
CPU2="Dual"
;;
@ -681,8 +689,8 @@ CPUTMP=(${CPU[0]})
IFS="$OIFS"
# For the short line
CPUMODEL="${CPU2}${CPU2+ }${CPUTMP[0]}" # clocked at [${CPU[${#CPU[@]}-1]}]" # old CPU2
CPUCLOCK="${CPU[${#CPU[@]}-1]}" # old CPU3
CPUFLAGS="${CPUTMP[3]}" # old CPU4
CPUCLOCK="${CPU[${#CPU[@]}-1]}" # old CPU3
CPUFLAGS="${CPUTMP[3]}" # old CPU4
# nx = AMD stack protection extensions
# lm = Intel 64bit 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' ' '))
[[ -z $CPUFLAGS ]] && CPUFLAGS="-"
if [[ -z $CPUFLAGS ]]
then
CPUFLAGS="-"
fi
for I in /proc/ide/ide*/hd*
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]}"
done
fi
@ -767,7 +780,7 @@ then
HDDCAP1="$((CAP/2))"
fi
# 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
HDD=0
@ -809,11 +822,11 @@ END {
printf("%.1f/%.1fMB\n", used/1024, tot/1024)
}' /proc/meminfo)
PROC="$(($(ps aux | wc -l)-1))"
UPT=$(uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }')
PROC="$(( $( ps aux | wc -l ) - 1 ))"
UPT=$( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }' )
IFS=$'\n'
GFX=($(echo "$LSPCI" | gawk -F': ' '/VGA compatible controller/ { print $NF }'))
GFX=($( echo "$LSPCI" | gawk -F': ' '/VGA compatible controller/ { print $NF }' ))
IFS="$OIFS"
for (( I=0; I < ${#GFX[@]}; I++ ))
do
@ -954,13 +967,15 @@ then
for ((I=1;I<${#CPU[@]}-1;I++))
do
IFS=","; CPUTMP=(${CPU[I]}); IFS="$OIFS"
IFS=","
CPUTMP=(${CPU[I]})
IFS="$OIFS"
LNCPU=$( printf "${C1}%-${INDENT}s${C2} %s" " " "($((I+1))) ${CPUTMP[0]}" )
if [[ $VBL -ge 3 ]]
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
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"
if [[ $I -gt 10 ]]
then
@ -981,14 +996,14 @@ then
I=1
while [[ -n ${GFX[I]} && $I -le 3 ]]
do
LNGFX=$(printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}")
LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}" )
say "$LNGFX"
((I++))
(( I++ ))
done
if [[ $VBL -ge 2 ]]
then
IFS=$'\n' LNNET=($(echo "$LSPCI" | gawk '
IFS=$'\n' LNNET=($( echo "$LSPCI" | gawk '
BEGIN { IGNORECASE=1 }
/^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ {
nic=gensub(/^[0-9a-f:.]+ [^:]+: (.+)$/,"\\1","g",$0)
@ -1047,26 +1062,26 @@ then
if ((X)) && ! ((MESA))
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))
then
LNLAST="${LNLAST}$(echo -ne " | ${C1}Direct rendering${C2} ${GLXDR}${CN}")"
LNLAST="${LNLAST}$( echo -ne " | ${C1}Direct rendering${C2} ${GLXDR}${CN}" )"
fi
fi
if [[ $RUNLVL ]]
then
LNLAST="${LNLAST}$(echo -ne " | ${C1}Runlevel${C2} ${RUNLVL}${CN}")"
LNLAST="${LNLAST}$( echo -ne " | ${C1}Runlevel${C2} ${RUNLVL}${CN}" )"
fi
if ((SHOWIRC))
then
LNLAST="${LNLAST}$(echo -ne " | ${C1}Client${C2} ${IRC}${IRCV}${CN}")"
LNLAST="${LNLAST}$( echo -ne " | ${C1}Client${C2} ${IRC}${IRCV}${CN}" )"
fi
LNLAST="${LNLAST}$(echo -ne " | ${C1}${MY_VERSION}")"
LNLAST="${LNLAST}$( echo -ne " | ${C1}${MY_VERSION}" )"
if ((SCHEME))
then
LNLAST="${LNLAST}$(echo -ne "${NORMAL}")"
LNLAST="${LNLAST}$( echo -ne "${NORMAL}" )"
fi
say "$LNLAST"
else # (IF VBL > 1 ... ELSE)