From b06b4a07c764918027965c0ff5570720288ded8a Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Thu, 30 Oct 2008 17:18:02 +0000 Subject: [PATCH] Changed all cases of: if [ .....] then or elif [....] then to use the hanging then turd method: if [....];then This will be the standard style for inxi All other flow controls will be on their own lines, ie: do done { } --- inxi | 240 ++++++++++++++++++++--------------------------------------- 1 file changed, 81 insertions(+), 159 deletions(-) diff --git a/inxi b/inxi index 251b08e..a77a211 100755 --- a/inxi +++ b/inxi @@ -1,8 +1,8 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 0.1.49 -#### Date: October 29 2008 +#### version: 0.1.50 +#### Date: October 30 2008 ######################################################################## #### inxi is a fork of infobash, the original bash sys info script by locsmif #### As time permits functionality and recoding will occur. @@ -44,7 +44,7 @@ A_DISTRO_GLOB='' IRC_CLIENT='' IRC_CLIENT_VERSION='' X_VENDOR='' -X_NUMBER='' +X_VER_NUM='' ## primary data array holders A_CPU_DATA='' @@ -132,13 +132,11 @@ A_NORMAL_BANS=( corporation communications gmbh technologies technology group $' A_CPU_BANS=( cpu processor $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" ) ## Source global config overrides -if [ -s /etc/$SCRIPT_NAME.conf ] -then +if [ -s /etc/$SCRIPT_NAME.conf ];then source /etc/$SCRIPT_NAME.conf fi # Source user config overrides -if [ -s $HOME/.$SCRIPT_NAME ] -then +if [ -s $HOME/.$SCRIPT_NAME ];then source $HOME/.$SCRIPT_NAME fi @@ -187,14 +185,11 @@ error_handler() script_debugger() { - if [ "$ALLUP" -gt 0 ] - then - if [ "$DEBUG" -eq 0 ] - then + if [ "$ALLUP" -gt 0 ];then + if [ "$DEBUG" -eq 0 ];then return fi - if ((DBI)) - then + if ((DBI));then for (( DBI=0; DBI < ${#DBGBUF[@]}; DBI++ )) do print_screen_output "${DBGBUF[DBI]}" @@ -203,8 +198,7 @@ script_debugger() fi print_screen_output "$@" else - if ((!DEBUG_FLOOD && DBI > 10)) - then + if ((!DEBUG_FLOOD && DBI > 10));then error_handler 2 fi DBGBUF[DBI++]="$@" @@ -221,10 +215,8 @@ script_debugger() # but that only works if infobash is being run as a konversation script to begin with print_screen_output() { - if [ "$DEBUG" -gt 5 ] - then - if [ "$KONVI" -eq 1 ] - then + if [ "$DEBUG" -gt 5 ];then + if [ "$KONVI" -eq 1 ];then dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "konvi='$KONVI' saying : '$@'" else echo "konvi='$KONVI' saying : '$@'" @@ -234,8 +226,7 @@ print_screen_output() fi #((KONVI)) && dcop $DCPORT Konversation print_screen_output $DCSERVER "$DCTARGET" "$1" || echo -ne "$1\n" - if [ "$KONVI" -eq 1 ] - then + if [ "$KONVI" -eq 1 ];then dcop "$DCPORT" "$DCOPOBJ" print_screen_output "$DCSERVER" "$DCTARGET" "$1" else echo -ne "$1\n" @@ -285,13 +276,11 @@ check_script_depends() { local app_name='' - if [ ! -d /proc/ ] - then + if [ ! -d /proc/ ];then error_handler 6 fi - if [ "$X" -gt 0 ] - then + if [ "$X" -gt 0 ];then for app_name in xrandr xdpyinfo glxinfo do type -p $app_name >/dev/null || { script_debugger "inxi: Resuming in non X mode: $app_name not found in path"; X=0; break; } @@ -314,8 +303,7 @@ make_bans() for BANSTR do #echo "BANSTR=\"$BANSTR\"" >&2 - if [[ ${BANSTR:0:1} = $'\2' ]] - then + if [[ ${BANSTR:0:1} = $'\2' ]];then MKBANS="${MKBANS}${MKBANS+|}${BANSTR:1:${#BANSTR}-1}" else # Automatically escapes [ ] ( ) . and + @@ -331,13 +319,11 @@ set_color_scheme() { local i='' script_colors='' color_codes='' - if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]] - then + if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]];then set -- 1 fi SCHEME="$1" # Set a global variable to allow checking for chosen scheme later - if [ "$IBSHELL" -gt 0 ] - then + if [ "$IBSHELL" -gt 0 ];then color_codes=($ANSI_COLORS) else color_codes=($IRC_COLORS) @@ -360,8 +346,7 @@ get_cmdline() { local i=0 - if [ ! -e /proc/$1/cmdline ] - then + if [ ! -e /proc/$1/cmdline ];then { echo 0; return; } fi ##print_screen_output "Marker" @@ -372,11 +357,9 @@ get_cmdline() CMDL[i++]="$L" ## note: make sure this is valid ## done &1 ;; -v|-v[0-9]|--verbose) - if [[ ${#1} -eq 3 ]] - then + if [[ ${#1} -eq 3 ]];then VERBOSITY_LEVEL="${1:2}" else - if [[ $2 = --* || $2 = -* || -z $2 ]] - then + if [[ $2 = --* || $2 = -* || -z $2 ]];then VERBOSITY_LEVEL=1 else shift @@ -429,8 +410,7 @@ get_parameters() # these will need to be converted to standard type options echo "$1" | grep -q '^[0-9][0-9]\?$' || error_handler 3 "$1" COLOR_SCHEME_SET='true' - if [ -z "$COLOR_SCHEME" ] - then + if [ -z "$COLOR_SCHEME" ];then set_color_scheme "$1" fi ;; @@ -492,18 +472,15 @@ get_start_source() { local irc_client_path='' irc_client_path_lower='' non_native_konvi='' i='' - if tty >/dev/null - then + if tty >/dev/null;then IRC_CLIENT="Shell" unset IRC_CLIENT_VERSION IBSHELL=1 - elif [ -n "$PPID" -a -f "/proc/$PPID/exe" ] - then + elif [ -n "$PPID" -a -f "/proc/$PPID/exe" ];then irc_client_path=$( readlink /proc/$PPID/exe ) # this handles the problem with konversation reporting itself as perl, which was missed because # when konversation starts infobash from inside itself, as a script, the parent is konversation, not perl - if [ -z "$( grep -i 'konversation' <<< $irc_client_path )" -a -n "$( grep -i 'perl' <<< $irc_client_path )" -a -n "$( pidof konversation )" ] - then + if [ -z "$( grep -i 'konversation' <<< $irc_client_path )" -a -n "$( grep -i 'perl' <<< $irc_client_path )" -a -n "$( pidof konversation )" ];then irc_client_path=$( which konversation ) non_native_konvi='true' fi @@ -516,16 +493,14 @@ get_start_source() ;; *konversation*) # this is necessary to avoid the dcop errors from starting inxi as a /cmd started script - if [ "$non_native_konvi" == 'true' ] - then + if [ "$non_native_konvi" == 'true' ];then KONVI=2 else KONVI=1 fi IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '/Konversation:/ { for (i=2;i<=NF;i++) { if (i == NF) { print $i } else { printf $i" " } } exit }' )" T=($IRC_CLIENT_VERSION) - if [[ ${T[0]} == *+* ]] - then + if [[ ${T[0]} == *+* ]];then # < Sho_> locsmif: The version numbers of SVN versions look like this: # "+ #' | tr '\n' ' ')) - if [ -z "$CPUFLAGS" ] - then + if [ -z "$CPUFLAGS" ];then CPUFLAGS="-" fi } @@ -827,25 +792,21 @@ get_distro_data() cd "$OLDPWD" shopt -u nullglob - if (( ${#A_DISTRO_GLOB[@]} == 1 )) - then + if (( ${#A_DISTRO_GLOB[@]} == 1 ));then DISTRO_FILE="${A_DISTRO_GLOB}" - elif (( ${#A_DISTRO_GLOB[@]} > 1 )) - then + elif (( ${#A_DISTRO_GLOB[@]} > 1 ));then for i in $DISTROS_DERIVED $DISTROS_PRIMARY do # 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' A_DISTRO_GLOB[@]='${A_DISTRO_GLOB[@]}'" - if [[ " ${A_DISTRO_GLOB[@]} " == *" $i "* ]] - then + if [[ " ${A_DISTRO_GLOB[@]} " == *" $i "* ]];then DISTRO_FILE="${i}" break fi done fi - if [ -n "$DISTRO_FILE" -a -s /etc/$DISTRO_FILE -a " $DISTROS_BLIST " != *" $DISTRO_FILE "* ] - then + if [ -n "$DISTRO_FILE" -a -s /etc/$DISTRO_FILE -a " $DISTROS_BLIST " != *" $DISTRO_FILE "* ];then DISTRO=$( remove_erroneous_chars "/etc/$DISTRO_FILE" ) else # Debian pure should fall through here @@ -855,8 +816,7 @@ get_distro_data() gsub(/^ +| +$/,""); print }' "/etc/${DISTRO_FILE}" ) fi - if (( ${#DISTRO} > 80 && ! CRAP )) - then + if (( ${#DISTRO} > 80 && ! CRAP ));then DISTRO="${RED}/etc/${DISTRO_FILE} corrupted, use --crap to override${NORMAL}" fi ## note: figure out a more readable way to achieve whatever is intended here ## @@ -877,8 +837,7 @@ get_graphics_data() # GFXMEM is UNUSED at the moment, because it shows AGP aperture size, which is not necessarily equal to GFX memory.. # GFXMEM="size=[$(echo "$LSPCI" | gawk '/VGA/{while (!/^$/) {getline;if (/size=[0-9][0-9]*M/) {size2=gensub(/.*\[size=([0-9]+)M\].*/,"\\1","g",$0);if (size 0 { print(gensub(/(.*)_agp.*/,"\\1","g",$1)) }' /proc/modules) @@ -985,11 +941,9 @@ get_hard_drive_data() for disk in /proc/ide/ide*/hd* do - if [[ -e $disk/media && $( remove_erroneous_chars $disk/media ) = disk ]] - then + if [[ -e $disk/media && $( remove_erroneous_chars $disk/media ) = disk ]];then # BUGFIX: Ran into a debian sarge kernel that did not have the "capacity" file in the hd* directories - if [[ ! -e $disk/capacity ]] - then + if [[ ! -e $disk/capacity ]];then CAP=0 break fi @@ -998,8 +952,7 @@ get_hard_drive_data() fi done - if [[ -e /proc/scsi/scsi ]] - then + if [[ -e /proc/scsi/scsi ]];then # Silly sata detection, will also pick up usb sticks, and it is all I will put into infobash. if you want more, infoperl is on # the way :) IFS=$'\n' @@ -1031,8 +984,7 @@ get_hard_drive_data() fi ##print_screen_output "$HDDMOD" ; exit - if ((CAP)) - then + if ((CAP));then HDDCAP1="$((CAP/2))" fi # See http://lanana.org/docs/device-list/devices-2.6+.txt for major numbers used below @@ -1042,13 +994,11 @@ get_hard_drive_data() HDD=0 for i in ${!HDDCAP*} do - if [[ ${!i} -gt $HDD ]] - then + if [[ ${!i} -gt $HDD ]];then HDD="${!i}" fi done - if [ "$HDD" -gt 0 ] - then + if [ "$HDD" -gt 0 ];then HDDUSG=$( df | gawk ' p { if (/^\/dev\/(mapper\/|[hs]d[a-z][0-9]+)/) { @@ -1151,21 +1101,18 @@ print_cpu_data() # The above mentioned only emerges when using the debugging markers below ##print_screen_output "a_cpu_working=\"***${a_cpu_working[@]} $hostName+++++++\"----------" - if [[ -z ${a_cpu_working[2]} ]] - then + if [[ -z ${a_cpu_working[2]} ]];then a_cpu_working[2]="unknown" fi - if [[ ${#A_CPU_DATA[@]} -gt 2 ]] - then + if [[ ${#A_CPU_DATA[@]} -gt 2 ]];then cpu_number="${C1}(1)${C2} " else # Array CPU always has one element: max clockfreq found. Therefore -gt and not -ge unset cpu_number fi cpu_data=$( create_print_line "CPU:" "${cpu_number}${a_cpu_working[0]}" ) - if [ "$VERBOSITY_LEVEL" -ge 3 ] - then + if [ "$VERBOSITY_LEVEL" -ge 3 ];then cpu_data="$cpu_data${C2} ${a_cpu_working[2]} cache${C2} ${C1}flags${C2} ($CPUFLAGS)${CN}" fi cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]} MHz${CN}" @@ -1177,14 +1124,12 @@ print_cpu_data() a_cpu_working=(${A_CPU_DATA[i]}) IFS="$OIFS" cpu_data=$( create_print_line " " "${C1}($(( i + 1 )))${C2} ${a_cpu_working[0]}" ) - if [ "$VERBOSITY_LEVEL" -ge 3 ] - then + if [ "$VERBOSITY_LEVEL" -ge 3 ];then cpu_data="$cpu_data${C2} ${a_cpu_working[2]} cache${C2} ${C1}flags${C2} ($CPUFLAGS)${CN}" fi cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]} MHz${CN}" print_screen_output "$cpu_data" - if [ "$i" -gt 10 ] - then + if [ "$i" -gt 10 ];then break fi done @@ -1194,8 +1139,7 @@ print_gfx_data() { local gfx_data='' i='' card_one='Card ' - if [[ ${#A_GFX_DATA[@]} -gt 1 ]] - then + if [[ ${#A_GFX_DATA[@]} -gt 1 ]];then i=1 while [[ -n ${A_GFX_DATA[i]} && $i -le 3 ]] do @@ -1206,20 +1150,16 @@ print_gfx_data() fi gfx_data=$( create_print_line "Graphics:" "${C1}$card_one${C2}${A_GFX_DATA[0]}${gfx_data}" ) - if [ "$X" -gt 0 ] - then + if [ "$X" -gt 0 ];then gfx_data="${gfx_data} ${CN}| ${C1}$X_VENDOR${C2} $X_VER_NUM ${CN}| ${C1}Res${C2} ${RES}" else gfx_data="${gfx_data} ${C1} tty resolution ${CN}(${C2} ${RES} ${CN})" fi print_screen_output "$gfx_data" -# echo x$X m$MESA -# echo GLXR$GLXR GLXV$GLXV - if [ "$X" -gt 0 -a "$MESA" -eq 0 ] - then + + if [ "$X" -gt 0 -a "$MESA" -eq 0 ];then gfx_data=$( create_print_line " " "${C1}GLX Renderer${C2} ${GLXR} ${CN}| ${C1}GLX Version${C2} ${GLXV}${CN}" ) - if [ "$CRAP" -gt 0 ] - then + if [ "$CRAP" -gt 0 ];then gfx_data="${gfx_data} ${C1}Direct rendering${C2} ${GLXDR}${CN}" fi print_screen_output "$gfx_data" @@ -1232,16 +1172,14 @@ print_hard_disk_data() local root_home_data="$( df -h -T | egrep '(/|/boot|/var|/home)$' | C1=${C1} C2=${C2} awk '{print ENVIRON["C1"]"Partition:"ENVIRON["C2"], $7, ENVIRON["C1"]"- ", ENVIRON["C1"]"size:"ENVIRON["C2"], $3, ENVIRON["C1"]"used:"ENVIRON["C2"], $4, "(", $6, ")"}' )" root_home_data=$( echo $root_home_data ) - if [ "$VERBOSITY_LEVEL" -ge 2 ] - then + if [ "$VERBOSITY_LEVEL" -ge 2 ];then hdd_data=$( create_print_line "Disks:" "${C1}HDD${C2} ${HDDMOD} ${C1}Size${C2} ${HDD} (${HDDUSG})${CN}" ) else hdd_data=$( create_print_line "Disks:" "${C1}HDD Size${C2} ${HDD} (${HDDUSG})${CN}" ) fi print_screen_output "$hdd_data" - if [ "$VERBOSITY_LEVEL" -ge 4 ] - then + if [ "$VERBOSITY_LEVEL" -ge 4 ];then hdd_data=$( create_print_line " " "${root_home_data}" ) print_screen_output "$hdd_data" fi @@ -1251,8 +1189,7 @@ print_intro_data() { local intro_data='' host_name=$( hostname ) - if [ "$SHOW_HOST" -gt 0 ] - then + if [ "$SHOW_HOST" -gt 0 ];then intro_data=$( create_print_line "System:" "${C1}Host${C2} $host_name ${C1}running${C2} ${CN}" ) else intro_data=$( create_print_line "System:" "${C1}running${C2} ${CN}" ) @@ -1265,10 +1202,8 @@ print_networking_data() { local i='' card_plural='s' card_one='Card-1 ' network_data='' - if [[ -n ${A_NETWORK_DATA[@]} ]] - then - if [[ ${#A_NETWORK_DATA[@]} -le 1 ]] - then + if [[ -n ${A_NETWORK_DATA[@]} ]];then + if [[ ${#A_NETWORK_DATA[@]} -le 1 ]];then card_plural='' card_one='' fi @@ -1288,8 +1223,7 @@ print_short_data() local short_data='' i='' #set_color_scheme 12 - if [ "$IBSHELL" -eq 0 ] - then + if [ "$IBSHELL" -eq 0 ];then for i in $C1 $C2 $CN do case "$i" in @@ -1297,12 +1231,10 @@ print_short_data() ;; esac done - if [ "$BGBLACK" -gt 0 ] - then + if [ "$BGBLACK" -gt 0 ];then for i in C1 C2 CN do - if [[ "${!i}" = "$NORMAL" ]] - then + if [[ "${!i}" = "$NORMAL" ]];then declare $i="${!i}15,1" else declare $i="${!i},1" @@ -1311,15 +1243,13 @@ print_short_data() #C1="${C1},1"; C2="${C2},1"; CN="${CN},1" fi fi - short_data="${C1}CPU${CN}[${C2}${CPUMODEL} clocked at ${CPUCLOCK}${CN}] ${C1}Kernel${CN}[${C2}${CURRENT_KERNEL}${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}]" + short_data="${C1}CPU${CN}[${C2}${CPUMODEL} clocked at ${CPUCLOCK}${CN}] ${C1}Kernel${CN}[${C2}${CURRENT_KERNEL}${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}]" - if [ "$SHOW_IRC" -gt 0 ] - then + if [ "$SHOW_IRC" -gt 0 ];then short_data="${short_data} ${C1}Client${CN}[${C2}${IRC_CLIENT}${IRC_CLIENT_VERSION}${CN}]" fi short_data="${short_data} ${CN}:: ${C1}$SCRIPT_NAME ${C2}v:$SCRIPT_VERSION_NUMBER${CN}" - if [ "$SCHEME" -gt 0 ] - then + if [ "$SCHEME" -gt 0 ];then short_data="${short_data} $NORMAL" fi print_screen_output "$short_data" @@ -1333,19 +1263,16 @@ print_system_data() # long_last=$( echo -ne "${C1}Processes${C2} ${PROC}${CN} | ${C1}Uptime${C2} ${UPT}${CN} | ${C1}Memory${C2} ${MEM}${CN}" ) system_data=$( create_print_line "Info:" "${C1}Processes${C2} ${PROC} ${CN}| ${C1}Uptime${C2} ${UPT} ${CN}| ${C1}Memory${C2} ${MEM}${CN}" ) - if [ "$RUNLVL" -gt 0 ] - then + if [ "$RUNLVL" -gt 0 ];then system_data="${system_data} ${CN}| ${C1}Runlevel${C2} ${RUNLVL}${CN}" fi - if [ "$SHOW_IRC" -gt 0 ] - then + if [ "$SHOW_IRC" -gt 0 ];then system_data="${system_data} ${CN}| ${C1}Client${C2} ${IRC_CLIENT}${IRC_CLIENT_VERSION}${CN}" fi system_data="${system_data} ${CN}| ${C1}$SCRIPT_NAME ${C2}v:$SCRIPT_VERSION_NUMBER${CN}" - if [ "$SCHEME" -gt 0 ] - then + if [ "$SCHEME" -gt 0 ];then system_data="${system_data} ${NORMAL}" fi print_screen_output "$system_data" @@ -1362,8 +1289,7 @@ print_it_out() print_cpu_data print_gfx_data - if [ "$VERBOSITY_LEVEL" -ge 2 ] - then + if [ "$VERBOSITY_LEVEL" -ge 2 ];then print_networking_data fi @@ -1384,8 +1310,7 @@ get_start_source # note: this only works if it's run from inside konversation as a script builtin or something # only do this if inxi has been started as a konversation script, otherwise bypass this -if [ "$KONVI" -eq 1 ] -then +if [ "$KONVI" -eq 1 ];then DCPORT="$1" DCSERVER="$2" DCTARGET="$3" @@ -1395,8 +1320,7 @@ then IFS=":" for kde_config in $( kde-config --path data ) do - if [[ -r ${kde_config}${KONVI_CFG} ]] - then + if [[ -r ${kde_config}${KONVI_CFG} ]];then source "${kde_config}${KONVI_CFG}" break fi @@ -1411,8 +1335,7 @@ fi get_parameters "$@" # If no colorscheme was set in the parameter handling routine, then set the default scheme -if [ "$COLOR_SCHEME_SET" != 'true' ] -then +if [ "$COLOR_SCHEME_SET" != 'true' ];then set_color_scheme "$DEFAULT_SCHEME" fi @@ -1432,8 +1355,7 @@ get_graphics_data print_it_out ## last steps -if [ "$IBSHELL" -gt 0 -a "$SCHEME" -gt 0 ] -then +if [ "$IBSHELL" -gt 0 -a "$SCHEME" -gt 0 ];then echo -n "" fi