sidux.com

Scripts - sidux-info for (IRC) support

ModestUser - Jun 06, 2008 - 10:58 PM
Post subject: sidux-info for (IRC) support
sidux-paste is a great tool that is often used in IRC support. To faciliate support i suggest this small script sidux-info that gathers some information from the system and pastes it via sidux-paste.

What is displayed?
infobash output, lspci -nn, lsusb, nicinfo (replaced MACs), apt-get check, infobash, installed firmware, errors in X.org log, /etc/network/interfaces (SSIDs and passphrases are deleted for security reasons), check for "evil" package managers that should not be used, activated repositories, UUIDs of partitions, ...

Files
display-sidux-info: main file
sidux-info: display-sidux-info and pastes its output after showing it to the user

Feedback welcome!

Installation procedure
as root:
put both files in /usr/local/bin/
Code:
chmod +x /usr/local/bin/{sidux-info,display-sidux-info}


sidux-info:
Code:

#!/bin/bash

# wrapper to directly paste display-sidux-info
# asks user before uploading

function clean_up () {
    rm -f "${TMP_FILE}"
    exit 0
}

DSI_CMD="$(which display-sidux-info)"
if [[ -z ${DSI_CMD} ]]; then
    echo >&2 "Error: display-sidux-info not found."
    exit 1
fi

TMP_FILE="$(tempfile)"
cat >"${TMP_FILE}" <<EOF
# This file will be uploaded to a nopaste server. You will be presented a
# link that can be posted on the IRC channel. Please go over this file to
# ensure that no private information like real names, passphrases etc. is
# revealed.

START
EOF

if (($UID == 0)); then
    "${DSI_CMD}" >> "${TMP_FILE}"
else
    echo "You must be root to run this script!"
    su -c "${DSI_CMD} >> ${TMP_FILE}"
fi

pager "${TMP_FILE}"
clear
echo "Would you like to upload this information?"
select answer in "Yes" "No"; do
    case "${answer}" in
   "Yes")   sed -i '1,/^START/ d' "${TMP_FILE}"
      sidux-paste "${TMP_FILE}"
      clean_up
      ;;
   "No")   clean_up
      ;;
    esac
done


display-sidux-info:
Code:

#!/bin/bash
#
# FILE: sidux-info
# VERSION: 0.4
# COPYRIGHT: ModestUser
# LICENSE: GPLv2
#
# This script gathers useful information for bug-tracking. Its output can be
# pasted via the wrapper sidux-info. PSKs, MACs and passphrases are deleted
# from /etc/network/interfaces for security reasons.
#


#################################################
# functions
#################################################

LINE="================================================================================"

# check if $1 can be executed
function check_app () {
    echo -en "Check for ${1} ... "
    if which "$1" >/dev/null; then
   echo "found"
    else
   echo "not found"
    fi
}

