USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

smxi, a great package, graphics, and management tool

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » System Administration and Security
View previous topic :: View next topic  
Author Message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Fri Nov 14, 2024 6:52 pm    Post subject: smxi, a great package, graphics, and management tool Reply with quote

The Tech Patterns site contains a number of great tools, and among them, smxi is my favorite of these tools. First developed at least three, almost four, years ago during the Kanotix days, Harold Hope, known as h2 on the 'net, has done a terrific job creating a console oriented systems management script that can handle packaging, graphics drivers, boot loaders, and various other features. With the Kanotix roots, this is a Debian-based tool. Now at home in sidux, it has become a default in antiX as well and is commonly used by many plain Debian and MEPIS users as well.

You've probably seen me talking up sidux and antiX. This tool is certainly a contributory reason for my enjoyment of those two systems.

Don't be intimidated by a console based system management tool. This is a menu based tool. There are only so many options on each page. Besides, if you can read, Harold has done a terrific job to thoroughly document his work.

I recommend that you take a look at this tool: smxi.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
JP
Linux Guru


Joined: 07 Jul 2024
Posts: 6670
Location: Central Montana

PostPosted: Fri Nov 14, 2024 9:27 pm    Post subject: Reply with quote

I used it when I had sidux, a very nice tool, my one complaint with it was having to runlevel 3 all the time to upgrade .... I'm surprised they haven't figured out a way to do it in runlevel 5 by now.



_________________
Dell Box - Arch Linux
Dell Lappy - DreamLinux 3.5 - Default OS
Mepis 8.0 - Backup
Back to top
View user's profile Send private message Visit poster's website
anticapitalista
Member


Joined: 13 Jan 2024
Posts: 185
Location: Greece

PostPosted: Fri Nov 14, 2024 9:50 pm    Post subject: Reply with quote

smxi is a wonderful script and h2 has no intention of finding a way to run it whilst in X.

Also from h2 and TechPatterns is inxi. (also included in antiX)

http://techpatterns.com/forums/about1133.html

Many people at MEPIS are using smxi or at least the sgfxi part of it to install graphic drivers. sgfxi has never failed me!



_________________
antiX
sidux
Back to top
View user's profile Send private message
tlmiller
Ultimate Member


Joined: 01 May 2024
Posts: 2433
Location: MD, USA

PostPosted: Fri Nov 14, 2024 11:38 pm    Post subject: Reply with quote

what is inxi do?



_________________
Debian Squeeze, Arch, Kubuntu mostly. Some Mandriva. Some Windows.
Desktops: shadowdragon, medusa
Laptops: bluedrake, banelord, sandwyrm, aardvark.
Back to top
View user's profile Send private message AIM Address MSN Messenger
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Fri Nov 14, 2024 11:49 pm    Post subject: Here is how to use smxi effectively Reply with quote

Totally agree, anti. There is no reason to run smxi in run level 5, and there are plenty of reasons to run it in run level 3, including making sure that X server upgrades work right.

Here is how I do things so that the inconveniece is quite minimal:

When booting, select the system to boot (if you are using a GRUB gfxboot menu, like antiX, MEPIS, and sidux provide).
1. Type in 3 - you will see that this gets appended to the end of the boot line.
2. Press Enter to boot, and you will go directly to run level 3.
3. Login as root
4. Type in smxi and update the system.

If a kernel upgrade is offered, do it, and reboot at the end of the kernel upgrade.
If an updated kernel, repeat steps 1-4 above. I find that if I do this, I validate that the new kernel works, then I can later remove previous kernels and update GRUB to include only the latest kernels.

5. Continue with the upgrade when past the kernel options.
6. When complete with the updates, manage the package cache and perform an autoclean (look for it in the menus).
7. Clean up any GRUB menu changes and periodically choose the autoremove options to get rid of old libraries and transition packages that are no longer needed, in order to keep a nice, tidy system.
8. When all done with everything, choose option 9 to return to the main menu, then choose option 8 to return to run level 5 and run your desktop system. Works beautifully and only takes a few minutes, at least if you do it regularly. For me, this usually takes less time than it took to write up these instructions.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Sat Nov 15, 2024 12:23 am    Post subject: Reply with quote

tlmiller wrote:
what is inxi do?

http://techpatterns.com/forums/about1133.html

It is a fork of infobash, and it provides you with all kinds of information about your system. You can closely examine your system's networking, sound subsystem, and any other kinds of things you like to do. In the past, you have had to use all kinds of different commands to get everything you need. Infobash has reduced that to a degree, as have a few other commands, but inxi puts it all in one place and has the same look and feel as smxi, and will eventually be a option in smxi, just as the sgfxi tool is also accessible from smxi. h2 is assembling very fast, complete system management tools that rival and even exceed some of the great tools that Jon Danzig put together for Libranet years ago.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
julian516
Jr. Member


Joined: 16 Jul 2024
Posts: 90
Location: Columbia, KY

PostPosted: Wed Oct 07, 2024 9:59 pm    Post subject: Reply with quote

Well, I do not have the experience many people on this site have, but I can say that smxi is the best thing I have found in Linux for helping me to maintain my systems. In fact I have grown reluctant to run something for which h2 does not have a script!



_________________
Ubuntu 9.10
Mandriva 2024 KDE
siduxKDE/antiX
Back to top
View user's profile Send private message
JP
Linux Guru


Joined: 07 Jul 2024
Posts: 6670
Location: Central Montana

PostPosted: Thu Oct 08, 2024 4:02 am    Post subject: Reply with quote

I wonder if he has set it up to work on any Debian-based system .... I wouldn't mind having it available on DL ...... Wink



_________________
Dell Box - Arch Linux
Dell Lappy - DreamLinux 3.5 - Default OS
Mepis 8.0 - Backup
Back to top
View user's profile Send private message Visit poster's website
crouse
Site Admin


Joined: 17 Apr 2024
Posts: 11833
Location: Iowa

PostPosted: Thu Oct 08, 2024 5:17 am    Post subject: Reply with quote

inxi looks very similar to my archinfo script........
http://archlinux.me/crouse/2009/05/20/arch-linux-info-script/

Quote:
[davec@Arch64 ~]$ info

ARCH LINUX - Machine Information Script ver .10
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DATE: 05/20/09 03:18:06 PM MACHINE NAME: Arch64

Eth0: Local IP:10.1.1.65 Bcast:10.1.1.255 Mask:255.255.255.0
ETHERNET CARD: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
CPU INFO: Qty=1 x86_64 Quad-Core AMD Opteron(tm) Processor 2384
VIDEO CARD: VMware Inc Abstract SVGA II Adapter
AUDIO CONTROLLER:
RAM INFO: 1026860 kB

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.1.1.0 * 255.255.255.0 U 0 0 0 eth0
default 10.1.1.254 0.0.0.0 UG 0 0 0 eth0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DISK USAGE:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 9.7G 2.8G 6.5G 30% /
none 502M 0 502M 0% /dev/shm
/dev/sda1 38M 9.8M 27M 27% /boot
/dev/sda4 9.8G 151M 9.2G 2% /home
jughead:/vol/vol1_isp/vusers
675G 492G 184G 73% /var/users
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UPTIME: 15:18:06 up 1 day, 22:26, 2 users, load average: 0.00, 0.00, 0.00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DAEMONS=(syslog-ng network portmap nfslock @netfs @crond @sshd @mysqld @httpd @vmware-tools)




_________________
Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
Back to top
View user's profile Send private message Visit poster's website AIM Address
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Thu Oct 08, 2024 11:33 am    Post subject: Here is all of the inxi code; quite comprehensive! Reply with quote

Yes, it looks fairly similar.

Here is the code for inxi:
[code:1:b84a144ca5]
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 1.1.13
#### Date: August 6 2024
########################################################################
#### SPECIAL THANKS
########################################################################
#### Special thanks to all those in #lsc and #smxi for their tireless
#### dedication helping test inxi modules.
########################################################################
#### ABOUT INXI
########################################################################
#### inxi is a fork of infobash 3.02, the original bash sys info script by locsmif
#### As time permits functionality improvements and recoding will occur.
####
#### inxi, the universal, portable, system info script for irc.
#### Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,
#### Gaim/Pidgin, Weechat, KVIrc and Kopete.
#### Original infobash author and copyright holder:
#### Copyright (C) 2024-2007 Michiel de Boer a.k.a. locsmif
#### inxi version: Copyright (C) 2024-9 Scott Rogers & Harald Hope
#### Further fixes (listed as known): Horst Tritremmel <hjt at sidux.com>
#### Steven Barrett (aka: damentz) - usb audio patch; swap percent used patch
####
#### Current script home page: http://techpatterns.com/forums/about1131.html
#### Script svn: http://code.google.com/p/inxi
####
#### This program is free software; you can redistribute it and/or modify
#### it under the terms of the GNU General Public License as published by
#### the Free Software Foundation; either version 3 of the License, or
#### (at your option) any later version.
####
#### This program is distributed in the hope that it will be useful,
#### but WITHOUT ANY WARRANTY; without even the implied warranty of
#### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#### GNU General Public License for more details.
####
#### You should have received a copy of the GNU General Public License
#### along with this program. If not, see <http://www.gnu.org/licenses/>.
####
#### If you don't understand what Free Software is, please read (or reread)
#### this page: http://www.gnu.org/philosophy/free-sw.html
########################################################################
#### DEPENDENCIES
#### bash >=3.0(bash), df;readlink;stty;tr;uname;wc(coreutils),
#### gawk(gawk), grep(grep), hostname(hostname), lspci(pciutils),
#### ps;uptime(procps), glxinfo;xdpyinfo;xrandr(xbase-clients)
#### Also the proc filesystem should be present and mounted
####
#### Apparently unpatched bash 3.0 has arrays broken; bug reports:
#### http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-008
#### http://lists.gnu.org/archive/html/bug-bash/2004-08/msg00144.html
####
#### Arrays work in bash 2.05b, but "egrep -m" does not
####
#### RECOMMENDS (Needed to run certain features)
#### For local interfaces/IP test: ifconfig (in net-tools for Debian systems)
#### runlevel(sysvinit): to view current runlevel while not in X window system
#### Bash 3.1 for proper array use
########################################################################
#### CONVENTIONS:
#### Indentation: TABS
#### Do not use `....` (back quotes), those are totally non-reabable, use $(....).
#### Do not use one liner flow controls.
#### The ONLY time you should use ';' (semi-colon) is in this single case: if [[ condition ]];then.
#### Never use compound 'if': ie, if [[ condition ]] && statement.
#### Note: [[ -n $something ]] - double brackets does not require quotes for variables: ie, "$something".
#### Always use quotes, double or single, for all string values.
####
#### All new code/methods must be in a function.
#### For all boolean tests, use 'true' / 'false'.
#### !! Do NOT use 0 or 1 unless it's a function return.
#### Avoid complicated tests in the if condition itself.
#### To 'return' a value in a function, use 'echo <var>'.
####
#### For gawk: use always if ( num_of_cores > 1 ) { hanging { starter for all blocks
#### This lets us use one method for all gawk structures, including BEGIN/END, if, for, etc
####
#### VARIABLE/FUNCTION NAMING:
#### All functions should follow standard naming--verb adjective noun.
#### ie, get_cpu_data
#### All variables MUST be initialized / declared explicitly.
#### All variables should clearly explain what they are, except counters like i, j.
#### Each word of variable must be separated by '_' (underscore) (camel form).
#### Global variables are 'UPPER CASE', at top of script.
#### ie, SOME_VARIABLE=''
#### Local variables are 'lower case' and declared at the top of the function.
#### ie, some_variable=''
#### Locals that will be inherited by child functions have first char capitalized (so you know they are inherited).
#### ie, Some_Variable
####
#### Booleans should start with b_ (local) or B_ (global) and state clearly what is being tested.
#### Arrays should start with a_ (local) or A_ (global).
####
#### SPECIAL NOTES:
#### The color variable ${C2} must always be followed by a space unless you know what
#### character is going to be next for certain. Otherwise irc color codes can be accidentally
#### activated or altered.
####
#### For native script konversation support (check distro for correct konvi scripts path):
#### ln -s <path to inxi> /usr/share/apps/konversation/scripts/inxi
#### DCOP doesn't like \n, so avoid using it for most output unless required, as in error messages.
####
#### As with all 'rules' there are acceptions, these are noted where used.
####
###################################################################################
#### KDE Konversation information. Moving from dcop(qt3/KDE3) to dbus(qt4/KDE4)
###################################################################################
#### dcop and dbus -- these talk back to Konversation from this script
####
#### Scripting info -- http://konversation.berlios.de/docs/scripting.html
#### -- http://www.kde.org.uk/apps/konversation/
####
#### dbus info -- http://dbus.freedesktop.org/doc/dbus-tutorial.html
#### view dbus info -- https://fedorahosted.org/d-feet/
#### -- or run qdbus
#### Konvi dbus/usage-- qdbus org.kde.konversation /irc say <server> <target-channel> <output>
####
#### Python usage -- http://wiki.python.org/moin/DbusExamples (just in case)
####
#### Because webpages come and go, the above information needs to be moved to inxi's wiki
####
########################################################################
#### Valuable Resources
#### gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
########################################################################
#### TESTING FLAGS
#### inxi supports advanced testing triggers to do various things, using -! <arg>
#### -! 1 - triggers default B_TESTING_1='true' to trigger some test or other
#### -! 2 - triggers default B_TESTING_2='true' to trigger some test or other
#### -! 3 - triggers B_TESTING_1='true' and B_TESTING_2='true'
#### -! 10 - triggers an update from the primary dev download server instead of svn
#### -! 11 - triggers an update from svn branch one - if present, of course
#### -! 12 - triggers an update from svn branch two - if present, of course
#### -! 13 - triggers an update from svn branch three - if present, of course
#### -! 14 - triggers an update from svn branch four - if present, of course
#### -! <http://......> - Triggers an update from whatever server you list.
#### LOG FLAGS (logs to $HOME/.inxi/inxi.log with rotate 3 total)
#### -@ 8 - Basic data logging of generated data / array values
#### -@ 9 - Full logging of all data used, including cat of files and system data
#### -@ 10 - Basic data logging plus color code logging
########################################################################
#### VARIABLES
########################################################################

## NOTE: we can use hwinfo if it's available in all systems, or most, to get
## a lot more data and verbosity levels going
# set to default LANG to avoid locales errors with , or .
LANG=C
### Variable initializations: null values
CMDL_MAX=''
COLOR_SCHEME=''
COLOR_SCHEME_SET=''
IRC_CLIENT=''
IRC_CLIENT_VERSION=''

### primary data array holders ## usage: 'A_<var>'
A_AUDIO_DATA=''
A_CMDL=''
A_CPU_CORE_DATA=''
A_CPU_DATA=''
A_CPU_TYPE_PCNT_CCNT=''
A_DEBUG_BUFFER=''
A_GFX_CARD_DATA=''
A_GLX_DATA=''
A_HDD_DATA=''
A_INTERFACES_DATA=''
A_NETWORK_DATA=''
A_PARTITION_DATA=''
A_SENSORS_DATA=''
A_X_DATA=''

### Boolean true/false globals ## usage: 'B_<var>'
# flag to allow distro maintainers to turn off update features. If false, turns off
# -U and -! testing/advanced update options, as well as removing the -U help menu item
B_ALLOW_UPDATE='true'
# triggers full display of cpu flags
B_CPU_FLAGS_FULL='false'
# Debug flood override: make 'true' to allow long debug output
B_DEBUG_FLOOD='false'
# show extra output data
B_EXTRA_DATA='false'
# override certain errors due to currupted data
B_HANDLE_CORRUPT_DATA='false'
B_LOG_COLORS='false'
B_LOG_FULL_DATA='false'
B_ROOT='false'
# Running in a shell? Defaults to false, and is determined later.
B_RUNNING_IN_SHELL='false'
# this sets the debug buffer
B_SCRIPT_UP='false'
# sensors only if installed
B_SENSORS='false'
# Show sound card data
B_SHOW_AUDIO='false'
B_SHOW_CPU='false'
B_SHOW_DISK='false'
# Show full hard disk output
B_SHOW_FULL_HDD='false'
B_SHOW_GRAPHICS='false'
# Set this to 'false' to avoid printing the hostname
B_SHOW_HOST='true'
B_SHOW_INFO='false'
B_SHOW_IP='false'
B_SHOW_LABELS='false'
B_SHOW_NETWORK='false'
# either -v > 3 or -P will show partitions
B_SHOW_PARTITIONS='false'
B_SHOW_PARTITIONS_FULL='false'
B_SHOW_SENSORS='false'
# triggers only short inxi output
B_SHOW_SHORT_OUTPUT='false'
B_SHOW_SYSTEM='false'
B_SHOW_UUIDS='false'
# triggers various debugging and new option testing
B_TESTING_1='false'
B_TESTING_2='false'
# set to true here for debug logging from script start
B_USE_LOGGING='false'
# Test for X running
B_X_RUNNING='false'
# test for dbus irc client
B_DBUS_CLIENT='false'

### Directory/file exist flags; test as [[ $(boolean) ]] not [[ $boolean ]]
B_PROC='false'
B_CPUINFO='false'
B_MEMINFO='false'
B_ASOUND_CARDS='false'
B_ASOUND_VERSION='false'
B_BASH_ARRAY='false'
B_IFCONFIG='false'
B_LSB_DIR='false'
B_SCSI_DIR='false'
B_MODULES_DIR='false' #
B_MOUNTS_DIR='false'
B_PARTITIONS_DIR='false' #

### File's used when present
FILE_CPUINFO='/proc/cpuinfo'
FILE_MEMINFO='/proc/meminfo'
FILE_ASOUND_DEVICE='/proc/asound/cards'
FILE_ASOUND_VERSION='/proc/asound/version'
FILE_LSB_RELEASE='/etc/lsb-release'
FILE_SCSI='/proc/scsi/scsi'
FILE_MODULES='/proc/modules'
FILE_MOUNTS='/proc/mounts'
FILE_PARTITIONS='/proc/partitions'

### Variable initializations: constants
DCOPOBJ="default"
DEBUG=0 # Set debug levels from 1-10 (8-10 trigger logging levels)
# Debug Buffer Index, index into a debug buffer storing debug messages until inxi is 'all up'
DEBUG_BUFFER_INDEX=0
## note: the debugger rerouting to /dev/null has been moved to the end of the get_parameters function
## so -@[number] debug levels can be set if there is a failure, otherwise you can't even see the errors

# Defaults to 2, make this 1 for normal, 0 for no colorcodes at all. Set to any other valid scheme you like.
# Same as runtime parameter.
DEFAULT_SCHEME=2

# Default indentation level
INDENT=10

# logging eval variables, start and end function: Insert to LOGFS LOGFE when debug level >= 8
LOGFS_STRING='log_function_data fs $FUNCNAME "$( echo $@ )"'
LOGFE_STRING='log_function_data fe $FUNCNAME'
LOGFS=''
LOGFE=''
# uncomment for debugging from script start
# LOGFS=$LOGFS_STRING
# LOGFE=$LOGFE_STRING

# default to false, no konversation found, 1 is native konvi (qt3/KDE3) script mode, 2 is /cmd inxi start,
## 3 is Konversation > 1.2 (qt4/KDE4)
KONVI=0
# NO_CPU_COUNT=0 # Wether or not the string "dual" or similar is found in cpuinfo output. If so, avoid dups.
# This is a variable that controls how many parameters inxi will parse in a /proc/<pid>/cmdline file before stopping.
PARAMETER_LIMIT=30
SCHEME=0 # set default scheme
# this is set in user prefs file, to override dynamic temp1/temp2 determination of sensors output in case
# cpu runs colder than mobo
SENSORS_CPU_NO=''
# SHOW_IRC=1 to avoid showing the irc client version number, or SHOW_IRC=0 to disable client information completely.
SHOW_IRC=2
# Verbosity level defaults to 0, this can also be set with -v0, -v2, -v3, etc as a parameter.
VERBOSITY_LEVEL=0
# Supported number of verbosity levels, including 0
VERBOSITY_LEVELS=5

# Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS"
# type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and
# therefore results in nothing.
shopt -u nullglob
## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html
# Backup the current Internal Field Separator
ORIGINAL_IFS="$IFS"

# These two determine separators in single line output, to force irc clients not to break off sections
SEP1='-'
SEP2='~'

### Script names/paths - must be non root writable
SCRIPT_DATA_DIR="$HOME/.inxi"
LOG_FILE="$SCRIPT_DATA_DIR/inxi.log"
LOG_FILE_1="$SCRIPT_DATA_DIR/inxi.1.log"
LOG_FILE_2="$SCRIPT_DATA_DIR/inxi.2.log"
SCRIPT_NAME="inxi"
SCRIPT_PATH="" #filled-in in Main
SCRIPT_VERSION_NUMBER="" #filled-in in Main
SCRIPT_DOWNLOAD='http://inxi.googlecode.com/svn/trunk/'
SCRIPT_DOWNLOAD_BRANCH_1='http://inxi.googlecode.com/svn/branches/one/'
SCRIPT_DOWNLOAD_BRANCH_2='http://inxi.googlecode.com/svn/branches/two/'
SCRIPT_DOWNLOAD_BRANCH_3='http://inxi.googlecode.com/svn/branches/three/'
SCRIPT_DOWNLOAD_BRANCH_4='http://inxi.googlecode.com/svn/branches/four/'
SCRIPT_DOWNLOAD_DEV='http://smxi.org/test/'
KONVI_CFG="konversation/scripts/$SCRIPT_NAME.conf" # relative path to $(kde-config --path data)

### Script Localization
# Make sure every program speaks English.
LC_ALL="C"
export LC_ALL

### Output Colors
# A more elegant way to have a scheme that doesn't print color codes (neither ANSI nor mIRC) at all. See below.
unset EMPTY
# DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW
ANSI_COLORS="       "
IRC_COLORS=" \x0314 \x0301 \x0304 \x0305 \x0309 \x0303 \x0308 \x0307"
# BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL
ANSI_COLORS="$ANSI_COLORS         "
IRC_COLORS=" $IRC_COLORS \x0312 \x0302 \x0313 \x0306 \x0311 \x0310 \x0300 \x0315 \x03"

#ANSI_COLORS=($ANSI_COLORS); IRC_COLORS=($IRC_COLORS)
A_COLORS_AVAILABLE=( DGREY BLACK RED DRED GREEN DGREEN YELLOW DYELLOW BLUE DBLUE MAGENTA DMAGENTA CYAN DCYAN WHITE GREY NORMAL )
# See above for notes on EMPTY
A_COLOR_SCHEMES=( EMPTY,EMPTY,EMPTY NORMAL,NORMAL,NORMAL BLUE,NORMAL,NORMAL GREEN,YELLOW,NORMAL DYELLOW,NORMAL,NORMAL CYAN,BLUE,NORMAL RED,NORMAL,NORMAL GREEN,NORMAL,NORMAL YELLOW,NORMAL,NORMAL GREEN,DGREEN,NORMAL BLUE,RED,NORMAL BLUE,NORMAL,RED YELLOW,WHITE,GREEN BLUE,NORMAL,GREEN DCYAN,NORMAL,DMAGENTA )
## Actual color variables
C1=''
C2=''
CN=''

