mirror of
https://github.com/smxi/inxi.git
synced 2024-11-17 00:31:19 +00:00
(Change Version)
Optimized to not do repeated tests of tools for functions that are used more than one time. Added boolean tested flags, and global app path variables to handle this. this can knock off up to 10 or more type -p app exists type tests for one script execution.
This commit is contained in:
parent
ffd2c631ef
commit
53bbf03cea
57
inxi
57
inxi
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
########################################################################
|
########################################################################
|
||||||
#### Script Name: inxi
|
#### Script Name: inxi
|
||||||
#### version: 1.3.3
|
#### version: 1.3.4
|
||||||
#### Date: January 29 2010
|
#### Date: January 29 2010
|
||||||
########################################################################
|
########################################################################
|
||||||
#### SPECIAL THANKS
|
#### SPECIAL THANKS
|
||||||
|
@ -266,6 +266,16 @@ FILE_MOUNTS='/proc/mounts'
|
||||||
FILE_PARTITIONS='/proc/partitions'
|
FILE_PARTITIONS='/proc/partitions'
|
||||||
FILE_SCSI='/proc/scsi/scsi'
|
FILE_SCSI='/proc/scsi/scsi'
|
||||||
|
|
||||||
|
## app tested for and present, to avoid repeat tests
|
||||||
|
B_FILE_TESTED='false'
|
||||||
|
B_HDDTEMP_TESTED='false'
|
||||||
|
B_MODINFO_TESTED='false'
|
||||||
|
B_SUDO_TESTED='false'
|
||||||
|
FILE_PATH=''
|
||||||
|
HDDTEMP_PATH=''
|
||||||
|
MODINFO_PATH=''
|
||||||
|
SUDO_PATH=''
|
||||||
|
|
||||||
### Variable initializations: constants
|
### Variable initializations: constants
|
||||||
DCOPOBJ="default"
|
DCOPOBJ="default"
|
||||||
DEBUG=0 # Set debug levels from 1-10 (8-10 trigger logging levels)
|
DEBUG=0 # Set debug levels from 1-10 (8-10 trigger logging levels)
|
||||||
|
@ -2689,18 +2699,25 @@ get_hdd_temp_data()
|
||||||
{
|
{
|
||||||
eval $LOGFS
|
eval $LOGFS
|
||||||
local hdd_temp='' sudo_command=''
|
local hdd_temp='' sudo_command=''
|
||||||
local hddtemp_path=$( type -p hddtemp )
|
|
||||||
local sudo_path=$( type -p sudo )
|
|
||||||
|
|
||||||
if [[ -n $hddtemp_path && -n $1 ]];then
|
if [[ $B_HDDTEMP_TESTED != 'true' ]];then
|
||||||
|
B_HDDTEMP_TESTED='true'
|
||||||
|
HDDTEMP_PATH=$( type -p hddtemp )
|
||||||
|
fi
|
||||||
|
if [[ $B_SUDO_TESTED != 'true' ]];then
|
||||||
|
B_SUDO_TESTED='true'
|
||||||
|
SUDO_PATH=$( type -p sudo )
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n $HDDTEMP_PATH && -n $1 ]];then
|
||||||
# only use sudo if not root, -n option requires sudo -V 1.7 or greater. sudo will just error out
|
# only use sudo if not root, -n option requires sudo -V 1.7 or greater. sudo will just error out
|
||||||
# which is the safest course here for now, otherwise that interactive sudo password thing is too annoying
|
# which is the safest course here for now, otherwise that interactive sudo password thing is too annoying
|
||||||
# important: -n makes it non interactive, no prompt for password
|
# important: -n makes it non interactive, no prompt for password
|
||||||
if [[ $B_ROOT != 'true' && -n $sudo_path ]];then
|
if [[ $B_ROOT != 'true' && -n $SUDO_PATH ]];then
|
||||||
sudo_command='sudo -n '
|
sudo_command='sudo -n '
|
||||||
fi
|
fi
|
||||||
# this will fail if regular user and no sudo present, but that's fine, it will just return null
|
# this will fail if regular user and no sudo present, but that's fine, it will just return null
|
||||||
hdd_temp=$( eval $sudo_command $hddtemp_path -nq -u C $1 )
|
hdd_temp=$( eval $sudo_command $HDDTEMP_PATH -nq -u C $1 )
|
||||||
if [[ -n $hdd_temp && -n $( grep -E '^([0-9]+)$' <<< $hdd_temp ) ]];then
|
if [[ -n $hdd_temp && -n $( grep -E '^([0-9]+)$' <<< $hdd_temp ) ]];then
|
||||||
echo $hdd_temp
|
echo $hdd_temp
|
||||||
fi
|
fi
|
||||||
|
@ -2750,10 +2767,14 @@ get_module_version_number()
|
||||||
{
|
{
|
||||||
eval $LOGFS
|
eval $LOGFS
|
||||||
local module_version=''
|
local module_version=''
|
||||||
local modinfo_path=$( type -p modinfo )
|
|
||||||
|
|
||||||
if [[ -n $modinfo_path ]];then
|
if [[ $B_MODINFO_TESTED != 'true' ]];then
|
||||||
module_version=$( $modinfo_path $1 2>/dev/null | gawk '
|
B_MODINFO_TESTED='true'
|
||||||
|
MODINFO_PATH=$( type -p modinfo )
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n $MODINFO_PATH ]];then
|
||||||
|
module_version=$( $MODINFO_PATH $1 2>/dev/null | gawk '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
IGNORECASE=1
|
IGNORECASE=1
|
||||||
}
|
}
|
||||||
|
@ -3636,19 +3657,27 @@ get_unmounted_partition_filesystem()
|
||||||
{
|
{
|
||||||
eval $LOGFS
|
eval $LOGFS
|
||||||
local partition_filesystem='' sudo_command=''
|
local partition_filesystem='' sudo_command=''
|
||||||
local file_path=$( type -p file )
|
|
||||||
local sudo_path=$( type -p sudo )
|
|
||||||
|
|
||||||
if [[ -n $file_path && -n $1 ]];then
|
if [[ $B_FILE_TESTED != 'true' ]];then
|
||||||
|
B_FILE_TESTED='true'
|
||||||
|
FILE_PATH=$( type -p file )
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $B_SUDO_TESTED != 'true' ]];then
|
||||||
|
B_SUDO_TESTED='true'
|
||||||
|
SUDO_PATH=$( type -p sudo )
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n $FILE_PATH && -n $1 ]];then
|
||||||
# only use sudo if not root, -n option requires sudo -V 1.7 or greater. sudo will just error out
|
# only use sudo if not root, -n option requires sudo -V 1.7 or greater. sudo will just error out
|
||||||
# which is the safest course here for now, otherwise that interactive sudo password thing is too annoying
|
# which is the safest course here for now, otherwise that interactive sudo password thing is too annoying
|
||||||
# important: -n makes it non interactive, no prompt for password
|
# important: -n makes it non interactive, no prompt for password
|
||||||
if [[ $B_ROOT != 'true' && -n $sudo_path ]];then
|
if [[ $B_ROOT != 'true' && -n $SUDO_PATH ]];then
|
||||||
sudo_command='sudo -n '
|
sudo_command='sudo -n '
|
||||||
fi
|
fi
|
||||||
# this will fail if regular user and no sudo present, but that's fine, it will just return null
|
# this will fail if regular user and no sudo present, but that's fine, it will just return null
|
||||||
# note the hack that simply slices out the first line if > 1 items found in string
|
# note the hack that simply slices out the first line if > 1 items found in string
|
||||||
partition_filesystem=$( eval $sudo_command $file_path -s $1 | grep -Eio '(ext2|ext3|ext4|ext5|ext[[:space:]]|ntfs|fat32|fat16|fat[[:space:]]\(.*\)|vfat|fatx|tfat|swap|btrfs|ffs[[:space:]]|hfs\+|hfs[[:space:]]plus|hfs[[:space:]]extended[[:space:]]version[[:space:]][1-9]|hfsj|hfs[[:space:]]|jfs[[:space:]]|nss[[:space:]]|reiserfs|reiser4|ufs2|ufs[[:space:]]|xfs[[:space:]]|zfs[[:space:]])' | grep -Em 1 '.*' )
|
partition_filesystem=$( eval $sudo_command $FILE_PATH -s $1 | grep -Eio '(ext2|ext3|ext4|ext5|ext[[:space:]]|ntfs|fat32|fat16|fat[[:space:]]\(.*\)|vfat|fatx|tfat|swap|btrfs|ffs[[:space:]]|hfs\+|hfs[[:space:]]plus|hfs[[:space:]]extended[[:space:]]version[[:space:]][1-9]|hfsj|hfs[[:space:]]|jfs[[:space:]]|nss[[:space:]]|reiserfs|reiser4|ufs2|ufs[[:space:]]|xfs[[:space:]]|zfs[[:space:]])' | grep -Em 1 '.*' )
|
||||||
if [[ -n $partition_filesystem ]];then
|
if [[ -n $partition_filesystem ]];then
|
||||||
echo $partition_filesystem
|
echo $partition_filesystem
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue