mirror of
https://github.com/smxi/inxi.git
synced 2024-11-16 16:21:39 +00:00
more refactoring
This commit is contained in:
parent
ef7ac17e39
commit
04674b0e72
92
inxi
92
inxi
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
########################################################################
|
||||
#### Script Name: inxi
|
||||
#### version: 0.1.4
|
||||
#### version: 0.1.5
|
||||
#### Date: October 27 2008
|
||||
########################################################################
|
||||
#### inxi is a fork of infobash, the original bash sys info script by locsmif
|
||||
|
@ -70,13 +70,13 @@ IRCCL=" $IRCCL \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 \x0300
|
|||
COLORS=(DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL)
|
||||
# See above for notes on EMPTY
|
||||
SCHEMES=(EMPTY,EMPTY,EMPTY NORMAL,NORMAL,NORMAL BLUE,NORMAL,NORMAL GREEN,YELLOW,NORMAL DYELLOW,NORMAL,NORMAL CYAN,BLUE,NORMAL RED,NORMAL,NORMAL GREEN,NORMAL,NORMAL YELLOW,NORMAL,NORMAL GREEN,DGREEN,NORMAL BLUE,RED,NORMAL BLUE,NORMAL,RED YELLOW,WHITE,GREEN BLUE,NORMAL,GREEN DCYAN,NORMAL,DMAGENTA)
|
||||
DEFSCHEME=2 # Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Set to any other valid scheme you like. Same as runtime parameter.
|
||||
SHOWHOST=1 # Set this to 0 to avoid printing the hostname
|
||||
SHOWIRC=2 # SHOWIRC=1 to avoid showing the irc client version number, or SHOWIRC=0 to disable client information completely.
|
||||
DEFAULT_SCHEME=2 # Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Set to any other valid scheme you like. Same as runtime parameter.
|
||||
SHOW_HOST=1 # Set this to 0 to avoid printing the hostname
|
||||
SHOW_IRC=2 # SHOW_IRC=1 to avoid showing the irc client version number, or SHOW_IRC=0 to disable client information completely.
|
||||
INDENT=14 # Default indentation level
|
||||
VBL=0 # Verbosity level defaults to 0, this can also be set with -v, -v2, -v3, etc as a parameter.
|
||||
IBSHELL=0 # Running in a shell? Defaults to false, and is determined later.
|
||||
NOCPUCOUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
|
||||
NO_CPU_COUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
|
||||
# In cases of derived distros where the version file of the base distro can also be found under /etc, the derived distro's
|
||||
# version file should go first. (Such as with Sabayon / Gentoo)
|
||||
DIST_DERIV="antiX kanotix-version knoppix-version redhat-release sabayon-release sidux-version turbolinux-release zenwalk-version"
|
||||
|
@ -85,14 +85,14 @@ DIST_MAIN="gentoo-release mandrake-release redhat-release slackware-version SuSE
|
|||
DIST_BLIST="debian_version ubuntu_version"
|
||||
FL1='-' # These two determine seperators in single line output, to force irc clients not to break off sections
|
||||
FL2=''
|
||||
# Precede a banword with $'\2' to prevent it from being subject to automated escaping by the mkbans routine
|
||||
# Precede a banword with $'\2' to prevent it from being subject to automated escaping by the make_bans routine
|
||||
# $'\1' gets weird results :
|
||||
# user@host $ ARR=($'\x01'"one two" three four); echo ${ARR[0]} | hd -v
|
||||
# 00000000 01 01 6f 6e 65 20 74 77 6f 0a |..one two.|
|
||||
NORMALBANS=(corporation communications technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. "(tm)" "(r)" $'\2'"\(rev ..\)")
|
||||
CPUBANS=(cpu processor $'\2'"[0-9.]+ *[MmGg][Hh][Zz]")
|
||||
XPATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" # Extra path variable to make execute failures less likely, merged below
|
||||
PARAMLIMIT=30 # This is a variable that controls how many parameters infobash will parse in a /proc/<pid>/cmdline file before stopping.
|
||||
NORMAL_BANS=(corporation communications technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. "(tm)" "(r)" $'\2'"\(rev ..\)")
|
||||
CPU_BANS=(cpu processor $'\2'"[0-9.]+ *[MmGg][Hh][Zz]")
|
||||
X_PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" # Extra path variable to make execute failures less likely, merged below
|
||||
PARAMETER_LIMIT=30 # This is a variable that controls how many parameters infobash will parse in a /proc/<pid>/cmdline file before stopping.
|
||||
CRAP=0 # New parameter
|
||||
FLAG=0 # A throw-away 'flag' variable intended to be used throughout infobash
|
||||
KONVICFG="konversation/scripts/$SCRIPT_LOWER_CASE.conf" # relative path to $(kde-config --path data)
|
||||
|
@ -139,7 +139,7 @@ print_screen_output()
|
|||
}
|
||||
|
||||
# Error handling
|
||||
error()
|
||||
error_handler()
|
||||
{
|
||||
case $1 in
|
||||
2)
|
||||
|
@ -165,7 +165,7 @@ error()
|
|||
exit $1
|
||||
}
|
||||
|
||||
debug_script()
|
||||
script_debugger()
|
||||
{
|
||||
if (( ALLUP ))
|
||||
then
|
||||
|
@ -185,7 +185,7 @@ debug_script()
|
|||
else
|
||||
if ((!DEBUG_FLOOD && DBI>10))
|
||||
then
|
||||
error 2
|
||||
error_handler 2
|
||||
fi
|
||||
DBGBUF[DBI++]="$@"
|
||||
fi
|
||||
|
@ -197,30 +197,30 @@ eat()
|
|||
}
|
||||
|
||||
# Determine if any of the absolutely necessary tools are absent
|
||||
checkdepend()
|
||||
check_script_depends()
|
||||
{
|
||||
if [ ! -d /proc/ ]
|
||||
then
|
||||
error 6
|
||||
error_handler 6
|
||||
fi
|
||||
|
||||
if ((X))
|
||||
then
|
||||
for I in xrandr xdpyinfo glxinfo
|
||||
do
|
||||
type -p $I >/dev/null || { debug_script "inxi: Resuming in non X mode: $I not found in path"; X=0; break; }
|
||||
type -p $I >/dev/null || { script_debugger "inxi: Resuming in non X mode: $I not found in path"; X=0; break; }
|
||||
done
|
||||
fi
|
||||
|
||||
# bc removed from deps for now
|
||||
for I in df free gawk grep hostname lspci ps readlink runlevel tr uname uptime wc
|
||||
do
|
||||
type -p $I >/dev/null || error 5 "$I"
|
||||
type -p $I >/dev/null || error_handler 5 "$I"
|
||||
done
|
||||
}
|
||||
|
||||
# Filter boilerplate & buzzwords.
|
||||
mkbans()
|
||||
make_bans()
|
||||
{
|
||||
unset MKBANS
|
||||
# Iterate over $@
|
||||
|
@ -240,7 +240,7 @@ mkbans()
|
|||
|
||||
# Set the colorscheme
|
||||
# $1 = <scheme number>|<"none">
|
||||
cscheme()
|
||||
set_color_scheme()
|
||||
{
|
||||
local I SCOLORS CLCODES
|
||||
|
||||
|
@ -267,7 +267,7 @@ cscheme()
|
|||
}
|
||||
|
||||
# Parse the null separated commandline under /proc/<pid passed in $1>/cmdline
|
||||
getcmdline()
|
||||
get_cmdline()
|
||||
{
|
||||
if [[ ! -e /proc/$1/cmdline ]]
|
||||
then
|
||||
|
@ -291,7 +291,7 @@ getcmdline()
|
|||
}
|
||||
|
||||
# Determine where infobash was run from
|
||||
roots()
|
||||
get_start_app()
|
||||
{
|
||||
if tty >/dev/null
|
||||
then
|
||||
|
@ -366,7 +366,7 @@ roots()
|
|||
;;
|
||||
*perl*)
|
||||
unset IRCV # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
|
||||
getcmdline $PPID
|
||||
get_cmdline $PPID
|
||||
for ((I=0; I<=$CMDLMAX; I++))
|
||||
do
|
||||
case ${CMDL[I]} in
|
||||
|
@ -399,7 +399,7 @@ roots()
|
|||
unset IRCV
|
||||
;;
|
||||
esac
|
||||
if [[ $SHOWIRC -lt 2 ]]
|
||||
if [[ $SHOW_IRC -lt 2 ]]
|
||||
then
|
||||
unset IRCV
|
||||
fi
|
||||
|
@ -439,7 +439,7 @@ get_parameters()
|
|||
VBL="$1"
|
||||
fi
|
||||
fi
|
||||
echo "$VBL" | grep -q '^[1-3]$' || error 4 "$VBL"
|
||||
echo "$VBL" | grep -q '^[1-3]$' || error_handler 4 "$VBL"
|
||||
;;
|
||||
-U)
|
||||
print_screen_output "Updating $SCRIPT_NAME now..."
|
||||
|
@ -460,10 +460,10 @@ get_parameters()
|
|||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "$1" | grep -q '^[0-9][0-9]\?$' || error 3 "$1"
|
||||
echo "$1" | grep -q '^[0-9][0-9]\?$' || error_handler 3 "$1"
|
||||
if ! ((CSCHEME))
|
||||
then
|
||||
cscheme "$1"
|
||||
set_color_scheme "$1"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
@ -489,11 +489,11 @@ then
|
|||
X=1
|
||||
fi
|
||||
|
||||
# Fallback paths put into $XPATH; This might, among others, help on gentoo.
|
||||
# Now, create a difference of $PATH and $XPATH and add that to $PATH:
|
||||
# Fallback paths put into $X_PATH; This might, among others, help on gentoo.
|
||||
# Now, create a difference of $PATH and $X_PATH and add that to $PATH:
|
||||
unset TPATH
|
||||
IFS=":"
|
||||
for I in $XPATH
|
||||
for I in $X_PATH
|
||||
do
|
||||
FLAG=0
|
||||
for J in $PATH
|
||||
|
@ -514,19 +514,19 @@ PATH="${PATH}${TPATH}"
|
|||
##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
|
||||
|
||||
# Check for dependencies before running any commands in this script! So yes, here!!
|
||||
checkdepend
|
||||
check_script_depends
|
||||
|
||||
# Do this after sourcing of config overrides so user can customize banwords
|
||||
NORMALBANS=$(mkbans "${NORMALBANS[@]}") # Contrary to my previous belief, "${ARR[@]}" passes a quoted list, not one string
|
||||
CPUBANS=$(mkbans "${CPUBANS[@]}")
|
||||
##echo "NORMALBANS='$NORMALBANS'"
|
||||
NORMAL_BANS=$(make_bans "${NORMAL_BANS[@]}") # Contrary to my previous belief, "${ARR[@]}" passes a quoted list, not one string
|
||||
CPU_BANS=$(make_bans "${CPU_BANS[@]}")
|
||||
##echo "NORMAL_BANS='$NORMAL_BANS'"
|
||||
|
||||
LSPCI=$(lspci -v | awk '{ gsub(/\(prog-if[^)]*\)/,""); print }')
|
||||
########################################################################
|
||||
#### MAIN FUNCTIONS
|
||||
########################################################################
|
||||
|
||||
roots
|
||||
get_start_app
|
||||
|
||||
if ((KONVI))
|
||||
then
|
||||
|
@ -554,11 +554,11 @@ get_parameters "$@"
|
|||
# If no colorscheme was set in the parameter handling routine, then set the default scheme
|
||||
if ! ((CSCHEME))
|
||||
then
|
||||
cscheme "$DEFSCHEME"
|
||||
set_color_scheme "$DEFAULT_SCHEME"
|
||||
fi
|
||||
|
||||
ALLUP=1
|
||||
debug_script "ALLUP=1 : inxi up and running.."
|
||||
script_debugger "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 print_screen_output() or debug_script()
|
||||
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
|
||||
# This is a known bug, search for the word "strange" inside comments
|
||||
# echo "I='$I' DISTGLOB[@]='${DISTGLOB[@]}'"
|
||||
if [[ " ${DISTGLOB[@]} " == *" $I "* ]]
|
||||
|
@ -647,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 NORMAL_BANS "${CPUTMP[0]}" )
|
||||
CPUTMP[0]=$( sanitize CPU_BANS "${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
|
||||
|
@ -663,7 +663,7 @@ done
|
|||
|
||||
if echo "${CPU[@]}" | grep -qi 'dual\|triple\|quad'
|
||||
then
|
||||
NOCPUCOUNT=1
|
||||
NO_CPU_COUNT=1
|
||||
else
|
||||
case $(( ${#CPU[@]}-1 )) in
|
||||
2)
|
||||
|
@ -830,7 +830,7 @@ GFX=($( echo "$LSPCI" | gawk -F': ' '/VGA compatible controller/ { print $NF }'
|
|||
IFS="$OIFS"
|
||||
for (( I=0; I < ${#GFX[@]}; I++ ))
|
||||
do
|
||||
GFX[I]=$( sanitize NORMALBANS "${GFX[I]}" )
|
||||
GFX[I]=$( sanitize NORMAL_BANS "${GFX[I]}" )
|
||||
done
|
||||
|
||||
# GFXMEM is UNUSED at the moment, because it shows AGP aperture size, which is not necessarily equal to GFX memory..
|
||||
|
@ -927,7 +927,7 @@ fi
|
|||
# (IF VBL > 1)
|
||||
if ((VBL))
|
||||
then
|
||||
if ((SHOWHOST))
|
||||
if ((SHOW_HOST))
|
||||
then
|
||||
LNINTRO=$(printf "${C1}%-${INDENT}s${C2} \"%s\"${C1} %s " "Host/Kernel/OS" "$HN" "running")
|
||||
else
|
||||
|
@ -1010,7 +1010,7 @@ then
|
|||
gsub(/realtek semiconductor/, "Realtek", nic)
|
||||
gsub(/davicom semiconductor/, "Davicom", nic)
|
||||
gsub(/,/," ", nic)
|
||||
gsub(/'"$NORMALBANS"'/, "", nic); gsub(/ [ ]+/," ", nic); gsub(/^ +| +$/,"", nic)
|
||||
gsub(/'"$NORMAL_BANS"'/, "", nic); gsub(/ [ ]+/," ", nic); gsub(/^ +| +$/,"", nic)
|
||||
# The doublequotes above are necessary because of the pipes in the variable.
|
||||
eth[nic]++
|
||||
while (getline && !/^$/) {
|
||||
|
@ -1074,7 +1074,7 @@ then
|
|||
LNLAST="${LNLAST}$( echo -ne " | ${C1}Runlevel${C2} ${RUNLVL}${CN}" )"
|
||||
fi
|
||||
|
||||
if ((SHOWIRC))
|
||||
if ((SHOW_IRC))
|
||||
then
|
||||
LNLAST="${LNLAST}$( echo -ne " | ${C1}Client${C2} ${IRC}${IRCV}${CN}" )"
|
||||
fi
|
||||
|
@ -1085,7 +1085,7 @@ then
|
|||
fi
|
||||
print_screen_output "$LNLAST"
|
||||
else # (IF VBL > 1 ... ELSE)
|
||||
#cscheme 12
|
||||
#set_color_scheme 12
|
||||
if ! ((IBSHELL))
|
||||
then
|
||||
for I in $C1 $C2 $CN ; do case "$I" in "$GREEN"|"$WHITE"|"$YELLOW"|"$CYAN") BGBLACK=1 ;; esac ; done
|
||||
|
@ -1093,7 +1093,7 @@ else # (IF VBL > 1 ... ELSE)
|
|||
#C1="${C1},1"; C2="${C2},1"; CN="${CN},1"
|
||||
fi
|
||||
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}]")"
|
||||
((SHOW_IRC)) && LNSHORT="${LNSHORT}$(echo -ne " ${C1}Client${CN}[${C2}${IRC}${IRCV}${CN}]")"
|
||||
((SCHEME)) && LNSHORT="${LNSHORT}$(echo -ne "$NORMAL")"
|
||||
print_screen_output "$LNSHORT"
|
||||
fi # (IF VBL > 1)
|
||||
|
|
Loading…
Reference in a new issue