### Distro Data
# 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)
DISTROS_DERIVED="antix-version kanotix-version knoppix-version mandrake-release pardus-release sabayon-release sidux-version turbolinux-release zenwalk-version"
# debian_version excluded from DISTROS_PRIMARY so Debian can fall through to /etc/issue detection. Same goes for Ubuntu.
DISTROS_EXCLUDE_LIST="debian_version ubuntu_version"
DISTROS_PRIMARY="gentoo-release redhat-release slackware-version SuSE-release"
DISTROS_LSB_GOOD="mandrake-release mandriva-release mandrakelinux-release"
## Distros with known problems
# DSL (Bash 2.05b: grep -m doesn't work; arrays won't work) --> unusable output
# Puppy Linux 4.1.2 (Bash 3.0: arrays won't work) --> works partially

### Bans Data
# Precede a banword with $'\2' to prevent it from being subject to automated escaping by the make_ban_lists routine
# $'\1' gets weird results :
# 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.|
A_NORMAL_BANS=( corporation communications gmbh technologies technology group $'\2'"\<ltd\>" ltd. $'\2'"\<inc\>" inc. $'\2'\<co\> co. "(tm)" "(r)" "®" $'\2'"\(rev ..\)" )
A_CPU_BANS=( @ cpu deca 'dual core' dual-core 'tri core' tri-core 'quad core' quad-core ennea genuine hepta hexa multi octa penta 'processor' processor single triple $'\2'"[0-9.]+ *[MmGg][Hh][Zz]" )
# after processing, the ban arrays will be put into these:
BAN_LIST_NORMAL=''
BAN_LIST_CPU=''

# WARNING: In the main part below (search for 'KONVI')
# there's a check for Konversation-specific config files.
# Any one of these can override the above if inxi is run
# from Konversation!

########################################################################
#### MAIN: Where it all begins
########################################################################
main()
{
eval $LOGFS

# This function just initializes variables
initialize_script_data

# Check for dependencies BEFORE running ANYTHING else except above functions
# Not all distro's have these depends installed by default
check_script_depends
check_script_suggested_apps

# first init function must be set first for colors etc. Remember, no debugger
# stuff works on this function unless you set the debugging flag manually.
# Debugging flag -@ [number] will not work until get_parameters runs.

### Only continue if depends ok
SCRIPT_PATH=$( dirname $0 )
SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )

### Source global config overrides
if [[ -s /etc/$SCRIPT_NAME.conf ]];then
source /etc/$SCRIPT_NAME.conf
fi
# Source user config overrides, ~/.inxi/inxi.conf
if [[ -s $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf ]];then
source $HOME/.$SCRIPT_NAME/$SCRIPT_NAME.conf
fi

## this needs to run before the KONVI stuff is set below
## Konversation 1.2 apparently does not like the $PPID test in get_start_client
## So far there is no known way to detect if qt4_konvi is the parent process
## this method will infer qt4_konvi as parent

get_start_client

# 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
# KONVI=3 ## for testing puroses
##
if [[ $KONVI -eq 1 || $KONVI -eq 3 ]];then

if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (ie 1.x < 1.2(qt3))
DCPORT="$1"
DCSERVER="$2"
DCTARGET="$3"
shift 3
elif [[ $KONVI -eq 3 ]]; then ## dbus Konversation (> 1.2 (qt4))
DCSERVER="$1" ##dbus testing
DCTARGET="$2" ##dbus testing
shift 2
fi

# The section below is on request of Argonel from the Konversation developer team:
# it sources config files like $HOME/.kde/share/apps/konversation/scripts/inxi.conf
IFS=":"
for kde_config in $( kde-config --path data )
do
if [[ -r ${kde_config}${KONVI_CFG} ]];then
source "${kde_config}${KONVI_CFG}"
break
fi
done
IFS="$ORIGINAL_IFS"
fi

## leave this for debugging dcop stuff if we get that working
# print_screen_output "DCPORT: $DCPORT"
# print_screen_output "DCSERVER: $DCSERVER"
# print_screen_output "DCTARGET: $DCTARGET"

# "$@" passes every parameter separately quoted, "$*" passes all parameters as one quoted parameter.
# must be here to allow debugger and other flags to be set.
get_parameters "$@"

# If no colorscheme was set in the parameter handling routine, then set the default scheme
if [[ $COLOR_SCHEME_SET != 'true' ]];then
set_color_scheme "$DEFAULT_SCHEME"
fi

# all the pre-start stuff is in place now
B_SCRIPT_UP='true'
script_debugger "Debugger: $SCRIPT_NAME is up and running..."

# then create the output
print_it_out

## last steps
if [[ $B_RUNNING_IN_SHELL == 'true' && $SCHEME -gt 0 ]];then
echo -n ""
fi
eval $LOGFE
# weechat's executor plugin forced me to do this, and rightfully so, because else the exit code
# from the last command is taken..
exit 0
}

#### -------------------------------------------------------------------
#### basic tests: set script data, booleans, PATH
#### -------------------------------------------------------------------

# Set PATH data so we can access all programs as user. Set BAN lists.
# initialize some boleans, these directories are used throughout the script
# some apps are used for extended functions any directory used, should be
# checked here first.
# No args taken.
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\""'

# Do this after sourcing of config overrides so user can customize banwords
BAN_LIST_NORMAL=$( make_ban_lists "${A_NORMAL_BANS[@]}" ) # Contrary to my previous belief, "${ARR[@]}" passes a quoted list, not one string
BAN_LIST_CPU=$( make_ban_lists "${A_CPU_BANS[@]}" )
##echo "BAN_LIST_NORMAL='$BAN_LIST_NORMAL'"

# now set the script BOOLEANS for files required to run features
if [[ -d "/proc/" ]];then
B_PROC='true'
else
error_handler 6
fi

if [[ -e $FILE_CPUINFO ]]; then
B_CPUINFO='true'
fi

if [[ -e $FILE_MEMINFO ]];then
B_MEMINFO='true'
fi

if [[ -e $FILE_ASOUND_DEVICE ]];then
B_ASOUND_CARDS='true'
fi

if [[ -e $FILE_ASOUND_VERSION ]];then
B_ASOUND_VERSION='true'
fi

if [[ -f $FILE_LSB_RELEASE ]];then
B_LSB_DIR='true'
fi

if [[ -e $FILE_SCSI ]];then
B_SCSI_DIR='true'
fi

# lack of ifconfig will throw an error only upon it's usage
if [[ -n $( type -p ifconfig ) ]]; then
B_IFCONFIG='true'
else
A_INTERFACES_DATA=( "Interfaces tool requires missing app: ifconfig" )
fi

if [[ -n $( type -p sensors ) ]];then
B_SENSORS='true'
fi

if [[ -n $DISPLAY ]];then
B_X_RUNNING='true'
fi

if [[ -e $FILE_MODULES ]];then
B_MODULES_DIR='true'
fi

if [[ -e $FILE_MOUNTS ]];then
B_MOUNTS_DIR='true'
fi

if [[ -e $FILE_PARTITIONS ]];then
B_PARTITIONS_DIR='true'
fi
# gfx output will require this flag
if [[ $( whoami ) == 'root' ]];then
B_ROOT='true'
fi
eval $LOGFE
}

# No args taken.
check_script_suggested_apps()
{
eval $LOGFS
local bash_array_test=( "one" "two" )

# check for array ability of bash, this is only good for the warning at this time
# the boolean could be used later
# bash version 2.05b is used in DSL
# bash version 3.0 is used in Puppy Linux; it has a known array bug <reference to be placed here>
# versions older than 3.1 don't handle arrays
# distro's using below 2.05b are unknown, released in 2024
if [[ ${bash_array_test[1]} -eq "two" ]];then
B_BASH_ARRAY='true'
else
script_debugger "Suggestion: update to Bash v3.1 for optimal inxi output"
fi
eval $LOGFE
}