# write title line
function title () {
    echo
    echo $1
    echo ${LINE:0:${#1}}
}

# check if $1 is opened and get the commands that holds it
# return value:
#   0 $1 is not open
#   1 $1 is open
function check_lock () {
    local lock_file="$1"
    if lsof $lock_file >/dev/null 2>&1; then
   local lock_owner="$(lsof $lock_file | awk 'NR==2 { print $1 }')"
   echo "$lock_file is opened by command $lock_owner."
   return 1
    else
   return 0
    fi
}

# check if root (sidux-info offers su -c in case you are not
if (($UID != 0)); then
    echo >&2 "ERROR: You must be root to run this script!"
    exit 1
fi

#################################################
# general info
#################################################

# full output of locale
title "original locale"
locale

# switch locale
LC_ALL=C
LANG=C

# call infobash -v3 without colors
title "INFOBASH output"
infobash -v3 0

# show runlevel (kdm should be 5 only)
title "runlevel"
echo "runlevel is $(runlevel | cut -d ' ' -f 2)."

# When migrating an old /home, it might happen that ownership is not set
# correctly. This function checks for UIDs and GIDs that have no user on this
# system. A chown -R is required then.
# The broken files are not shown for security reasons.
title "check for invalid UIDs or GIDs in /home"
[[ -z "$(find /home -maxdepth 2 -nouser -o -nogroup -quit)" ]] || echo "Files with invalid UID or GID have been found in /home!"


# smxi, sgfxi, and svmi are not part of sidux but it is good to know
# if they can be used.
# synaptic, adept and aptitude should not be used for d-u. Their existance is
# no problem but could indicate misuse.
title "check for some programs"

check_app smxi
check_app sgfxi
check_app svmi
check_app synaptic
check_app aptitude
check_app adept_manager

#################################################
# package management
#################################################

dpkg_update_file="/var/cache/apt/pkgcache.bin"
apt_lock="/var/lib/apt/lists/lock"
dpkg_lock="/var/lib/dpkg/lock"

title "status of apt-get / dpkg"

# get passed time since last apt-get update
if [[ -f $dpkg_update_file ]]; then
    now="$(date +%s)"
    last_dpkg_update="$(date -r $dpkg_update_file +%s)"
    printf "Last apt-get update took place %d minutes ago.\n"    $(( ($now - $last_dpkg_update) / 60 ))
fi

# check locks of apt-get and dpkg and show
# the commands that hold them
check_lock $apt_lock

if check_lock $dpkg_lock; then
    title "apt-get check"
    apt-get check
fi

# list all repositories that are available
# sources.list should be empty
title "repositories"
grep -irT '^deb' --include='*.list' --color=never /etc/apt

# show packages on hold
title "packages on hold"
dpkg -l | awk '/^hi/ { print $2 " (" $3 ")" }'

if which apt-show-versions >/dev/null; then
    # show packages from experimental
    title "packages from experimental"
    apt-show-versions | awk -F "/| " '{ if ($2 == "experimental") print $1 " (" $4 ")" }'
fi

#################################################
# firmware
#################################################

title "content of /lib/firmware"
ls /lib/firmware

title "installed firmware packages"
dpkg -l | grep firmware


#################################################
# networking
#################################################

# show /etc/network/interfaces, delete SSIDs, PSKs and passphrases
title "/etc/network/interfaces"
sed 's#\(psk\|ssid\|passphrase\) .\+#\1 <deleted by sidux-info>#' /etc/network/interfaces

# show nicinfo output with MACs deleted
title "nicinfo"
nicinfo | sed 's#\(..:\)\{5\}..#<deleted by sidux-info>#'

#################################################
# log files
#################################################

# list errors in Xorg.0.log
title "check for errors in X log files"
grep --color=never '^(EE)' /var/log/Xorg.0.log


#################################################
# hardware info
#################################################

title "lsusb"
lsusb

title "fdisk -l"
fdisk -l

title "free disk space"
df -h

title "/dev/disk/by-uuid"
ls -l /dev/disk/by-uuid

title "lspci -nn"
lspci -nn

title "loaded modules"
lsmod

echo
echo "================ END ========================="



Changelog
changelog 0.2: fix repository content, check for invalid UIDs/GIDs (typical when you failed to migrate your /home properly)

changelog 0.3: added many comments, offers su -c if you start it as non-root, checks for locks by dpkg and apt-get, shows free disk space, shows locales, shows packages on hold, shows if smxi/sgfxi is installed, removed dmesg output

changelog 0.4: add fdisk -l and /dev/disk/by-uuid; user is now asked before uploading
rdsu - Jun 06, 2008 - 11:31 PM
Post subject: RE: sidux-info for (IRC) support
Where should I put this to try?
ModestUser - Jun 07, 2008 - 12:13 AM
Post subject: RE: sidux-info for (IRC) support
/usr/local/bin/, made executable and owned by root
op4latino - Jun 07, 2008 - 03:32 AM
Post subject: RE: sidux-info for (IRC) support
or put it in your IRC client's script directory.

edit: nevermind, I had the wrong idea, /usr/bin or /usr/local/bin or a directory in /home then PATH="${PATH}/home/username/whatever-path" is good
rdsu - Jun 07, 2008 - 09:43 AM
Post subject: RE: sidux-info for (IRC) support
It seems that worked well Smile

http://rafb.net/p/GN6zO995.html

This could be useful Wink
op4latino - Jun 07, 2008 - 11:45 AM
Post subject: RE: sidux-info for (IRC) support
wait, so does this script only run as root?
I had the wrong idea, heh. I thought this script was called from the irc client, but still good idea
mylo - Jun 07, 2008 - 12:03 PM
Post subject: RE: sidux-info for (IRC) support
very nice thing!! Thanks
ModestUser - Jul 08, 2008 - 01:58 AM
Post subject: RE: sidux-info for (IRC) support
new version 0.3
h2 - Jul 08, 2008 - 05:25 AM
Post subject: RE: sidux-info for (IRC) support
ModestUser, you can slightly modify this script: http://smxi.googlecode.com/svn/trunk/dev-tools/zsl

to remove the need to set -x and chown root for users, this script is what I use to build smxi.zip, which does the same basic thing, it makes the files executable and chowns to root, as well as copying to the zip directory then zipping it up.

The only difference you'd need to make would be to change the zip command to tar whatever you use to create the tar.gz, and change the paths and variable names etc to make sense for your needs.

I'm putting up my little tool scripts for smxi, this is the last one, just finished it tonight, might as well be useful to other people.

When users unzip it, it's all ready to go, executable, owned by root.
ModestUser - Oct 10, 2008 - 09:09 PM
Post subject: RE: sidux-info for (IRC) support
new version 0.4. see changelog above

Recommendation to everyone here: Do not attach anything important as file. They seem to get lost over time.
rdsu - Oct 10, 2008 - 10:01 PM
Post subject: RE: sidux-info for (IRC) support
@ModestUser:

Is this a issue:
Code:
root@siduxbox:/home/rdsu# display-sidux-info

original locale
===============
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

INFOBASH output
===============
Host/Kernel/OS  "siduxbox" running Linux 2.6.26-5.slh.12-sidux-686 i686 [ sidux 2008-01 Νυξ - kde-lite - (200804112323) ]
CPU Info        Intel Pentium M 1024 KB cache flags( sse2 ) clocked at [ 1700.000 MHz ]
Videocard       ATI Radeon RV250 [Mobility FireGL 9000]  X.Org 1.4.2  [ 1400x1050@61.8hz ]
Network cards   Intel PRO/Wireless LAN 2100 3B Mini PCI Adapter
                Broadcom BCM4401 100Base-T
Processes 115 | Uptime 4:04 | Memory 414.2/1264.8MB | HDD ATA IC25N060ATMR04-0 Size 60GB (54%used) | Client Shell | Infobash v3.01

runlevel
========
runlevel is 5.

check for invalid UIDs or GIDs in /home
=======================================
/usr/local/bin/display-sidux-info: line 83: syntax error near unexpected token `\ '
/usr/local/bin/display-sidux-info: line 83: `[[ -z "$(find /home -maxdepth 2 -nouser -o -nogroup -quit)" ]] \ '

?
ModestUser - Oct 10, 2008 - 10:57 PM
Post subject: RE: sidux-info for (IRC) support
There should be no space after the \ in that line. This seems to be some copy and paste issue. It is one line now. Sorry for that.
rdsu - Oct 10, 2008 - 11:25 PM
Post subject: RE: sidux-info for (IRC) support
You also have the same issue here:

status of apt-get / dpkg
========================
/usr/local/bin/display-sidux-info: line 113: printf: : invalid number
Last apt-get update took place 0 minutes ago.
/usr/local/bin/display-sidux-info: line 114: 5: command not found
ModestUser - Oct 10, 2008 - 11:37 PM
Post subject: RE: sidux-info for (IRC) support
@rdsu: Thanks a lot for debugging! Smile There was one more \ in it.
rdsu - Oct 10, 2008 - 11:45 PM
Post subject: RE: sidux-info for (IRC) support
You are welcome! Wink

Now it seems to be fine... Wink

Thanks
All times are GMT
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits