Changes of Revision 68
[-] | Changed | _service:set_version:inventory-system.spec |
1
2 %define pkgname inventory-system 3 Name: inventory-system 4 Release: 0 5 -Version: 0.0.rev1763 6 +Version: 0.0.rev1770 7 Url: http://www.linux-administrator.com/ 8 License: GPLv2 9 Group: System 10 |
||
[+] | Changed | _service:recompress:tar_scm:inventory-system-0.0.rev1770.tar.bz2/client/inventory-system.conf ^ |
@@ -24,4 +24,9 @@ # CUSTOM_FUNCTIONS="" # - +## Description: Disable listed functions (space separated) +## Type: string +## Default: "" +# +DISABLE_FUNCTIONS="" +# | ||
[+] | Changed | _service:recompress:tar_scm:inventory-system-0.0.rev1770.tar.bz2/client/inventory-system.sh ^ |
@@ -1,8 +1,8 @@ #!/bin/bash # Inventory System # Author: Carsten Schoene -# $LastChangedDate: 2012-09-10 17:52:40 +0200 (Mon, 10 Sep 2012) $ -# $Rev: 1763 $ +# $LastChangedDate: 2012-09-11 15:41:47 +0200 (Tue, 11 Sep 2012) $ +# $Rev: 1770 $ # # Default options (can be changed by inventory-system.conf) DEBUG="yes" @@ -86,7 +86,7 @@ # script usage function usage { - echo "Usage: $0 [--help|--uuid|--all-disks|--disks|--systemtype|--serial|--cpu|--mem|--product|--arch|--os|--kernel|--mgmtmac|--mgmtip]" + echo "Usage: $0 [--help|--uuid|--all-disks|--disks|--systemtype|--serial|--cpu|--mem|--product|--arch|--os|--kernel|--mgmtmac|--mgmtip|--update]" echo -e "\t--help\t\tShows this help" echo -e "\t--uuid\t\tUUID of this system" echo -e "\t--disk\t\tRoot disk size of this system" @@ -101,11 +101,12 @@ echo -e "\t--kernel\tRunning kernel version" echo -e "\t--mgmtmac\tIPMI management MAC address" echo -e "\t--mgmtip\tIPMI management IP address" + echo -e "\t--update\trun update of this script" exit } RUN_FUNCTIONS="" -args=`${GETOPT} -a -o h -l help,uuid,disk,all-disks,systemtype,serial,cpu,mem,product,arch,os,kernel,mgmtmac,mgmtip -- "$@"` +args=`${GETOPT} -a -o h -l help,uuid,disk,all-disks,systemtype,serial,cpu,mem,product,arch,os,kernel,mgmtmac,mgmtip,update -- "$@"` if [ $? != 0 ] ; then usage fi @@ -168,6 +169,10 @@ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_mgmt_ip" shift ;; + -u|--update) + RUN_FUNCTIONS="${RUN_FUNCTIONS} autoupdate" + shift + ;; --) shift break @@ -175,8 +180,44 @@ esac done +# function to check if called function is in DISABLE_FUNCTIONS +function is_disabled { + FUNC_TO_CHECK=$1 + RETVAL=0 + for FUNC in ${DISABLE_FUNCTIONS} ; do + if [ "${FUNC}" == "${FUNC_TO_CHECK}" ] ; then + RETVAL=1 + fi + done + echo ${RETVAL} +} + +# autoupdate function +function autoupdate { + [ "`is_disabled $FUNCNAME`" == "1" ] && return + PKG=`rpm -qf --queryformat '%{name}\n' $0 | ${GREP} -v "^file /"` + YUM=`which yum 2>/dev/null` + ZYP=`which zypper 2>/dev/null` + if [ -n "${PKG}" ] ; then + if [ -n "${YUM}" ] ; then + CUPD="${YUM} check-update ${PK} | ${TAIL} -n1 | ${AWK} '{print $1}'" + if [ -n "`${CUPD}`" ] ; then + UPD="${YUM} -y update ${PKG}" + ${UPD} + fi + elif [ -n "${ZYP}" ] ; then + CUPD="${ZYP} -q lu | ${GREP} ${PKG}" + if [ -n "`${CUPD}`" ] ; then + UPD="${ZYP} -n update ${PKG}" + ${UPD} + fi + fi + fi +} + # get unique system uuid function get_system_uuid { + [ "`is_disabled $FUNCNAME`" == "1" ] && return # newer systems have uuid integrated UUID=`${LSHW} -quiet -C system | ${GREP} "configuration:" | ${GREP} -i uuid | ${SED} -e 's@.*[ \s]uuid=@@i'` # for older systems or virtual create one and save it for later use @@ -193,6 +234,7 @@ # read serialnumber / service tag with dmidecode function get_system_serial { + [ "`is_disabled $FUNCNAME`" == "1" ] && return SYSSERIAL=`${DMIDECODE} -s system-serial-number` debug "SYSTEM-SERIAL: ${SYSSERIAL}" echo ${SYSSERIAL} @@ -200,12 +242,14 @@ # get list of MAC addresses from lshw function get_system_macs { + [ "`is_disabled $FUNCNAME`" == "1" ] && return ${LSHW} -quiet -C network | ${GREP} serial: | ${AWK} '{print tolower($NF)}' | ${SORT} -u | \ ${GREP} -i -E '([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})' } # get interface name from MAC address function get_iface_name_from_mac { + [ "`is_disabled $FUNCNAME`" == "1" ] && return MAC=${1} debug ${MAC} ${IFCONFIG} -a | ${GREP} -i ${MAC} | ${AWK} '{print $1}' | ${HEAD} -n1 @@ -213,6 +257,7 @@ # get link state for interface from ethtool function get_iface_link_state { + [ "`is_disabled $FUNCNAME`" == "1" ] && return IFACE=${1} debug ${IFACE} ${ETHTOOL} ${IFACE} | ${GREP} -i "Link detected:" | ${AWK} '{print tolower($NF)}' @@ -220,6 +265,7 @@ # get system type function get_system_type { + [ "`is_disabled $FUNCNAME`" == "1" ] && return RETVAL=`${VIRTWHAT}` if [ $? == 0 ] ; then TYPE=`${VIRTWHAT} | ${TAIL} -n1` @@ -235,6 +281,7 @@ # get system cpu type function get_system_cpu { + [ "`is_disabled $FUNCNAME`" == "1" ] && return CPU=`${LSHW} -quiet -C processor | ${GREP} "product:" | ${SORT} -u | ${AWK} -F"product: " '{ print $NF}' | ${HEAD} -n1 | ${SED} -e 's@\s\+@ @g'` debug "SYSTEM-CPU: ${CPU}" echo ${CPU} @@ -242,6 +289,7 @@ # get system memory in MB function get_system_memory { + [ "`is_disabled $FUNCNAME`" == "1" ] && return INSTMEM=0 case `get_system_type` in xen-domU|openvz) @@ -260,6 +308,7 @@ # get the disk size of boot device function get_system_disk_size_bootdev { + [ "`is_disabled $FUNCNAME`" == "1" ] && return case `get_system_type` in openvz) SIZE=`LANG=C ${DF} / | ${GREP} -v ^Filesystem| ${AWK} '{print $2 / 1024}'` @@ -337,13 +386,15 @@ # get all (v)disks with sizes function get_system_disk_sizes { - DEV_SIZES=`LANG=C ${FDISK} -l 2>/dev/null | ${GREP} "^Disk /" | ${AWK} '{print $2","int($(NF-1)/1000/1000)}' | ${SED} -e 's@:,@,@' | ${GREP} -E '(/dev/cciss/c[0-9]d[0-9]|/dev/x?[hsv]d[a-z],[0-9]{1,9})'` + [ "`is_disabled $FUNCNAME`" == "1" ] && return + DEV_SIZES=`LANG=C ${FDISK} -l 2>/dev/null | ${GREP} "^Disk /" | ${SORT} | ${AWK} '{print $2","int($(NF-1)/1000/1000)}' | ${SED} -e 's@:,@,@' | ${GREP} -E '(/dev/cciss/c[0-9]d[0-9]|/dev/x?[hsv]d[a-z],[0-9]{1,9})'` debug "SYSTEM-DEVS-SIZES: ${DEV_SIZES}" echo ${DEV_SIZES} } # get product name function get_system_productname { + [ "`is_disabled $FUNCNAME`" == "1" ] && return PRODNAME=`${DMIDECODE} -s system-product-name` debug "SYSTEM-PRODUCTNAME: ${PRODNAME}" echo ${PRODNAME} @@ -351,6 +402,7 @@ # get system vendor function get_system_manufacturer { + [ "`is_disabled $FUNCNAME`" == "1" ] && return SYSMANUF=`${DMIDECODE} -s system-manufacturer` debug "SYSTEM-MANUFACTURER: ${SYSMANUF}" echo ${SYSMANUF} @@ -358,6 +410,7 @@ # get system bios version function get_system_biosversion { + [ "`is_disabled $FUNCNAME`" == "1" ] && return BIOSV=`${DMIDECODE} -s bios-version` debug "BIOS-VERSION: ${BIOSV}" echo ${BIOSV} @@ -365,6 +418,7 @@ # get comma seperated list of ethernet devices (mac,iface,link) function get_system_net_info { + [ "`is_disabled $FUNCNAME`" == "1" ] && return for MAC in `get_system_macs` ; do IF=`get_iface_name_from_mac ${MAC}` IFL=`get_iface_link_state ${IF}` @@ -374,6 +428,7 @@ # get kernel version function get_system_kernelversion { + [ "`is_disabled $FUNCNAME`" == "1" ] && return KERNEL=`${UNAME} -r` debug "KERNEL-VERSION: ${KERNEL}" echo ${KERNEL} @@ -381,6 +436,7 @@ # get system architecture function get_system_arch { + [ "`is_disabled $FUNCNAME`" == "1" ] && return SYSARCH=`${UNAME} -m` debug "SYSTEM-ARCHITECTURE: ${SYSARCH}" echo ${SYSARCH} @@ -389,6 +445,7 @@ # get distribution function get_system_os { + [ "`is_disabled $FUNCNAME`" == "1" ] && return OSREL=`${LSB_RELEASE} -d | ${AWK} -F":\t" '{print $NF}'` debug "SYSTEM-OS: ${OSREL}" echo ${OSREL} @@ -396,6 +453,7 @@ # get hostname function get_system_hostname { + [ "`is_disabled $FUNCNAME`" == "1" ] && return HN=`${HOSTNAME} -f` debug "SYSTEM-HOSTNAME: ${HN}" echo ${HN} @@ -403,6 +461,7 @@ # get all system ipv4 addresses function get_system_ipv4 { + [ "`is_disabled $FUNCNAME`" == "1" ] && return IPV4ADDR=`${IP} -4 addr show scope global | ${GREP} inet | ${AWK} '{print $2}' | ${AWK} -F/ '{print $1}' | ${SORT} -u` debug "SYSTEM-IPV4-ADDRESSES: ${IPV4ADDR}" echo ${IPV4ADDR} @@ -410,6 +469,7 @@ # get all system ipv6 addresses function get_system_ipv6 { + [ "`is_disabled $FUNCNAME`" == "1" ] && return IPV6ADDR=`${IP} -6 addr show scope global | ${GREP} inet | ${AWK} '{print $2}' | ${AWK} -F/ '{print $1}' | ${SORT} -u` debug "SYSTEM-IPV6-ADDRESSES: ${IPV6ADDR}" echo ${IPV6ADDR} @@ -417,6 +477,7 @@ # get primary network interface from default route function get_system_default_interface { + [ "`is_disabled $FUNCNAME`" == "1" ] && return INT=`${IP} -4 route show default | ${AWK} '{print $NF}'` debug "SYSTEM-DEFAULT-IFACE: ${INT}" echo ${INT} @@ -424,6 +485,7 @@ # get primary ip from interface function get_system_default_interface_ip_from_int { + [ "`is_disabled $FUNCNAME`" == "1" ] && return DEVICE=${1} DEFAULTIP=`${IP} -4 addr show dev ${DEVICE} | ${GREP} inet | ${HEAD} -n1 | ${AWK} '{print $2}' | ${AWK} -F/ '{print $1}'` debug "SYSTEM-DEFAULT-IP: ${DEFAULTIP}" @@ -432,11 +494,13 @@ # get system default ip function get_system_default_ip { + [ "`is_disabled $FUNCNAME`" == "1" ] && return get_system_default_interface_ip_from_int `get_system_default_interface` } # get ipmi mac function get_system_mgmt_mac { + [ "`is_disabled $FUNCNAME`" == "1" ] && return case `get_system_type` in xen-dom0|baremetal) ${MODPROBE} ipmi_devintf >/dev/null 2>&1 @@ -464,6 +528,7 @@ # get ipmi ip function get_system_mgmt_ip { + [ "`is_disabled $FUNCNAME`" == "1" ] && return case `get_system_type` in xen-dom0|baremetal) ${MODPROBE} ipmi_devintf >/dev/null 2>&1 @@ -490,6 +555,7 @@ # get rpm package list function get_system_software { + [ "`is_disabled $FUNCNAME`" == "1" ] && return PACKAGES=`${RPM} -qa --queryformat '%{name}-%{version}-%{release}.%{arch} '` debug "SYSTEM-SOFTWARE: ${PACKAGES}" echo ${PACKAGES} @@ -497,6 +563,7 @@ # get current date function get_system_date { + [ "`is_disabled $FUNCNAME`" == "1" ] && return LANG=C DATUM=`${DATE}` debug "SYSTEM-DATE: ${DATUM}" | ||
[+] | Changed | inventory-system.conf ^ |
@@ -18,3 +18,9 @@ # DEBUG="no" # +## Description: Disable listed functions (space separated) +## Type: string +## Default: "" +# +DISABLE_FUNCTIONS="" +# |