# Determine if any of the absolutely necessary tools are absent
# No args taken.
check_script_depends()
{
eval $LOGFS
local app_name='' app_data=''
# bc removed from deps for now
local depends="df free gawk grep hostname lspci ps readlink tr uname uptime wc"
local x_apps="xrandr xdpyinfo glxinfo"

if [[ $B_X_RUNNING == 'true' ]];then
for app_name in $x_apps
do
app_data=$( type -p $app_name )
if [[ -z $app_data ]];then
script_debugger "Resuming in non X mode: $app_name not found in path"
B_X_RUNNING='false'
break
fi
done
fi

app_name=''

for app_name in $depends
do
app_data=$( type -p $app_name )
if [[ -z $app_data ]];then
error_handler 5 "$app_name"
fi
done
eval $LOGFE
}

## note: this is now running inside each gawk sequence directly to avoid exiting gawk
## looping in bash through arrays, then re-entering gawk to clean up, then writing back to array
## in bash. For now I'll leave this here because there's still some interesting stuff to get re methods
# Enforce boilerplate and buzzword filters
# args: $1 - BAN_LIST_NORMAL/BAN_LIST_CPU; $2 - string to sanitize
sanitize_characters()
{
eval $LOGFS
# Cannot use strong quotes to unquote a string with pipes in it!
# bash will interpret the |'s as usual and try to run a subshell!
# Using weak quotes instead, or use '"..."'
echo "$2" | gawk "
BEGIN {
IGNORECASE=1
}
{
gsub(/${!1}/,\"\")
gsub(/ [ ]+/,\" \") ## ([ ]+) with (space)
gsub(/^ +| +$/,\"\") ## (pipe char) with (nothing)
print ## prints (returns) cleaned input
}"
eval $LOGFE
}

# Filter boilerplate & buzzwords.
# args: $1 - quoted: "$@" array of ban terms
make_ban_lists()
{
eval $LOGFS
local ban_list=''
# Iterate over $@
## note: this is a weird, non-intuitive method, needs some documentation or rewriting
## if you declare ban_string it stops working, have to read up on this
for ban_string
do
# echo "term=\"$ban_string\"" # >&2
if [[ ${ban_string:0:1} = $'\2' ]];then
ban_list="${ban_list}${ban_list+|}${ban_string:1:${#ban_string}-1}"
else
# Automatically escapes [ ] ( ) . and +
ban_list="${ban_list}${ban_list+|}$( echo "$ban_string" | gawk '{
gsub(/([\[\]+().])/,"\\\\&")
print
}' )"
fi
done

echo "$ban_list"
eval $LOGFS
}
# make_ban_lists "${A_CPU_BANS[@]}";exit

# Set the colorscheme
# args: $1 = <scheme number>|<"none">
set_color_scheme()
{
eval $LOGFS
local i='' script_colors='' color_codes=''

if [[ $1 -ge ${#A_COLOR_SCHEMES[@]} ]];then
set -- 1
fi
# Set a global variable to allow checking for chosen scheme later
SCHEME="$1"
if [[ $B_RUNNING_IN_SHELL == 'true' ]];then
color_codes=( $ANSI_COLORS )
else
color_codes=( $IRC_COLORS )
fi
for (( i=0; i < ${#A_COLORS_AVAILABLE[@]}; i++ ))
do
eval "${A_COLORS_AVAILABLE[i]}=\"${color_codes[i]}\""
done
IFS=","
script_colors=( ${A_COLOR_SCHEMES[$1]} )
IFS="$ORIGINAL_IFS"
# then assign the colors globally
C1="${!script_colors[0]}"
C2="${!script_colors[1]}"
CN="${!script_colors[2]}"
# ((COLOR_SCHEME++)) ## note: why is this? ##
eval $LOGFE
}

########################################################################
#### UTILITY FUNCTIONS
########################################################################

#### -------------------------------------------------------------------
#### error handler, debugger, script updater
#### -------------------------------------------------------------------

# Error handling
# args: $1 - error number; $2 - optional, extra information
error_handler()
{
eval $LOGFS
local error_message=''

# assemble the error message
case $1 in
2) error_message="large flood danger, debug buffer full!"
;;
3) error_message="unsupported color scheme number: $2"
;;
4) error_message="unsupported verbosity level: $2"
;;
5) error_message="dependency not met: $2 not found in path"
;;
6) error_message="/proc not found! Quitting..."
;;
7) error_message="One of the options you entered in your script parameters: $2\nIs not supported. For supported options, check the help menu: $SCRIPT_NAME -h"
;;
8) error_message="the self-updater failed, wget exited with error: $2.\nYou probably need to be root.\nHint, to make for easy updates without being root, do: chown <user name> $SCRIPT_PATH/$SCRIPT_NAME"
;;
9) error_message="unsupported debugging level: $2"
;;
10)
error_message="the alt download url you provided: $2\nappears to be wrong, download aborted. Please note, the url\nneeds to end in /, without $SCRIPT_NAME, like: http://yoursite.com/downloads/"
;;
11)
error_message="unsupported testing option argument: -! $2"
;;
12)
error_message="the svn branch download url: $2\nappears to be empty currently. Make sure there is an actual svn branch version\nactive before you try this again. Check http://code.google.com/p/inxi\nto verify the branch status."
;;
*) error_message="error unknown: $@"
set -- 99
;;
esac
# then print it and exit
print_screen_output "Error $1: $error_message"
eval $LOGFE
exit $1
}

# prior to script up set, pack the data into an array
# then we'll print it out later.
# args: $1 - $@ debugging string text
script_debugger()
{
eval $LOGFS
if [[ $B_SCRIPT_UP == 'true' ]];then
# only return if debugger is off and no pre start up errors have occured
if [[ $DEBUG -eq 0 && $DEBUG_BUFFER_INDEX -eq 0 ]];then
return 0
# print out the stored debugging information if errors occured
elif [[ $DEBUG_BUFFER_INDEX -gt 0 ]];then
for (( DEBUG_BUFFER_INDEX=0; DEBUG_BUFFER_INDEX < ${#A_DEBUG_BUFFER[@]}; DEBUG_BUFFER_INDEX++ ))
do
print_screen_output "${A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]}"
done
DEBUG_BUFFER_INDEX=0
fi
# or print out normal debugger messages if debugger is on
if [[ $DEBUG -gt 0 ]];then
print_screen_output "$1"
fi
else
if [[ $B_DEBUG_FLOOD == 'true' && $DEBUG_BUFFER_INDEX -gt 10 ]];then
error_handler 2
# this case stores the data for later printout, will print out only
# at B_SCRIPT_UP == 'true' if array index > 0
else
A_DEBUG_BUFFER[$DEBUG_BUFFER_INDEX]="$1"
# increment count for next pre script up debugging error
(( DEBUG_BUFFER_INDEX++ ))
fi
fi
eval $LOGFE
}

# NOTE: no logging available until get_parameters is run, since that's what sets logging
# in order to trigger earlier logging manually set B_USE_LOGGING to true in top variables.
# $1 alone: logs data; $2 with or without $3 logs func start/end.
# $1 type (fs/fe/cat/raw) or logged data; [$2 is $FUNCNAME; [$3 - function args]]
log_function_data()
{
if [ "$B_USE_LOGGING" == 'true' ];then
local logged_data='' spacer=' ' line='----------------------------------------'
case $1 in
fs)
logged_data="Function: $2 - Primary: Start"
if [ -n "$3" ];then
logged_data="$logged_data\n${spacer}Args: $3"
fi
spacer=''
;;
fe)
logged_data="Function: $2 - Primary: End"
spacer=''
;;
cat)
if [[ $B_LOG_FULL_DATA == 'true' ]];then
logged_data="\n$line\nFull file data: cat $2\n\n$( cat $2 )\n$line\n"
spacer=''
fi
;;
raw)
if [[ $B_LOG_FULL_DATA == 'true' ]];then
logged_data="\n$line\nRaw system data:\n\n$2\n$line\n"
spacer=''
fi
;;
*)
logged_data="$1"
;;
esac
# Create any required line breaks and strip out escape color code, either ansi (case 1)or irc (case 2).
# This pattern doesn't work for irc colors, if we need that someone can figure it out
if [[ -n $logged_data ]];then
if [[ $B_LOG_COLORS != 'true' ]];then
echo -e "${spacer}$logged_data" | sed -r 's/\x1b\[[0-9]{1,2}(;[0-9]{1,2}){0,2}m//g' >> $LOG_FILE
else
echo -e "${spacer}$logged_data" >> $LOG_FILE
fi
fi
fi
}

