new option: --recommends

This lets users check their system for all the required/recommended apps, and also shows any missing core directories,
with an explanation of what each item does.

Also prints out a list of distro packages that should help users install the missing package.

So far only debian/ubuntu and arch linux lists are done.
This commit is contained in:
inxi-svn 2011-06-10 23:07:01 +00:00
parent b1f7966f9b
commit 6a2f09858f

258
inxi
View file

@ -1,9 +1,9 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 1.6.5
#### version: 1.6.6
#### Date: June 10 2011
#### Patch Number: 01
#### Patch Number: 00
########################################################################
#### SPECIAL THANKS
########################################################################
@ -645,38 +645,16 @@ main()
initialize_script_data()
{
eval $LOGFS
local path='' sys_path='' added_path='' b_path_found=''
# Extra path variable to make execute failures less likely, merged below
local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
# Fallback paths put into $extra_paths; This might, among others, help on gentoo.
# Now, create a difference of $PATH and $extra_paths and add that to $PATH:
IFS=":"
for path in $extra_paths
do
b_path_found='false'
for sys_path in $PATH
do
if [[ $path == $sys_path ]];then
b_path_found='true'
fi
done
if [[ $b_path_found == 'false' ]];then
added_path="$added_path:$path"
fi
done
IFS="$ORIGINAL_IFS"
PATH="${PATH}${added_path}"
##echo "PATH='$PATH'"
##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
# now set the script BOOLEANS for files required to run features
if [[ -d "/proc/" ]];then
B_PROC_DIR='true'
else
error_handler 6
fi
initialize_script_paths
# found a case of battery existing but having nothing in it on desktop mobo
# not all laptops show the first,
if [[ -n $( ls /proc/acpi/battery 2>/dev/null ) ]];then
@ -741,6 +719,35 @@ initialize_script_data()
eval $LOGFE
}
initialize_script_paths()
{
local path='' added_path='' b_path_found='' sys_path=''
# Extra path variable to make execute failures less likely, merged below
local extra_paths="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
# Fallback paths put into $extra_paths; This might, among others, help on gentoo.
# Now, create a difference of $PATH and $extra_paths and add that to $PATH:
IFS=":"
for path in $extra_paths
do
b_path_found='false'
for sys_path in $PATH
do
if [[ $path == $sys_path ]];then
b_path_found='true'
fi
done
if [[ $b_path_found == 'false' ]];then
added_path="$added_path:$path"
fi
done
IFS="$ORIGINAL_IFS"
PATH="${PATH}${added_path}"
##echo "PATH='$PATH'"
##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""'
}
# No args taken.
check_script_suggested_apps()
{
@ -1307,7 +1314,7 @@ debug_data_collector()
cat $FILE_CPUINFO &> $xiin_data_dir/proc-cpu-info.txt
cat $FILE_MEMINFO &> $xiin_data_dir/proc-meminfo.txt
cat $FILE_MODULES &> $xiin_data_dir/proc-modules.txt
check_recommends &> $xiin_data_dir/check-recommends.txt
# note, only bash 4> supports ;;& for case, so using if/then here
if [[ $1 == 'sys' || $1 == 'all' ]];then
xiin_data_file=$SCRIPT_DATA_DIR/$xiin_data_dir/xiin-sys.txt
@ -1417,6 +1424,194 @@ debug_data_collector()
exit 0
}
check_recommends()
{
local Line='-----------------------------------------------------------------------------------------'
if ! tty >/dev/null;then
print_screen_output "Sorry, you can't run this option in an IRC client."
exit 1
fi
initialize_script_paths
echo "$SCRIPT_NAME will now begin checking for the programs it needs to operate."
echo $Line
echo 'Test One: Script Dependencies and Required System Directories.'
echo "If one of these applications is missing, $SCRIPT_NAME cannot operate."
echo $Line
echo "You are using bash version: $( bash --version 2>&1 | awk 'BEGIN {IGNORECASE=1} /^GNU bash/ {print $4}' )"
echo $Line
check_recommends_items 'required-dirs'
check_recommends_items 'required-apps'
echo 'Test Two: Script Recommends for Graphics features. If you do not use X these do not matter.'
echo "If one of these applications is missing, $SCRIPT_NAME will have incomplete output."
echo $Line
check_recommends_items 'recommended-x-apps'
echo 'Test Three: Script Recommends for remaining features.'
echo "If one of these applications is missing, $SCRIPT_NAME will have incomplete output."
echo $Line
check_recommends_items 'recommended-apps'
echo 'Test Four: System directories for various information.'
echo "If one of these directories is missing, $SCRIPT_NAME will have incomplete output."
echo $Line
check_recommends_items 'system-dirs'
}
# args: $1 - check item
check_recommends_items()
{
local item='' item_list='' item_string='' missing_items='' missing_string=''
local package='' application='' feature='' type=''
local required_dirs='/proc /sys'
# package-owner: 1 - debian/ubuntu; 2 - arch; 3 - rpm
# rpm rpm -qf /usr/bin/package
# for uninstalled: repoquery -qf /usr/bin/package
# pardus: pisi sf -q /usr/bin/package
local required_apps='
df:coreutils~coreutils~?~:partition-data
free:procps~procps~?~:system-memory
gawk:gawk~gawk~gawk~:core-tool
grep:grep~grep~grep~:string-search
hostname:hostname~coreutils~?~:
lspci:pciutils~pciutils~?~:hardware-data
ps:procps~procps~?~:process-data
readlink:coreutils~coreutils~?~:
sed:sed~sed~sed~:string-replace
tr:coreutils~coreutils~?~:character-replace
uname:uname~coreutils~?~:kernel-data
uptime:procps~procps~?~:
wc:coreutils~coreutils~?~:word-character-count
'
local x_recommends='
glxinfo:mesa-utils~mesa-demos~?~:-G_glx-info
xdpyinfo:X11-utils~xorg-xdpyinfo~?~:-G_multi-screen-resolution
xprop:X11-utils~xprop~?~:-S_desktop-data
xrandr:x11-xserver-utils~xrandr~?~:-G_single-screen-resolution
'
local recommended_apps='
file:file~file~file~:-o_file-system
hddtemp:hddtemp~hddtemp~hddtemp~:-Dx_show-hdd-temp
ifconfig:net-tools~net-tools~?~:-i_ip-lan
sensors:lm-sensors~lm_sensors~?~:-s_sensors-output
lsusb:usbutils~usbutils~?~:-A_usb-audio;-N_usb-networking
modinfo:module-init-tools~module-init-tools~?~:-Ax_module-version
runlevel:sysvinit~sysvinit~?~:-I_runlevel
sudo:sudo~sudo~sudo~:-Dx_user-hddtemp;-o_user-filesystem
'
local recommended_dirs='
/sys/class/dmi/id/:-M_motherboard-bios
/dev:-p,-P,-D_disk-partition-data
/dev/disk/by-label/:-p,-P_partition-labels
/dev/disk/by-uuid/:-p,-P_partition-uuid
'
case $1 in
required-dirs)
item_list=$required_dirs
item_string='Required file system'
missing_string='system directories'
type='directories'
;;
required-apps)
item_list=$required_apps
item_string='Required application'
missing_string='applications, and their corresponding packages,'
type='applications'
;;
recommended-x-apps)
item_list=$x_recommends
item_string='Recommended X application'
missing_string='applications, and their corresponding packages,'
type='applications'
;;
recommended-apps)
item_list=$recommended_apps
item_string='Recommended application'
missing_string='applications, and their corresponding packages,'
type='applications'
;;
system-dirs)
item_list=$recommended_dirs
item_string='System directory'
missing_string='system directories'
type='directories'
;;
esac
# great trick from: http://ideatrash.net/2011/01/bash-string-padding-with-sed.html
# left pad: sed -e :a -e 's/^.\{1,80\}$/& /;ta'
# right pad: sed -e :a -e 's/^.\{1,80\}$/ &/;ta'
# center pad: sed -e :a -e 's/^.\{1,80\}$/ & /;ta'
for item in $item_list
do
if [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 0 ]];then
application=$item
package=''
feature=''
location=''
elif [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 1 ]];then
application=$( cut -d ':' -f 1 <<< $item )
package=''
feature=$( cut -d ':' -f 2 <<< $item )
location=''
else
application=$( cut -d ':' -f 1 <<< $item )
package=$( cut -d ':' -f 2 <<< $item )
location=$( type -p $application )
if [[ $( awk -F ":" '{print NF-1}' <<< $item ) -eq 2 ]];then
feature=$( cut -d ':' -f 3 <<< $item )
else
feature=''
fi
fi
if [[ -n $feature ]];then
print_string="$item_string: $application (info: $feature)"
else
print_string="$item_string: $application"
fi
starter="$( sed -e :a -e 's/^.\{1,75\}$/&./;ta' <<< $print_string )"
if [[ -z $( grep '^/' <<< $application ) && -n $location ]] || [[ -d $application ]];then
if [[ -n $location ]];then
finisher=" $location"
else
finisher=" Present"
fi
else
finisher=" Missing"
missing_items="$missing_items$separator$application:$package"
separator=' '
fi
echo "$starter$finisher"
done
echo $Line
if [[ -n $missing_items ]];then
echo "The following $type are missing from your system:"
for item in $missing_items
do
application=$( cut -d ':' -f 1 <<< $item )
if [[ $type == 'applications' ]];then
echo '--------------------------------------------------------'
package=$( cut -d ':' -f 2 <<< $item )
package_deb=$( cut -d '~' -f 1 <<< $package )
package_pacman=$( cut -d '~' -f 2 <<< $package )
package_rpm=$( cut -d '~' -f 3 <<< $package )
echo "Application: $application"
echo "To add to your system, install the proper distribution package for your system:"
echo "Debian/Ubuntu: $package_deb :: Arch Linux: $package_pacman :: Redhat/Fedora/Suse: $package_rpm"
else
echo "Directory: $application"
fi
done
if [[ $item_string == 'System directory' ]];then
echo "These directories are created by the kernel, so don't worry if they are not present."
fi
else
echo "All the $( cut -d ' ' -f 1 <<< $item_string | sed -e 's/Re/re/' -e 's/Sy/sy/' ) $type are present."
fi
echo $Line
}
#### -------------------------------------------------------------------
#### print / output cleaners
#### -------------------------------------------------------------------
@ -1520,6 +1715,9 @@ get_parameters()
elif [[ $1 == '--help' ]];then
show_options
exit 0
elif [[ $1 == '--recommends' ]];then
check_recommends
exit 0
# the short form only runs if no args output args are used
# no need to run through these if there are no args
# reserved for future use: -g for extra Graphics; -m for extra Machine; -d for extra Disk
@ -1907,6 +2105,8 @@ show_options()
print_screen_output "Additional Options:"
print_screen_output "-h --help This help menu."
print_screen_output "-H This help menu, plus developer options. Do not use dev options in normal operation!"
print_screen_output "--recommends Checks $SCRIPT_NAME application dependencies + recommends, and directories, then shows"
print_screen_output " what package(s) you need to install to add support for that feature."
if [[ $B_ALLOW_UPDATE == 'true' ]];then
print_screen_output "-U Auto-update script. Note: if you installed as root, you"
print_screen_output " must be root to update, otherwise user is fine."