mirror of
https://github.com/smxi/inxi.git
synced 2024-11-16 16:21:39 +00:00
more refactoring and code cleanup, it's starting to get readable now
This commit is contained in:
parent
a5dd519b0f
commit
46f05dc2fc
64
inxi
64
inxi
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
########################################################################
|
########################################################################
|
||||||
#### Script Name: inxi
|
#### Script Name: inxi
|
||||||
#### version: 0.1.6
|
#### version: 0.1.7
|
||||||
#### Date: October 27 2008
|
#### Date: October 27 2008
|
||||||
########################################################################
|
########################################################################
|
||||||
#### inxi is a fork of infobash, the original bash sys info script by locsmif
|
#### inxi is a fork of infobash, the original bash sys info script by locsmif
|
||||||
|
@ -38,7 +38,11 @@ ALLUP=0 # inxi hasn't been 'booted' yet.
|
||||||
DEBUG=0 # Set levels from 1-10
|
DEBUG=0 # Set levels from 1-10
|
||||||
DEBUG_FLOOD=0 # Debug flood override: toggle on to allow long debug output
|
DEBUG_FLOOD=0 # Debug flood override: toggle on to allow long debug output
|
||||||
DBI=0 # Debug Buffer Index, index into a debug buffer storing debug messages until infobash is 'all up'
|
DBI=0 # Debug Buffer Index, index into a debug buffer storing debug messages until infobash is 'all up'
|
||||||
((DEBUG)) || exec 2>/dev/null # Reroute all error messages to the bitbucket (if not debugging)
|
if ! ((DEBUG))
|
||||||
|
then
|
||||||
|
# Reroute all error messages to the bitbucket (if not debugging)
|
||||||
|
exec 2>/dev/null
|
||||||
|
fi
|
||||||
#((DEBUG)) && exec 2>&1 # This is for debugging konversation
|
#((DEBUG)) && exec 2>&1 # This is for debugging konversation
|
||||||
|
|
||||||
# Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$OIFS"
|
# Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$OIFS"
|
||||||
|
@ -79,18 +83,18 @@ IBSHELL=0 # Running in a shell? Defaults to false, and is determined later.
|
||||||
NO_CPU_COUNT=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
|
# 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)
|
# 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"
|
DISTROS_SECONDARY="antiX kanotix-version knoppix-version redhat-release sabayon-release sidux-version turbolinux-release zenwalk-version"
|
||||||
DIST_MAIN="gentoo-release mandrake-release redhat-release slackware-version SuSE-release"
|
DISTROS_PRIMARY="gentoo-release mandrake-release redhat-release slackware-version SuSE-release"
|
||||||
# debian_version excluded from DIST_MAIN so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
|
# debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
|
||||||
DIST_BLIST="debian_version ubuntu_version"
|
DISTROS_BLIST="debian_version ubuntu_version"
|
||||||
FL1='-' # These two determine seperators in single line output, to force irc clients not to break off sections
|
FL1='-' # These two determine seperators in single line output, to force irc clients not to break off sections
|
||||||
FL2=''
|
FL2=''
|
||||||
# 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_bans routine
|
||||||
# $'\1' gets weird results :
|
# $'\1' gets weird results :
|
||||||
# user@host $ ARR=($'\x01'"one two" three four); echo ${ARR[0]} | hd -v
|
# 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.|
|
# 00000000 01 01 6f 6e 65 20 74 77 6f 0a |..one two.|
|
||||||
NORMAL_BANS=(corporation communications technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. "(tm)" "(r)" $'\2'"\(rev ..\)")
|
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]")
|
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
|
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.
|
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
|
CRAP=0 # New parameter
|
||||||
|
@ -312,7 +316,7 @@ get_start_app()
|
||||||
;;
|
;;
|
||||||
*konversation*)
|
*konversation*)
|
||||||
KONVI=1
|
KONVI=1
|
||||||
IRCV="$($IRC -v | gawk '/Konversation:/ { for (i=2;i<=NF;i++) { if (i == NF) { print $i } else { printf $i" " } } exit }')"
|
IRCV="$( $IRC -v | gawk '/Konversation:/ { for (i=2;i<=NF;i++) { if (i == NF) { print $i } else { printf $i" " } } exit }' )"
|
||||||
T=($IRCV)
|
T=($IRCV)
|
||||||
if [[ ${T[0]} == *+* ]]; then
|
if [[ ${T[0]} == *+* ]]; then
|
||||||
# < Sho_> locsmif: The version numbers of SVN versions look like this:
|
# < Sho_> locsmif: The version numbers of SVN versions look like this:
|
||||||
|
@ -325,11 +329,14 @@ get_start_app()
|
||||||
T2="${T[0]}"
|
T2="${T[0]}"
|
||||||
fi
|
fi
|
||||||
# Remove any dots except the first, and make sure there are no trailing zeroes,
|
# Remove any dots except the first, and make sure there are no trailing zeroes,
|
||||||
T2=$(echo "$T2" | gawk '{ sub(/\./, " "); gsub(/\./, ""); sub(/ /, "."); printf("%g\n", $0) }')
|
T2=$( echo "$T2" | gawk '{ sub(/\./, " "); gsub(/\./, ""); sub(/ /, "."); printf("%g\n", $0) }' )
|
||||||
# Since Konversation 1.0, the DCOP interface has changed a bit: dcop "$DCPORT" Konversation ..etc
|
# Since Konversation 1.0, the DCOP interface has changed a bit: dcop "$DCPORT" Konversation ..etc
|
||||||
# becomes : dcop "$DCPORT" default ... or dcop "$DCPORT" irc ..etc. So we check for versions smaller
|
# becomes : dcop "$DCPORT" default ... or dcop "$DCPORT" irc ..etc. So we check for versions smaller
|
||||||
# than 1 and change the DCOP parameter/object accordingly.
|
# than 1 and change the DCOP parameter/object accordingly.
|
||||||
[[ ${T2} < 1 ]] && DCOPOBJ="Konversation"
|
if [[ ${T2} < 1 ]]
|
||||||
|
then
|
||||||
|
DCOPOBJ="Konversation"
|
||||||
|
fi
|
||||||
IRC="Konversation"
|
IRC="Konversation"
|
||||||
;;
|
;;
|
||||||
*xchat*)
|
*xchat*)
|
||||||
|
@ -344,33 +351,33 @@ get_start_app()
|
||||||
IRC="BitchX"
|
IRC="BitchX"
|
||||||
;;
|
;;
|
||||||
*ircii*)
|
*ircii*)
|
||||||
IRCV=" $($IRC -v | gawk 'NR == 1 { print $3 }')"
|
IRCV=" $( $IRC -v | gawk 'NR == 1 { print $3 }' )"
|
||||||
IRC="ircII"
|
IRC="ircII"
|
||||||
;;
|
;;
|
||||||
*gaim*)
|
*gaim*)
|
||||||
IRCV=" $($IRC -v | gawk 'NR == 1 { print $2 }')"
|
IRCV=" $( $IRC -v | gawk 'NR == 1 { print $2 }' )"
|
||||||
IRC="Gaim"
|
IRC="Gaim"
|
||||||
;;
|
;;
|
||||||
*pidgin*)
|
*pidgin*)
|
||||||
IRCV=" $($IRC -v | gawk 'NR == 1 { print $2 }')"
|
IRCV=" $( $IRC -v | gawk 'NR == 1 { print $2 }' )"
|
||||||
IRC="Pidgin"
|
IRC="Pidgin"
|
||||||
;;
|
;;
|
||||||
*weechat-curses*)
|
*weechat-curses*)
|
||||||
IRCV=" $($IRC -v)"
|
IRCV=" $( $IRC -v) "
|
||||||
IRC="Weechat"
|
IRC="Weechat"
|
||||||
;;
|
;;
|
||||||
*kvirc*)
|
*kvirc*)
|
||||||
IRCV=" $($IRC -v 2>&1 | gawk '{ for (i=2;i<=NF;i++) { if (i==NF) print $i; else printf $i" " }; exit }')"
|
IRCV=" $( $IRC -v 2>&1 | gawk '{ for (i=2;i<=NF;i++) { if (i==NF) print $i; else printf $i" " }; exit }' )"
|
||||||
IRC="KVIrc"
|
IRC="KVIrc"
|
||||||
;;
|
;;
|
||||||
*kopete*)
|
*kopete*)
|
||||||
IRCV=" $(kopete -v | gawk '/Kopete:/ { print $2; exit }')"
|
IRCV=" $( kopete -v | gawk '/Kopete:/ { print $2; exit }' )"
|
||||||
IRC="Kopete"
|
IRC="Kopete"
|
||||||
;;
|
;;
|
||||||
*perl*)
|
*perl*)
|
||||||
unset IRCV # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
|
unset IRCV # KSirc is one of the possibilities now. KSirc is a wrapper around dsirc, a perl client
|
||||||
get_cmdline $PPID
|
get_cmdline $PPID
|
||||||
for ((I=0; I<=$CMDLMAX; I++))
|
for (( I=0; I<=$CMDLMAX; I++ ))
|
||||||
do
|
do
|
||||||
case ${CMDL[I]} in
|
case ${CMDL[I]} in
|
||||||
*dsirc*)
|
*dsirc*)
|
||||||
|
@ -383,7 +390,7 @@ get_start_app()
|
||||||
# You can imagine how hosed I am if I try to make infobash find out dynamically with which path
|
# 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 was run by browsing up the process tree in /proc. That alone is straightjacket material.
|
||||||
# (KSirc sucks anyway ;)
|
# (KSirc sucks anyway ;)
|
||||||
IRCV=" $(ksirc -v | gawk '/KSirc:/ { print $2; exit }')"
|
IRCV=" $( ksirc -v | gawk '/KSirc:/ { print $2; exit }' )"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -524,8 +531,8 @@ PATH="${PATH}${TPATH}"
|
||||||
check_script_depends
|
check_script_depends
|
||||||
|
|
||||||
# Do this after sourcing of config overrides so user can customize banwords
|
# Do this after sourcing of config overrides so user can customize banwords
|
||||||
NORMAL_BANS=$(make_bans "${NORMAL_BANS[@]}") # Contrary to my previous belief, "${ARR[@]}" passes a quoted list, not one string
|
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[@]}")
|
CPU_BANS=$( make_bans "${CPU_BANS[@]}" )
|
||||||
##echo "NORMAL_BANS='$NORMAL_BANS'"
|
##echo "NORMAL_BANS='$NORMAL_BANS'"
|
||||||
|
|
||||||
LSPCI=$(lspci -v | awk '{ gsub(/\(prog-if[^)]*\)/,""); print }')
|
LSPCI=$(lspci -v | awk '{ gsub(/\(prog-if[^)]*\)/,""); print }')
|
||||||
|
@ -580,7 +587,7 @@ then
|
||||||
DISTFILE="${DISTGLOB}"
|
DISTFILE="${DISTGLOB}"
|
||||||
elif (( ${#DISTGLOB[@]} > 1 ))
|
elif (( ${#DISTGLOB[@]} > 1 ))
|
||||||
then
|
then
|
||||||
for I in $DIST_DERIV $DIST_MAIN
|
for I in $DISTROS_SECONDARY $DISTROS_PRIMARY
|
||||||
do
|
do
|
||||||
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
|
# Only echo works with ${var[@]}, not print_screen_output() or script_debugger()
|
||||||
# This is a known bug, search for the word "strange" inside comments
|
# This is a known bug, search for the word "strange" inside comments
|
||||||
|
@ -592,7 +599,7 @@ then
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ -n "$DISTFILE" -a -s /etc/$DISTFILE -a " $DIST_BLIST " != *" $DISTFILE "* ]
|
if [ -n "$DISTFILE" -a -s /etc/$DISTFILE -a " $DISTROS_BLIST " != *" $DISTFILE "* ]
|
||||||
then
|
then
|
||||||
DISTRO=$( eat "/etc/$DISTFILE" )
|
DISTRO=$( eat "/etc/$DISTFILE" )
|
||||||
else
|
else
|
||||||
|
@ -650,14 +657,14 @@ END {
|
||||||
' /proc/cpuinfo))
|
' /proc/cpuinfo))
|
||||||
IFS="$OIFS"
|
IFS="$OIFS"
|
||||||
|
|
||||||
for ((I=0;I<${#CPU[@]}-1;I++))
|
for (( I=0; I < ${#CPU[@]} - 1; I++))
|
||||||
do
|
do
|
||||||
IFS=","; CPUTMP=(${CPU[I]}); IFS="$OIFS"
|
IFS=","; CPUTMP=(${CPU[I]}); IFS="$OIFS"
|
||||||
unset CPU[I]
|
unset CPU[I]
|
||||||
CPUTMP[0]=$( sanitize NORMAL_BANS "${CPUTMP[0]}" )
|
CPUTMP[0]=$( sanitize NORMAL_BANS "${CPUTMP[0]}" )
|
||||||
CPUTMP[0]=$( sanitize CPU_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.
|
# 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++ ))
|
for (( J=0; J < ${#CPUTMP[@]}; J++ ))
|
||||||
do
|
do
|
||||||
if ((J))
|
if ((J))
|
||||||
then
|
then
|
||||||
|
@ -745,7 +752,7 @@ do
|
||||||
CAP=0
|
CAP=0
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
((CAP+=$(eat $I/capacity)))
|
(( CAP+=$( eat $I/capacity ) ))
|
||||||
HDDMOD="${HDDMOD}${HDDMOD+,}$(eat $I/model)"
|
HDDMOD="${HDDMOD}${HDDMOD+,}$(eat $I/model)"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -847,7 +854,7 @@ if ((X))
|
||||||
then
|
then
|
||||||
# Added the two ?'s , because the resolution is now reported without spaces around the 'x', as in
|
# Added the two ?'s , because the resolution is now reported without spaces around the 'x', as in
|
||||||
# 1400x1050 instead of 1400 x 1050. Change as of X.org version 1.3.0
|
# 1400x1050 instead of 1400 x 1050. Change as of X.org version 1.3.0
|
||||||
RES=$(xrandr | gawk '
|
RES=$( xrandr | gawk '
|
||||||
/\*/ { res[++m] = gensub(/^.* ([0-9]+) ?x ?([0-9]+)[_ ].* ([0-9\.]+)\*.*$/,"\\1x\\2@\\3hz","g",$0) }
|
/\*/ { res[++m] = gensub(/^.* ([0-9]+) ?x ?([0-9]+)[_ ].* ([0-9\.]+)\*.*$/,"\\1x\\2@\\3hz","g",$0) }
|
||||||
END {
|
END {
|
||||||
for (n in res) {
|
for (n in res) {
|
||||||
|
@ -857,7 +864,8 @@ then
|
||||||
if (line)
|
if (line)
|
||||||
print(line)
|
print(line)
|
||||||
}
|
}
|
||||||
')
|
' )
|
||||||
|
|
||||||
if [[ -z $RES ]]
|
if [[ -z $RES ]]
|
||||||
then
|
then
|
||||||
RES=$( xdpyinfo | gawk '/dimensions/ { print $2 }' )
|
RES=$( xdpyinfo | gawk '/dimensions/ { print $2 }' )
|
||||||
|
|
Loading…
Reference in a new issue