# called in the initial -@ 10 script args setting so we can get logging as soon as possible
# will have max 3 files, inxi.log, inxi.1.log, inxi.2.log
create_rotate_logfiles()
{
if [[ ! -d $SCRIPT_DATA_DIR ]];then
mkdir $SCRIPT_DATA_DIR
fi
# do the rotation if logfile exists
if [[ -f $LOG_FILE ]];then
# copy if present second to third
if [[ -f $LOG_FILE_1 ]];then
mv -f $LOG_FILE_1 $LOG_FILE_2
fi
# then copy initial to second
mv -f $LOG_FILE $LOG_FILE_1
fi
# now create the logfile
touch $LOG_FILE
# and echo the start data
echo "=========================================================" >> $LOG_FILE
echo "START $SCRIPT_NAME LOGGING:" >> $LOG_FILE
echo "Script started: $( date +%Y-%m-%d-%H:%M:%S )" >> $LOG_FILE
echo "=========================================================" >> $LOG_FILE
}

# args: $1 - download url, not including file name; $2 - string to print out
# note that $1 must end in / to properly construct the url path
script_self_updater()
{
eval $LOGFS
local wget_error=0
print_screen_output "Starting $SCRIPT_NAME self updater."
print_screen_output "Currently running $SCRIPT_NAME version number: $SCRIPT_VERSION_NUMBER"
print_screen_output "Updating $SCRIPT_NAME in $SCRIPT_PATH using $2 as download source..."
# first test if path is good, need to make sure it's good because we're -O overwriting file
wget -q --spider $1$SCRIPT_NAME || wget_error=$?
# then do the actual download
if [[ $wget_error -eq 0 ]];then
wget -q -O $SCRIPT_PATH/$SCRIPT_NAME $1$SCRIPT_NAME || wget_error=$?
if [[ $wget_error -eq 0 ]];then
SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
print_screen_output "Successfully updated to $2 version: $SCRIPT_VERSION_NUMBER"
print_screen_output "To run the new version, just start $SCRIPT_NAME again."
exit 0
fi
fi
# now run the error handlers on any wget failure
if [[ $wget_error -gt 0 ]];then
if [[ $2 == 'svn server' ]];then
error_handler 8 "$wget_error"
elif [[ $2 == 'alt server' ]];then
error_handler 10 "$1"
else
error_handler 12 "$1"
fi
fi
eval $LOGFS
}

#### -------------------------------------------------------------------
#### print / output cleaners
#### -------------------------------------------------------------------

# inxi speaks through here. When run by Konversation script alias mode, uses DCOP
# for dcop to work, must use 'say' operator, AND colors must be evaluated by echo -e
# note: dcop does not seem able to handle \n so that's being stripped out and replaced with space.
print_screen_output()
{
eval $LOGFS
# the double quotes are needed to avoid losing whitespace in data when certain output types are used
local print_data="$( echo -e "$1" )"

# just using basic debugger stuff so you can tell which thing is printing out the data. This
# should help debug kde 4 konvi issues when that is released into sid, we'll see. Turning off
# the redundant debugger output which as far as I can tell does exactly nothing to help debugging.
if [[ $DEBUG -gt 5 ]];then
if [[ $KONVI -eq 1 ]];then
# konvi doesn't seem to like \n characters, it just prints them literally
# print_data="$( tr '\n' ' ' <<< "$print_data" )"
# dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "konvi='$KONVI' saying : '$print_data'"
print_data="KP-$KONVI: $print_data"
elif [[ $KONVI -eq 2 ]];then
# echo "konvi='$KONVI' saying : '$print_data'"
print_data="KP-$KONVI: $print_data"
else
# echo "printing out: '$print_data'"
print_data="P: $print_data"
fi
fi

if [[ $KONVI -eq 1 ]]; then ## dcop Konversation (<= 1.1 (qt3))
# konvi doesn't seem to like \n characters, it just prints them literally
$print_data="$( tr '\n' ' ' <<< "$print_data" )"
dcop "$DCPORT" "$DCOPOBJ" say "$DCSERVER" "$DCTARGET" "$print_data"

elif [[ $KONVI -eq 3 ]]; then ## dbus Konversation (> 1.2 (qt4))
qdbus org.kde.konversation /irc say "$DCSERVER" "$DCTARGET" "$print_data"

# elif [[ $IRC_CLIENT == 'X-Chat' ]]; then
# qdbus org.xchat.service print "$print_data\n"

else
# the -n is needed to avoid double spacing of output in terminal
echo -ne "$print_data\n"
fi
eval $LOGFE
}

## this handles all verbose line construction with indentation/line starter
## args: $1 - null (, actually: " ") or line starter; $2 - line content
create_print_line()
{
eval $LOGFS
printf "${C1}%-${INDENT}s${C2} %s" "$1" "$2"
eval $LOGFE
}

# this removes newline and pipes.
# args: $1 - string to clean
remove_erroneous_chars()
{
eval $LOGFS
## RS is input record separator
## gsub is substitute;
gawk '
BEGIN {
RS=""
}
{
gsub(/\n$/,"") ## (newline; end of string) with (nothing)
gsub(/\n/," "); ## (newline) with (space)
gsub(/^ *| *$/, "") ## (pipe char) with (nothing)
gsub(/ +/, " ") ## ( +) with (space)
gsub(/ [ ]+/, " ") ## ([ ]+) with (space)
gsub(/^ +| +$/, "") ## (pipe char) with (nothing)
printf $0
}' "$1" ## prints (returns) cleaned input
eval $LOGFE
}

#### -------------------------------------------------------------------
#### parameter handling, print usage functions.
#### -------------------------------------------------------------------

