mirror of
https://github.com/smxi/inxi.git
synced 2024-11-16 16:21:39 +00:00
refactored into primary data get and print functions
This commit is contained in:
parent
862eb60967
commit
af2a1da5db
207
inxi
207
inxi
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
########################################################################
|
########################################################################
|
||||||
#### Script Name: inxi
|
#### Script Name: inxi
|
||||||
#### version: 0.1.11
|
#### version: 0.1.20
|
||||||
#### 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
|
||||||
|
@ -563,10 +563,8 @@ set_konvi()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# temp function to contain all script core engine pieces until they are broken into real functions
|
get_distro_data()
|
||||||
main_temp_engine()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
unset DISTRO
|
unset DISTRO
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
cd /etc
|
cd /etc
|
||||||
|
@ -601,7 +599,10 @@ else
|
||||||
fi
|
fi
|
||||||
((${#DISTRO} > 80 && ! CRAP)) && DISTRO="${RED}/etc/${DISTFILE} corrupted, use --crap to override${NORMAL}"
|
((${#DISTRO} > 80 && ! CRAP)) && DISTRO="${RED}/etc/${DISTFILE} corrupted, use --crap to override${NORMAL}"
|
||||||
: ${DISTRO:=Unknown distro o_O}
|
: ${DISTRO:=Unknown distro o_O}
|
||||||
|
}
|
||||||
|
|
||||||
|
get_cpu_data()
|
||||||
|
{
|
||||||
OSKERN=$( uname -a | gawk '{print $1,$3,$(NF-1)}' )
|
OSKERN=$( uname -a | gawk '{print $1,$3,$(NF-1)}' )
|
||||||
|
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
@ -733,7 +734,10 @@ if [[ -z $CPUFLAGS ]]
|
||||||
then
|
then
|
||||||
CPUFLAGS="-"
|
CPUFLAGS="-"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_hard_drive_data()
|
||||||
|
{
|
||||||
for I in /proc/ide/ide*/hd*
|
for I in /proc/ide/ide*/hd*
|
||||||
do
|
do
|
||||||
if [[ -e $I/media && $(eat $I/media) = disk ]]
|
if [[ -e $I/media && $(eat $I/media) = disk ]]
|
||||||
|
@ -820,7 +824,10 @@ else
|
||||||
unset HDDUSG
|
unset HDDUSG
|
||||||
HDD="unknown.."
|
HDD="unknown.."
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_memory_data()
|
||||||
|
{
|
||||||
MEM=$( gawk '
|
MEM=$( gawk '
|
||||||
/^MemTotal:/ { tot = $2 }
|
/^MemTotal:/ { tot = $2 }
|
||||||
/^(MemFree|Buffers|Cached):/ { notused+=$2 }
|
/^(MemFree|Buffers|Cached):/ { notused+=$2 }
|
||||||
|
@ -828,10 +835,16 @@ END {
|
||||||
used = tot-notused
|
used = tot-notused
|
||||||
printf("%.1f/%.1fMB\n", used/1024, tot/1024)
|
printf("%.1f/%.1fMB\n", used/1024, tot/1024)
|
||||||
}' /proc/meminfo )
|
}' /proc/meminfo )
|
||||||
|
}
|
||||||
|
|
||||||
|
get_processes_uptime()
|
||||||
|
{
|
||||||
PROC="$(( $( ps aux | wc -l ) - 1 ))"
|
PROC="$(( $( ps aux | wc -l ) - 1 ))"
|
||||||
UPT=$( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }' )
|
UPT=$( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); gsub(/ /,"",a); print a }' )
|
||||||
|
}
|
||||||
|
|
||||||
|
get_graphics_data()
|
||||||
|
{
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
GFX=($( echo "$LSPCI" | gawk -F': ' '/VGA compatible controller/ { print $NF }' ))
|
GFX=($( echo "$LSPCI" | gawk -F': ' '/VGA compatible controller/ { print $NF }' ))
|
||||||
IFS="$OIFS"
|
IFS="$OIFS"
|
||||||
|
@ -943,87 +956,10 @@ else
|
||||||
RES=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{ print $2"x"$1 }' )
|
RES=$( stty -F $( readlink /proc/$PPID/fd/0 ) size | gawk '{ print $2"x"$1 }' )
|
||||||
RUNLVL=$( runlevel | gawk '{ print $2 }' )
|
RUNLVL=$( runlevel | gawk '{ print $2 }' )
|
||||||
fi
|
fi
|
||||||
# (IF VERBOSITY_LEVEL > 1)
|
}
|
||||||
if ((VERBOSITY_LEVEL))
|
|
||||||
then
|
|
||||||
if ((SHOW_HOST))
|
|
||||||
then
|
|
||||||
LNINTRO=$( printf "${C1}%-${INDENT}s${C2} \"%s\"${C1} %s " "Host/Kernel/OS" "$HN" "running" )
|
|
||||||
else
|
|
||||||
LNINTRO=$( printf "${C1}%-${INDENT}s${C2} " "OS/Kernel" )
|
|
||||||
fi
|
|
||||||
LNINTRO="$LNINTRO$( echo -ne "${C2}$OSKERN ${CN}[ ${C1}$DISTRO ${CN}]" )"
|
|
||||||
print_screen_output "$LNINTRO"
|
|
||||||
|
|
||||||
##print_screen_output "CPU[0]=\"${CPU[0]}\""
|
get_networking_data()
|
||||||
IFS=","
|
{
|
||||||
CPUTMP=(${CPU[0]})
|
|
||||||
IFS="$OIFS"
|
|
||||||
# Strange (and also some expected) behavior encountered.
|
|
||||||
# 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
|
|
||||||
##print_screen_output "CPUTMP=\"***${CPUTMP[@]} $HN+++++++\"----------"
|
|
||||||
|
|
||||||
if [[ -z ${CPUTMP[2]} ]]
|
|
||||||
then
|
|
||||||
CPUTMP[2]="unknown"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${#CPU[@]} -gt 2 ]]
|
|
||||||
then
|
|
||||||
CPUNUM="(1)"
|
|
||||||
else
|
|
||||||
# Array CPU always has one element: max clockfreq found. Therefore -gt and not -ge
|
|
||||||
unset CPUNUM
|
|
||||||
fi
|
|
||||||
LNCPU=$( printf "${C1}%-${INDENT}s${C2} %s" "CPU Info" "${CPUNUM}${CPUNUM+ }${CPUTMP[0]}" )
|
|
||||||
if [[ $VERBOSITY_LEVEL -ge 3 ]]
|
|
||||||
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" "]" )
|
|
||||||
print_screen_output "$LNCPU"
|
|
||||||
|
|
||||||
for (( I=1; I < ${#CPU[@]}-1; I++))
|
|
||||||
do
|
|
||||||
IFS=","
|
|
||||||
CPUTMP=(${CPU[I]})
|
|
||||||
IFS="$OIFS"
|
|
||||||
LNCPU=$( printf "${C1}%-${INDENT}s${C2} %s" " " "($((I+1))) ${CPUTMP[0]}" )
|
|
||||||
if [[ $VERBOSITY_LEVEL -ge 3 ]]
|
|
||||||
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" "]" )
|
|
||||||
print_screen_output "$LNCPU"
|
|
||||||
if [[ $I -gt 10 ]]
|
|
||||||
then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" "Videocard" "${GFX[0]}" )
|
|
||||||
if ((X))
|
|
||||||
then
|
|
||||||
LNGFX="${LNGFX}$( echo -ne "${C1} $XVER ${CN}[${C2} ${RES} ${CN}]" )"
|
|
||||||
else
|
|
||||||
LNGFX="${LNGFX}$( echo -ne "${C1} tty resolution ${CN}(${C2} ${RES} ${CN})" )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
print_screen_output "$LNGFX"
|
|
||||||
I=1
|
|
||||||
while [[ -n ${GFX[I]} && $I -le 3 ]]
|
|
||||||
do
|
|
||||||
LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}" )
|
|
||||||
print_screen_output "$LNGFX"
|
|
||||||
(( I++ ))
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ $VERBOSITY_LEVEL -ge 2 ]]
|
|
||||||
then
|
|
||||||
IFS=$'\n' LNNET=($( echo "$LSPCI" | gawk '
|
IFS=$'\n' LNNET=($( echo "$LSPCI" | gawk '
|
||||||
BEGIN { IGNORECASE=1 }
|
BEGIN { IGNORECASE=1 }
|
||||||
/^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ {
|
/^[0-9a-f:.]+ (ethernet|network) (controller|bridge)/ || /^[0-9a-f:.]+ [^:]+: .*(ethernet|network).*$/ {
|
||||||
|
@ -1070,6 +1006,94 @@ then
|
||||||
print_screen_output "$( printf "${C1}%-${INDENT}s${C2} %s" " " "${LNNET[I]}" )"
|
print_screen_output "$( printf "${C1}%-${INDENT}s${C2} %s" " " "${LNNET[I]}" )"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print_it_out()
|
||||||
|
{
|
||||||
|
# (IF VERBOSITY_LEVEL > 1)
|
||||||
|
if ((VERBOSITY_LEVEL))
|
||||||
|
then
|
||||||
|
if ((SHOW_HOST))
|
||||||
|
then
|
||||||
|
LNINTRO=$( printf "${C1}%-${INDENT}s${C2} \"%s\"${C1} %s " "Host/Kernel/OS" "$HN" "running" )
|
||||||
|
else
|
||||||
|
LNINTRO=$( printf "${C1}%-${INDENT}s${C2} " "OS/Kernel" )
|
||||||
|
fi
|
||||||
|
LNINTRO="$LNINTRO$( echo -ne "${C2}$OSKERN ${CN}[ ${C1}$DISTRO ${CN}]" )"
|
||||||
|
print_screen_output "$LNINTRO"
|
||||||
|
|
||||||
|
##print_screen_output "CPU[0]=\"${CPU[0]}\""
|
||||||
|
IFS=","
|
||||||
|
CPUTMP=(${CPU[0]})
|
||||||
|
IFS="$OIFS"
|
||||||
|
# Strange (and also some expected) behavior encountered.
|
||||||
|
# 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
|
||||||
|
##print_screen_output "CPUTMP=\"***${CPUTMP[@]} $HN+++++++\"----------"
|
||||||
|
|
||||||
|
if [[ -z ${CPUTMP[2]} ]]
|
||||||
|
then
|
||||||
|
CPUTMP[2]="unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${#CPU[@]} -gt 2 ]]
|
||||||
|
then
|
||||||
|
CPUNUM="(1)"
|
||||||
|
else
|
||||||
|
# Array CPU always has one element: max clockfreq found. Therefore -gt and not -ge
|
||||||
|
unset CPUNUM
|
||||||
|
fi
|
||||||
|
LNCPU=$( printf "${C1}%-${INDENT}s${C2} %s" "CPU Info" "${CPUNUM}${CPUNUM+ }${CPUTMP[0]}" )
|
||||||
|
if [[ $VERBOSITY_LEVEL -ge 3 ]]
|
||||||
|
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" "]" )
|
||||||
|
print_screen_output "$LNCPU"
|
||||||
|
|
||||||
|
for (( I=1; I < ${#CPU[@]}-1; I++))
|
||||||
|
do
|
||||||
|
IFS=","
|
||||||
|
CPUTMP=(${CPU[I]})
|
||||||
|
IFS="$OIFS"
|
||||||
|
LNCPU=$( printf "${C1}%-${INDENT}s${C2} %s" " " "($((I+1))) ${CPUTMP[0]}" )
|
||||||
|
if [[ $VERBOSITY_LEVEL -ge 3 ]]
|
||||||
|
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" "]" )
|
||||||
|
print_screen_output "$LNCPU"
|
||||||
|
if [[ $I -gt 10 ]]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" "Videocard" "${GFX[0]}" )
|
||||||
|
if ((X))
|
||||||
|
then
|
||||||
|
LNGFX="${LNGFX}$( echo -ne "${C1} $XVER ${CN}[${C2} ${RES} ${CN}]" )"
|
||||||
|
else
|
||||||
|
LNGFX="${LNGFX}$( echo -ne "${C1} tty resolution ${CN}(${C2} ${RES} ${CN})" )"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_screen_output "$LNGFX"
|
||||||
|
I=1
|
||||||
|
while [[ -n ${GFX[I]} && $I -le 3 ]]
|
||||||
|
do
|
||||||
|
LNGFX=$( printf "${C1}%-${INDENT}s${C2} %s" " " "${GFX[I]}" )
|
||||||
|
print_screen_output "$LNGFX"
|
||||||
|
(( I++ ))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $VERBOSITY_LEVEL -ge 2 ]]
|
||||||
|
then
|
||||||
|
get_networking_data
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch!
|
# Some code could look superfluous but BitchX doesn't like lines not ending in a newline. F*&k that bitch!
|
||||||
|
@ -1142,11 +1166,8 @@ else # (IF VERBOSITY_LEVEL > 1 ... ELSE)
|
||||||
fi
|
fi
|
||||||
print_screen_output "$LNSHORT"
|
print_screen_output "$LNSHORT"
|
||||||
fi # (IF VERBOSITY_LEVEL > 1)
|
fi # (IF VERBOSITY_LEVEL > 1)
|
||||||
|
|
||||||
## end main_temp_engine
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
#### SCRIPT EXECUTION
|
#### SCRIPT EXECUTION
|
||||||
########################################################################
|
########################################################################
|
||||||
|
@ -1171,8 +1192,16 @@ set_konvi
|
||||||
|
|
||||||
script_debugger "ALLUP=1 : inxi up and running.."
|
script_debugger "ALLUP=1 : inxi up and running.."
|
||||||
|
|
||||||
# we'll pull these features out one by one and make them into real functions
|
# assemble data for output
|
||||||
main_temp_engine
|
get_distro_data
|
||||||
|
get_cpu_data
|
||||||
|
get_hard_drive_data
|
||||||
|
get_memory_data
|
||||||
|
get_processes_uptime
|
||||||
|
get_graphics_data
|
||||||
|
|
||||||
|
# then create the output
|
||||||
|
print_it_out
|
||||||
|
|
||||||
## last steps
|
## last steps
|
||||||
if ((IBSHELL && SCHEME))
|
if ((IBSHELL && SCHEME))
|
||||||
|
|
Loading…
Reference in a new issue