From 3912580aadaa8ca4717cd1210dc43ec523f1ebd3 Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Fri, 31 Oct 2008 20:20:44 +0000 Subject: [PATCH] lots of cleanup, refactored more --- inxi | 190 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 110 insertions(+), 80 deletions(-) diff --git a/inxi b/inxi index c27197f..0a56503 100755 --- a/inxi +++ b/inxi @@ -1,8 +1,8 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 0.2.15 -#### Date: October 30 2008 +#### version: 0.2.16 +#### Date: October 31 2008 ######################################################################## #### inxi is a fork of infobash, the original bash sys info script by locsmif #### As time permits functionality and recoding will occur. @@ -40,23 +40,22 @@ ######################################################################## ### Variable initializations: null values + +CMDL_MAX='' COLOR_SCHEME_SET='' COLOR_SCHEME='' CPU_MODEL='' CPU_CLOCK='' CPU_FLAGS='' -HDD_CAPACITY='' -#: note: if this is declared, whatever string you want inserted will be inserted first -## in this case, it's desirable to print out (x) before each driver found. -HDD_MODEL='' -HDD_USED='' IRC_CLIENT='' IRC_CLIENT_VERSION='' ### primary data array holders +A_CMDL='' A_CPU_DATA='' A_GFX_CARD_DATA='' A_GLX_DATA='' +A_HDD_DATA='' A_NETWORK_DATA='' A_X_DATA='' @@ -64,20 +63,29 @@ A_X_DATA='' # Running in a shell? Defaults to false, and is determined later. B_RUNNING_IN_SHELL='false' # Set this to 'false' to avoid printing the hostname -B_SHOW_HOST='true' +B_SHOW_HOST='true' +# Assume X not running until tests show it is B_X_RUNNING='false' ### Variable initializations: constants # inxi hasn't been 'booted' yet. -ALLUP=0 +ALL_UP=0 # New parameter CRAP=0 -# Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up' -DBI=0 + DCOPOBJ="default" DEBUG=0 # Set debug levels from 1-10 +# Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up' +DEBUG_BUFFER_INDEX=0 # Debug flood override: toggle on to allow long debug output DEBUG_FLOOD=0 +### Reroute all error messages to the bitbucket (if not debugging) +if [ "$DEBUG" -eq 0 ] +then + exec 2>/dev/null +fi +#((DEBUG)) && exec 2>&1 # This is for debugging konversation + # 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. DEFAULT_SCHEME=2 @@ -87,7 +95,6 @@ FLAG=0 INDENT=10 # default to false, no konversation found, 1 is /cmd inxi start, 2 is native konvi script mode KONVI=0 -LSPCI=$( lspci -v | awk '{ gsub(/\(prog-if[^)]*\)/,""); print }' ) # NO_CPU_COUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups. # This is a variable that controls how many parameters inxi will parse in a /proc//cmdline file before stopping. PARAMETER_LIMIT=30 @@ -99,13 +106,6 @@ VERBOSITY_LEVEL=0 # Supported number of verbosity levels VERBOSITY_LEVELS=4 -### Reroute all error messages to the bitbucket (if not debugging) -if [ "$DEBUG" -eq 0 ] -then - exec 2>/dev/null -fi -#((DEBUG)) && exec 2>&1 # This is for debugging konversation - # Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$OIFS" # type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and # therefore results in nothing. Tricky as fuck. @@ -120,7 +120,6 @@ FL2='' SCRIPT_NAME="inxi" SCRIPT_PATH=$( dirname $0 ) SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | awk '{print $3}' ) -SCRIPT_DATE=$( grep -im 1 'date:' $SCRIPT_PATH/$SCRIPT_NAME | awk '{print $3 " " $4 ", " $5}' ) KONVI_CFG="konversation/scripts/$SCRIPT_NAME.conf" # relative path to $(kde-config --path data) ### Script Localization @@ -141,6 +140,10 @@ IRC_COLORS=" $IRC_COLORS \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL ) # See above for notes on EMPTY A_COLOR_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 ) +## Actual color variables +C1='' +C2='' +CN='' ### Distro Data # In cases of derived distros where the version file of the base distro can also be found under /etc, @@ -151,7 +154,7 @@ DISTROS_PRIMARY="gentoo-release mandrake-release redhat-release slackware-versio DISTROS_BLIST="debian_version ubuntu_version" ### Bans Data -# Precede a banword with $'\2' to prevent it from being subject to automated escaping by the make_bans routine +# Precede a banword with $'\2' to prevent it from being subject to automated escaping by the make_ban_lists 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.| @@ -220,23 +223,25 @@ error_handler() script_debugger() { - if [ "$ALLUP" -gt 0 ];then + local a_debug_buffer='' + + if [ "$ALL_UP" -gt 0 ];then if [ "$DEBUG" -eq 0 ];then return fi - if ((DBI));then - for (( DBI=0; DBI < ${#DBGBUF[@]}; DBI++ )) + if ((DEBUG_BUFFER_INDEX));then + for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#a_debug_buffer[@]}; DEBUG_BUFFER_INDEX++ )) do - print_screen_output "${DBGBUF[DBI]}" + print_screen_output "${a_debug_buffer[DEBUG_BUFFER_INDEX]}" done - DBI=0 + DEBUG_BUFFER_INDEX=0 fi print_screen_output "$@" else - if ((!DEBUG_FLOOD && DBI > 10));then + if ((!DEBUG_FLOOD && DEBUG_BUFFER_INDEX > 10));then error_handler 2 fi - DBGBUF[DBI++]="$@" + a_debug_buffer[DEBUG_BUFFER_INDEX++]="$@" fi } @@ -278,6 +283,7 @@ create_print_line() } # this removes newline and pipes. +# args: $1 - string to clean remove_erroneous_chars() { ## RS is input record separator @@ -292,6 +298,7 @@ remove_erroneous_chars() } # Enforce boilerplate and buzzword filters +# args: $1 - A_NORMAL_BANS/A_CPU_BANS; $2 - string to sanitize sanitize_characters() { # Cannot use strong quotes to unquote a string with pipes in it! @@ -332,25 +339,29 @@ check_script_depends() } # Filter boilerplate & buzzwords. -make_bans() +# args: $1 - quoted: "$@" array of ban terms +make_ban_lists() { - unset MKBANS - # Iterate over $@ - for BANSTR + local ban_list='' + # Iterate over $@ + ## note: this is a weird, non-intuitive method, needs some documentation or rewriting + ## if you declare ban_string it stops working, have to read up on this + for ban_string do - #echo "BANSTR=\"$BANSTR\"" >&2 - if [[ ${BANSTR:0:1} = $'\2' ]];then - MKBANS="${MKBANS}${MKBANS+|}${BANSTR:1:${#BANSTR}-1}" + # echo "term=\"$ban_string\"" # >&2 + if [[ ${ban_string:0:1} = $'\2' ]];then + ban_list="${ban_list}${ban_list+|}${ban_string:1:${#ban_string}-1}" else # Automatically escapes [ ] ( ) . and + - MKBANS="${MKBANS}${MKBANS+|}$(echo "$BANSTR" | gawk '{ gsub(/([\[\]+().])/,"\\\\&"); print }')" + ban_list="${ban_list}${ban_list+|}$( echo "$ban_string" | gawk '{ gsub(/([\[\]+().])/,"\\\\&"); print }' )" fi done - echo "$MKBANS" + + echo "$ban_list" } - +# make_ban_lists "${A_CPU_BANS[@]}";exit # Set the colorscheme -# $1 = |<"none"> +# args: $1 = |<"none"> set_color_scheme() { local i='' script_colors='' color_codes='' @@ -378,31 +389,34 @@ set_color_scheme() } # Parse the null separated commandline under /proc//cmdline +# args: $1 - $PPID get_cmdline() { - local i=0 + local i=0 ppid=$1 - if [ ! -e /proc/$1/cmdline ];then + if [ ! -e /proc/$ppid/cmdline ];then { echo 0; return; } fi ##print_screen_output "Marker" - ##print_screen_output "\$1='$1' -=- $(< /proc/$1/cmdline)" - unset CMDL + ##print_screen_output "\$ppid='$ppid' -=- $(< /proc/$ppid/cmdline)" + unset A_CMDL + ## note: need to figure this one out, and ideally clean it up and make it readable while read -d $'\0' L && [ "$i" -lt 32 ] do - CMDL[i++]="$L" ## note: make sure this is valid ## - done