# Get the parameters. Note: standard options should be lower case, advanced or testing, upper
# args: $1 - full script startup args: $@
get_parameters()
{
eval $LOGFS
local opt='' wget_test='' update_flags='U!:'
local use_short='true' # this is needed to trigger short output, every v/d/F/line trigger sets this false

# <comment here. what is this for?>
if [[ $B_ALLOW_UPDATE == 'false' ]];then
update_flags=''
fi

# the short form only runs if no args output args are used
# no need to run through these if there are no args
if [[ -n $1 ]];then
while getopts Ac:CdDfFGhHiIlNpPsSuv:Vx%@:${update_flags} opt
do
case $opt in
A) B_SHOW_AUDIO='true'
use_short='false'
;;
c) if [[ -n $( egrep '^[0-9][0-9]?$' <<< $OPTARG ) ]];then
COLOR_SCHEME_SET='true'
## note: not sure about this, you'd think user values should be overridden, but
## we'll leave this for now
if [[ -z $COLOR_SCHEME ]];then
set_color_scheme "$OPTARG"
fi
else
error_handler 3 "$OPTARG"
fi
;;
C) B_SHOW_CPU='true'
use_short='false'
;;
d) VERBOSITY_LEVEL=1
use_short='false'
;;
D) B_SHOW_DISK='true'
use_short='false'
;;
f) B_SHOW_CPU='true'
B_CPU_FLAGS_FULL='true'
use_short='false'
;;
F) VERBOSITY_LEVEL=$VERBOSITY_LEVELS
B_EXTRA_DATA='true'
B_SHOW_DISK='true'
B_SHOW_PARTITIONS='true'
B_SHOW_AUDIO='true'
use_short='false'
;;
G) B_SHOW_GRAPHICS='true'
use_short='false'
;;
i) B_SHOW_IP='true'
B_SHOW_NETWORK='true'
use_short='false'
;;
I) B_SHOW_INFO='true'
use_short='false'
;;
l) B_SHOW_LABELS='true'
B_SHOW_PARTITIONS='true'
use_short='false'
;;
N) B_SHOW_NETWORK='true'
use_short='false'
;;
p) B_SHOW_PARTITIONS_FULL='true'
B_SHOW_PARTITIONS='true'
use_short='false'
;;
P) B_SHOW_PARTITIONS='true'
use_short='false'
;;
s) B_SHOW_SENSORS='true'
use_short='false'
;;
S) B_SHOW_SYSTEM='true'
use_short='false'
;;
u) B_SHOW_UUIDS='true'
B_SHOW_PARTITIONS='true'
use_short='false'
;;
v) if [[ -n $( egrep "^[0-9][0-9]?$" <<< $OPTARG ) && $OPTARG -le $VERBOSITY_LEVELS ]];then
VERBOSITY_LEVEL="$OPTARG"
if [[ $OPTARG -gt 0 ]];then
use_short='false'
fi
else
error_handler 4 "$OPTARG"
fi
;;
U) script_self_updater "$SCRIPT_DOWNLOAD" 'svn server'
;;
V) print_version_info
exit 0
;;
x) B_EXTRA_DATA='true'
;;
h) show_options
exit 0
;;
H) show_options 'full'
exit 0
;;
## debuggers and testing tools
%) B_HANDLE_CORRUPT_DATA='true'
;;
@) if [[ -n $( egrep "^([1-9]|10)$" <<< $OPTARG ) ]];then
DEBUG=$OPTARG
exec 2>&1
# switch on logging only for -@ 8-10
if [[ $OPTARG -ge 8 ]];then
if [[ $OPTARG -eq 10 ]];then
B_LOG_COLORS='true'
elif [[ $OPTARG -eq 9 ]];then
B_LOG_FULL_DATA='true'
fi
B_USE_LOGGING='true'
# pack the logging data for evals function start/end
LOGFS=$LOGFS_STRING
LOGFE=$LOGFE_STRING
create_rotate_logfiles # create/rotate logfiles before we do anything else
fi
else
error_handler 9 "$OPTARG"
fi
;;
!) # test for various supported methods
case $OPTARG in
1) B_TESTING_1='true'
;;
2) B_TESTING_2='true'
;;
3) B_TESTING_1='true'
B_TESTING_2='true'
;;
10)
script_self_updater "$SCRIPT_DOWNLOAD_DEV" 'dev server'
;;
11)
script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_1" 'svn: branch one server'
;;
12)
script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_2" 'svn: branch two server'
;;
13)
script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_3" 'svn: branch three server'
;;
14)
script_self_updater "$SCRIPT_DOWNLOAD_BRANCH_4" 'svn: branch four server'
;;
http*)
script_self_updater "$OPTARG" 'alt server'
;;
*) error_handler 11 "$OPTARG"
;;
esac
;;
*) error_handler 7 "$1"
;;
esac
done
fi
## this must occur here so you can use the debugging flag to show errors
## Reroute all error messages to the bitbucket (if not debugging)
if [[ $DEBUG -eq 0 ]];then
exec 2>/dev/null
fi
#((DEBUG)) && exec 2>&1 # This is for debugging konversation

# after all the args have been processed, if no long output args used, run short output
if [[ $use_short == 'true' ]];then
B_SHOW_SHORT_OUTPUT='true'
fi
eval $LOGFE
}

