code refactoring

This commit is contained in:
inxi-svn 2008-10-28 02:14:34 +00:00
parent fa66c967b5
commit ef7ac17e39

90
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 0.1.3
#### version: 0.1.4
#### Date: October 27 2008
########################################################################
#### inxi is a fork of infobash, the original bash sys info script by locsmif
@ -118,21 +118,21 @@ fi
########################################################################
# inxi speaks through here. When run by Konversation, use DCOP
say()
print_screen_output()
{
if (( DEBUG > 5 ))
then
if ((KONVI))
then
dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "konvi='$konvi' saying : '$@'"
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "konvi='$konvi' saying : '$@'"
else
echo "konvi='$konvi' saying : '$@'"
fi
fi
#((KONVI)) && dcop $DCPORT Konversation say $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n"
#((KONVI)) && dcop $DCPORT Konversation print_screen_output $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n"
if (( KONVI ))
then
dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$1"
dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "$1"
else
echo -ne "$1\n"
fi
@ -143,29 +143,29 @@ error()
{
case $1 in
2)
say "$SCRIPT_NAME: large flood danger, debug buffer full!"
print_screen_output "$SCRIPT_NAME: large flood danger, debug buffer full!"
;;
3)
say "$SCRIPT_NAME: error in colorscheme, or unknown parameter: $2"
print_screen_output "$SCRIPT_NAME: error in colorscheme, or unknown parameter: $2"
;;
4)
say "$SCRIPT_NAME: unknown verbosity level $2"
print_screen_output "$SCRIPT_NAME: unknown verbosity level $2"
;;
5)
say "$SCRIPT_NAME: dependency not met: $2 not found in path"
print_screen_output "$SCRIPT_NAME: dependency not met: $2 not found in path"
;;
6)
say "$SCRIPT_NAME: /proc not found! Quitting..."
print_screen_output "$SCRIPT_NAME: /proc not found! Quitting..."
;;
*)
say "$SCRIPT_NAME: error unknown: $@"
print_screen_output "$SCRIPT_NAME: error unknown: $@"
set -- 99
;;
esac
exit $1
}
dbg()
debug_script()
{
if (( ALLUP ))
then
@ -177,11 +177,11 @@ dbg()
then
for (( DBI=0; DBI < ${#DBGBUF[@]}; DBI++ ))
do
say "${DBGBUF[DBI]}"
print_screen_output "${DBGBUF[DBI]}"
done
DBI=0
fi
say "$@"
print_screen_output "$@"
else
if ((!DEBUG_FLOOD && DBI>10))
then
@ -208,7 +208,7 @@ checkdepend()
then
for I in xrandr xdpyinfo glxinfo
do
type -p $I >/dev/null || { dbg "inxi: Resuming in non X mode: $I not found in path"; X=0; break; }
type -p $I >/dev/null || { debug_script "inxi: Resuming in non X mode: $I not found in path"; X=0; break; }
done
fi
@ -273,15 +273,15 @@ getcmdline()
then
{ echo 0; return; }
fi
##say "Marker"
##say "\$1='$1' -=- $(< /proc/$1/cmdline)"
##print_screen_output "Marker"
##print_screen_output "\$1='$1' -=- $(< /proc/$1/cmdline)"
local I=0
unset CMDL
while read -d $'\0' L && [[ $I -lt 32 ]]
do
CMDL[I++]="$L"
done </proc/$1/cmdline
##say "\$I='$I'"
##print_screen_output "\$I='$I'"
if ! ((I))
then
CMDL[0]=$(< /proc/$1/cmdline)
@ -442,21 +442,21 @@ get_parameters()
echo "$VBL" | grep -q '^[1-3]$' || error 4 "$VBL"
;;
-U)
say "Updating $SCRIPT_NAME now..."
print_screen_output "Updating $SCRIPT_NAME now..."
wget -O $SCRIPT_PATH/$SCRIPT_NAME http://techpatterns.com/downloads/distro/$SCRIPT_NAME
say "To run the new version, just start $SCRIPT_NAME again."
print_screen_output "To run the new version, just start $SCRIPT_NAME again."
exit 0
;;
--version)
say "InfoBash, the universal, portable, system info script for irc."
say "Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,"
say "Gaim/Pidgin, Weechat, KVIrc and Kopete."
say "Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif <infobash@rebelhomicide.demon.nl>"
say " "
say "This program is free software; you can redistribute it and/or modify"
say "it under the terms of the GNU General Public License as published by"
say "the Free Software Foundation; either version 3 of the License, or"
say "(at your option) any later version."
print_screen_output "InfoBash, the universal, portable, system info script for irc."
print_screen_output "Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,"
print_screen_output "Gaim/Pidgin, Weechat, KVIrc and Kopete."
print_screen_output "Copyright (C) 2005-2007 Michiel de Boer a.k.a. locsmif <infobash@rebelhomicide.demon.nl>"
print_screen_output " "
print_screen_output "This program is free software; you can redistribute it and/or modify"
print_screen_output "it under the terms of the GNU General Public License as published by"
print_screen_output "the Free Software Foundation; either version 3 of the License, or"
print_screen_output "(at your option) any later version."
exit 0
;;
*)
@ -558,7 +558,7 @@ then
fi
ALLUP=1
dbg "ALLUP=1 : inxi up and running.."
debug_script "ALLUP=1 : inxi up and running.."
HN=$(hostname)
@ -575,7 +575,7 @@ elif (( ${#DISTGLOB[@]} > 1 ))
then
for I in $DIST_DERIV $DIST_MAIN
do
# Only echo works with ${var[@]}, not say() or dbg()
# Only echo works with ${var[@]}, not print_screen_output() or debug_script()
# This is a known bug, search for the word "strange" inside comments
# echo "I='$I' DISTGLOB[@]='${DISTGLOB[@]}'"
if [[ " ${DISTGLOB[@]} " == *" $I "* ]]
@ -774,7 +774,7 @@ then
done
fi
##say "$HDDMOD" ; exit
##print_screen_output "$HDDMOD" ; exit
if ((CAP))
then
HDDCAP1="$((CAP/2))"
@ -782,7 +782,7 @@ 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 )
##say "HDDCAP1=\"$HDDCAP1\" HDDCAP2=\"$HDDCAP2"" ; exit
##print_screen_output "HDDCAP1=\"$HDDCAP1\" HDDCAP2=\"$HDDCAP2"" ; exit
HDD=0
for I in ${!HDDCAP*}
do
@ -934,16 +934,16 @@ then
LNINTRO=$(printf "${C1}%-${INDENT}s${C2} " "OS/Kernel")
fi
LNINTRO="$LNINTRO$(echo -ne "${C2}$OSKERN ${CN}[ ${C1}$DISTRO ${CN}]")"
say "$LNINTRO"
print_screen_output "$LNINTRO"
##say "CPU[0]=\"${CPU[0]}\""
##print_screen_output "CPU[0]=\"${CPU[0]}\""
IFS=","; CPUTMP=(${CPU[0]}); IFS="$OIFS"
# Strange (and also some expected) behavior encountered.
# If say() uses $1 as the parameter to output to the screen, then passing "<text1> ${ARR[@]} <text2>"
# If print_screen_output() uses $1 as the parameter to output to the screen, then passing "<text1> ${ARR[@]} <text2>"
# will output only <text1> and the first element of ARR. That "@" splits in elements and "*" _doesn't_, is to be expected.
# However, that text2 is consecutively truncated is somewhat strange, so take note. This has been confirmed by #bash on freenode.
# The above mentioned only emerges when using the debugging markers below
##say "CPUTMP=\"***${CPUTMP[@]} $HN+++++++\"----------"
##print_screen_output "CPUTMP=\"***${CPUTMP[@]} $HN+++++++\"----------"
if [[ -z ${CPUTMP[2]} ]]
then
@ -963,7 +963,7 @@ then
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" "]")
say "$LNCPU"
print_screen_output "$LNCPU"
for ((I=1;I<${#CPU[@]}-1;I++))
do
@ -976,7 +976,7 @@ then
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" "]" )
say "$LNCPU"
print_screen_output "$LNCPU"
if [[ $I -gt 10 ]]
then
break
@ -992,12 +992,12 @@ then
LNGFX="${LNGFX}$(echo -ne "${C1} tty resolution ${CN}(${C2} ${RES} ${CN})")"
fi
say "$LNGFX"
print_screen_output "$LNGFX"
I=1
while [[ -n ${GFX[I]} && $I -le 3 ]]
do
LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}" )
say "$LNGFX"
print_screen_output "$LNGFX"
(( I++ ))
done
@ -1043,10 +1043,10 @@ then
if [[ -n ${LNNET[@]} ]]
then
I=0
say "$(printf "${C1}%-${INDENT}s${C2} %s" "Network cards" "${LNNET[I]}")"
print_screen_output "$(printf "${C1}%-${INDENT}s${C2} %s" "Network cards" "${LNNET[I]}")"
while [[ -n ${LNNET[++I]} ]]
do
say "$(printf "${C1}%-${INDENT}s${C2} %s" " " "${LNNET[I]}")"
print_screen_output "$(printf "${C1}%-${INDENT}s${C2} %s" " " "${LNNET[I]}")"
done
fi
fi
@ -1083,7 +1083,7 @@ then
then
LNLAST="${LNLAST}$( echo -ne "${NORMAL}" )"
fi
say "$LNLAST"
print_screen_output "$LNLAST"
else # (IF VBL > 1 ... ELSE)
#cscheme 12
if ! ((IBSHELL))
@ -1095,7 +1095,7 @@ else # (IF VBL > 1 ... ELSE)
LNSHORT=$(echo -ne "${C1}CPU${CN}[${C2}${CPUMODEL} clocked at ${CPUCLOCK}${CN}] ${C1}Kernel${CN}[${C2}${OSKERN}${CN}] ${C1}Up${CN}[${C2}${FL2}${FL1}${UPT}${FL1}${CN}] ${C1}Mem${CN}[${C2}${FL2}${FL1}${MEM}${FL1}${CN}] ${C1}HDD${CN}[${C2}${FL2}${FL1}${HDD}($HDDUSG)${FL1}${CN}] ${C1}Procs${CN}[${C2}${FL2}${FL1}${PROC}${FL1}${CN}]")
((SHOWIRC)) && LNSHORT="${LNSHORT}$(echo -ne " ${C1}Client${CN}[${C2}${IRC}${IRCV}${CN}]")"
((SCHEME)) && LNSHORT="${LNSHORT}$(echo -ne "$NORMAL")"
say "$LNSHORT"
print_screen_output "$LNSHORT"
fi # (IF VBL > 1)
if ((IBSHELL && SCHEME))