## print out help menu, not including Testing or Debugger stuff because it's not needed
show_options()
{
local color_scheme_count=${#A_COLOR_SCHEMES[@]}

print_screen_output "$SCRIPT_NAME supports the following options. You can combine them, or list them"
print_screen_output "one by one: Examples: $SCRIPT_NAME -v4 -c6 OR $SCRIPT_NAME -dDc 6"
print_screen_output ""
print_screen_output "If you start $SCRIPT_NAME with no arguments, it will show the short form."
print_screen_output "The following options if used without -d or -v will show just that complete line:"
print_screen_output "A,C,D,G,I,N,P,S - you can use these together to show just the lines you want to see."
print_screen_output "If you use them with a -v level (or -d), it will show the full output for that line "
print_screen_output "along with the output for the chosen verbosity level."
print_screen_output "- - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
print_screen_output "Output Control Options:"
print_screen_output "-A Show Audio/sound card information."
print_screen_output "-c Available color schemes. Scheme number is required."
print_screen_output " Supported schemes: 0-$color_scheme_count Example: $SCRIPT_NAME -c 11"
print_screen_output "-C Show full CPU output, including per CPU clockspeed."
print_screen_output "-d Default output verbosity level, same as: $SCRIPT_NAME -v 1"
print_screen_output "-D Show full hard Disk info, not only model, ie: /dev/sda ST380817AS 80.0GB."
print_screen_output "-f Show all cpu flags used, not just the short list. Not shown with -F to avoid spamming."
print_screen_output "-F Show Full output for $SCRIPT_NAME. Does not show extra verbose options like -f -u -l or -p"
print_screen_output "-G Show Graphic card information (card, x type, resolution, glx renderer, version)."
print_screen_output "-i Show Wan IP address, and shows local interfaces (requires ifconfig network tool)."
print_screen_output " Not shown with -F for user security reasons, you shouldn't paste your local/wan IP."
print_screen_output "-I Show Information: processes, uptime, memory, irc client, inxi version."
print_screen_output "-l Show partition labels. Default: short partition -P. For full -p output, use: -pl (or -plu)."
print_screen_output "-N Show Network card information."
print_screen_output "-p Show full partition information (-P plus all other detected partitions)."
print_screen_output "-P Show Partition information (shows what -v 4 would show, but without extra data)."
print_screen_output " Shows, if detected: / /boot /home /tmp /usr /var. Use -p to see all mounted partitions."
print_screen_output "-s Show sensors output (if sensors installed/configured): mobo/cpu temp; detected fan speeds."
print_screen_output "-S Show System information: host name, kernel, distro"
print_screen_output "-u Show partition UUIDs. Default: short partition -P. For full -p output, use: -pu (or -plu)."
print_screen_output "-v Script verbosity levels. Verbosity level number is required."
print_screen_output " Supported levels: 0-${VERBOSITY_LEVELS} Example: $SCRIPT_NAME -v 4"
print_screen_output " 0 - short output, same as: $SCRIPT_NAME"
print_screen_output " 1 - basic verbose, same as: $SCRIPT_NAME -d"
print_screen_output " 2 - Also show networking card data"
print_screen_output " 3 - Also show hard disk names as detected."
print_screen_output " 4 - Also show partition size/filled data for (if present):/, /home, /var/, /boot"
print_screen_output " 5 - For multicore systems, also shows: per core clock speeds; audio card; full disk data."
print_screen_output "-x Show extra data: bogomips on Cpu; driver version (if available) for Network/Audio;"
print_screen_output " direct rendering status for Graphics (in X). Only works with verbose or line output."
print_screen_output " Shows hdd temp with disk data if you have hddtemp installed, if you are root OR if you have"
print_screen_output " added to /etc/sudoers (sudo v. 1.7 or newer) (path to hddtemp): <username> ALL = NOPASSWD: /usr/sbin/hddtemp"
print_screen_output ""
print_screen_output "Additional Options:"
print_screen_output "-h - this help menu."
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."
fi
print_screen_output "-V $SCRIPT_NAME version information. Prints information then exits."
print_screen_output "-% Overrides defective or corrupted data."
print_screen_output "-@ Triggers debugger output. Requires debugging level 1-10 (8-10 - logging)."
print_screen_output " 8 - basic logging; 9 - full file/sys info logging; 10 - color logging."
if [[ $1 == 'full' ]];then
print_screen_output ""
print_screen_output "Developer and Testing Options (Advanced):"
print_screen_output "-! 1 - Sets testing flag B_TESTING_1='true' to trigger testing condition 1."
print_screen_output "-! 2 - Sets testing flag B_TESTING_2='true' to trigger testing condition 2."
print_screen_output "-! 3 - Sets flags B_TESTING_1='true' and B_TESTING_2='true'."
print_screen_output "-! 10 - Triggers an update from the primary dev download server instead of svn."
print_screen_output "-! 11 - Triggers an update from svn branch one - if present, of course."
print_screen_output "-! 12 - Triggers an update from svn branch two - if present, of course."
print_screen_output "-! 13 - Triggers an update from svn branch three - if present, of course."
print_screen_output "-! 14 - Triggers an update from svn branch four - if present, of course."
print_screen_output "-! <http://......> - Triggers an update from whatever server you list."
print_screen_output ""
fi
print_screen_output ""
}

## print out version information for -V/--version
print_version_info()
{
local last_modified=$( grep -im 1 'date:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3,$4,$5}' )

print_screen_output "$SCRIPT_NAME - the universal, portable, system info script for irc."
print_screen_output "Version: $SCRIPT_VERSION_NUMBER"
print_screen_output "Script Last Modified: $last_modified"
print_screen_output "Script Location: $SCRIPT_PATH"
print_screen_output ""
print_screen_output "Tested with Irssi, Xchat, Konversation, BitchX, KSirc, ircII,"
print_screen_output "Gaim/Pidgin, Weechat, KVIrc and Kopete."
print_screen_output ""
print_screen_output "This script is a fork of Infobash 3.02, which is:"
print_screen_output "Copyright (C) 2024-2007 Michiel de Boer a.k.a. locsmif"
print_screen_output "Subsequent changes and modifications (after Infobash 3.02) are:"
print_screen_output "Copyright (C) 2024-9 Scott Rogers, Harald Hope, aka trash80 & h2"
print_screen_output ""
print_screen_output "This program is free software; you can redistribute it and/or modify"
print_screen_output "it under the terms of the GNU General Public License as published by"
print_screen_output "the Free Software Foundation; either version 3 of the License, or"
print_screen_output "(at your option) any later version."
}

########################################################################
#### MAIN FUNCTIONS
########################################################################

#### -------------------------------------------------------------------
#### initial startup stuff
#### -------------------------------------------------------------------

# Determine where inxi was run from, set IRC_CLIENT and IRC_CLIENT_VERSION
get_start_client()
{
eval $LOGFS
local irc_client_path='' irc_client_path_lower='' non_native_konvi='' i=''
local b_non_native_app='false' pppid='' app_working_name=''
local b_qt4_konvi='false'

if tty >/dev/null;then
IRC_CLIENT='Shell'
unset IRC_CLIENT_VERSION
B_RUNNING_IN_SHELL='true'
elif [[ -n $PPID && -f /proc/$PPID/exe ]];then
irc_client_path=$( readlink /proc/$PPID/exe )
irc_client_path_lower=$( tr '[:upper:]' '[:lower:]' <<< $irc_client_path )
app_working_name=$( basename $irc_client_path_lower )
# handles the xchat/sh/bash/dash cases, and the konversation/perl cases, where clients
# report themselves as perl or unknown shell. IE: when konversation starts inxi
# from inside itself, as a script, the parent is konversation/xchat, not perl/bash etc
# note: perl can report as: perl5.10.0, so it needs wildcard handling
case $app_working_name in
bash|dash|sh|perl*) # We want to know who wrapped it into the shell or perl.
pppid="$( ps -p $PPID -o ppid --no-headers | sed 's/ //g' )"
if [[ -n $pppid && -f /proc/$pppid/exe ]];then
irc_client_path="$( readlink /proc/$pppid/exe )"
irc_client_path_lower="$( tr '[:upper:]' '[:lower:]' <<< $irc_client_path )"
app_working_name=$( basename $irc_client_path_lower )
b_non_native_app='true'
fi
;;
esac
# replacing loose detection with tight detection, bugs will be handled with app names
# as they appear.
case $app_working_name in
# check for shell first
bash|dash|sh)
unset IRC_CLIENT_VERSION
IRC_CLIENT="Shell wrapper"
;;
# now start on irc clients, alphabetically
bitchx)
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk '
/Version/ {
a=tolower($2)
gsub(/[()]|bitchx-/,"",a)
print a
exit
}
$2 == "version" {
a=tolower($3)
sub(/bitchx-/,"",a)
print a
exit
}' )"
IRC_CLIENT="BitchX"
;;
finch)
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
print $2
}' )"
IRC_CLIENT="Finch"
;;
gaim)
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
print $2
}' )"
IRC_CLIENT="Gaim"
;;
ircii)
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
print $3
}' )"
IRC_CLIENT="ircII"
;;
irssi-text|irssi)
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
print $2
}' )"
IRC_CLIENT="Irssi"
;;
konversation) ## konvi < 1.2 (qt4)
# this is necessary to avoid the dcop errors from starting inxi as a /cmd started script
if [[ $b_non_native_app == 'true' ]];then ## true negative is confusing
KONVI=2
else # if native app
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
# < Sho_> locsmif: The version numbers of SVN versions look like this:
# "<version number of last release>+ #<build number", i.e. "1.0+ #3177" ...
# for releases we remove the + and build number, i.e. "1.0" or soon "1.0.1"
IRC_CLIENT_VERSION=" CVS $IRC_CLIENT_VERSION"
T2="${T[0]/+/}"
else
IRC_CLIENT_VERSION=" ${T[0]}"
T2="${T[0]}"
fi
# 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)
}' )
# 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
# than 1 and change the DCOP parameter/object accordingly.
if [[ ${T2} -lt 1 ]];then
DCOPOBJ="Konversation"
fi
IRC_CLIENT="Konversation"
;;
kopete)
IRC_CLIENT_VERSION=" $( kopete -v | gawk '
/Kopete:/ {
print $2
exit
}' )"
IRC_CLIENT="Kopete"
;;
kvirc)
IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>&1 | gawk '{
for ( i=2; i<=NF; i++) {
if ( i == NF ) {
print $i
}
else {
printf $i" "
}
}
exit
}' )"
IRC_CLIENT="KVIrc"
;;
pidgin)
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
print $2
}' )"
IRC_CLIENT="Pidgin"
;;
quassel*)
# sample: quassel -v
# Qt: 4.5.0
# KDE: 4.2.65 (KDE 4.2.65 (KDE 4.3 >= 20240226))
# Quassel IRC: v0.4.0 [+60] (git-22effe5)
# note: early < 0.4.1 quassels do not have -v
IRC_CLIENT_VERSION=" $( $irc_client_path -v 2>/dev/null | gawk -F ': ' '
BEGIN {
IGNORECASE=1
clientVersion=""
}
/Quassel IRC/ {
clientVersion = $2
}
END {
# this handles pre 0.4.1 cases with no -v
if ( clientVersion == "" ) {
clientVersion = "(pre v0.4.1)"
}
print clientVersion
}' )"
# now handle primary, client, and core. quasselcore doesn't actually
# handle scripts with exec, but it's here just to be complete
case $app_working_name in
quassel)
IRC_CLIENT="Quassel [M]"
;;
quasselclient)
IRC_CLIENT="Quassel"
;;
quasselcore)
IRC_CLIENT="Quassel (core)"
;;
esac
;;
weechat-curses)
IRC_CLIENT_VERSION=" $( $irc_client_path -v ) "
IRC_CLIENT="Weechat"
;;
xchat-gnome)
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
print $2
}' )"
IRC_CLIENT="X-Chat-Gnome"
;;
xchat)
IRC_CLIENT_VERSION=" $( $irc_client_path -v | gawk 'NR == 1 {
print $2
}' )"
IRC_CLIENT="X-Chat"
;;
# then do some perl type searches, do this last s



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Thu Oct 08, 2024 11:38 am    Post subject: Reply with quote

Hmm, did not seem to all make it, but that gives you a pretty good idea what inxi is like - a bash script that is a serious and major extension (and fork) to infobash. See http://techpatterns.com/forums/about1131.html to get the complete script.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » System Administration and Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse