Skip to content
Snippets Groups Projects
Select Git revision
  • ef7526d0efc5499bc10f4fdcd966618b0fc6f3b4
  • master default protected
  • th/caddy-wip
  • th/caddy
  • th/lego
  • th/acmebot
  • pyzabbix
  • th/keycloak
8 results

.yamllint

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    lipnsa.sh 6.44 KiB
    #!/bin/sh
    # lipnsa.sh -- collecting your data for a better world
    # Lars Beckers, larsb@fsmpi.rwth-aachen.de, September 2014
    
    LIPSTICK="/cdrom"
    LIPSTATS="${LIPSTICK}/lipstats"
    TARGET="/root"
    LOGFUNCTIONSSOURCE="/scripts/casper-functions"
    
    if [ $# -gt 0 ]; then
    	echo "collects system information, i.e. hardware and what the kernel thinks about it"
    	echo "called as liphook before leaving initramfs"
    	echo "usage: lipnsa.sh"
    	echo ""
    	echo "requires proc and sysfs to be mounted"
    	echo "append 'fnord' to your kernel cmdline to disable this tool"
    	echo "data is saved to ${LIPSTATS}/dmi-product-uuid/kernel-boot-id/"
    	echo "${LIPSTICK} is remounted rw in the process, remounted ro at the end"
    	echo "if there is no dmi-product-uuid available a kernel-random-uuid will be used"
    	echo "some commands are processed outside the initramfs, in a chroot using the prepared system"
    	echo ""
    	echo "currently lipnsa.sh collects the following:"
    	echo "    running architecture"
    	echo "    ip link information"
    	echo "    block device listing"
    	echo "    pci device listing"
    	echo "    usb device listing"
    	echo "    cpu information"
    	echo "    listing of kernel modules"
    	echo "    kernel command line"
    	echo "    decoded dmi table"
    	echo "    detection of active efi"
    	echo "    detection of secureboot"
    	echo "    memory information"
    	echo "    partition information"
    	echo "    and the current timestamp"
    	exit
    fi
    
    source ${LOGFUNCTIONSSOURCE}
    
    if [ -f /proc/cmdline ]; then
    	grep fnord /proc/cmdline
    	if [ $? == 0 ]; then
    		log_warning_msg "lipnsa.sh has been deactivated. :("
    		exit
    	fi
    else
    	log_failure_msg "It seems that /proc is not mounted. lipnsa.sh aborting."
    	exit
    fi
    if [ ! -d /sys/class ]; then
    	log_failure_msg "It seems that /sys is not mounted. lipnsa.sh aborting."
    	exit
    fi
    
    log_success_msg "This is lipnsa.sh -- collecting your data for a better world"
    
    UUID=`cat /sys/class/dmi/id/product_uuid`
    if [ $? != 0 ]; then
    	log_warning_msg "> dmi system-uuid is unavailable, using random uuid"
    	UUID=`cat /proc/sys/kernel/random/uuid`
    fi
    BOOTID=`cat /proc/sys/kernel/random/boot_id`
    log_success_msg "> using ${UUID}/${BOOTID}"
    
    DIR="${LIPSTATS}/${UUID}/${BOOTID}"
    mount -o remount,rw ${LIPSTICK}
    mkdir -p "${DIR}"
    if [ $? != 0 ]; then
    	log_failure_msg "> could not create directory, aborting"
    	exit
    fi
    log_success_msg "> remounted lipstick rw, created directory"
    
    date +%s > "${DIR}/timestamp" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save timestamp"
    else
    	log_success_msg "> saved timestamp"
    fi
    
    uname -m > "${DIR}/architecture" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save architecture"
    else
    	log_success_msg "> saved architecture"
    fi
    
    ip link > "${DIR}/ip-link" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save ip devices"
    else
    	log_success_msg "> saved ip devices"
    fi
    
    kmod list > "${DIR}/kmod-list" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save the formatted module list"
    else
    	log_success_msg "> saved the formatted module list"
    fi
    
    blkid > "${DIR}/blkid" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save block device information"
    else
    	log_success_msg "> saved block device information"
    fi
    
    if [ -d /sys/firmware/efi ]; then
    	echo "yes" > "${DIR}/efi" 2>&1
    	
    	ls /sys/firmware/efi/efivars | grep -i SecureBoot > "${DIR}/secureboot"
    	if [ $? != 0 ]; then
    		echo "not found" > "${DIR}/secureboot" 2>&1
    	fi
    else
    	echo "no" > "${DIR}/efi" 2>&1
    	echo "not found" > "${DIR}/secureboot" 2>&1
    fi
    log_success_msg "> saved detection of efi and secureboot"
    
    cat /proc/cmdline > "${DIR}/cmdline" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save the kernel command line"
    else
    	log_success_msg "> saved the kernel command line"
    fi
    
    cat /proc/modules > "${DIR}/modules" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save the module list"
    else
    	log_success_msg "> saved the module list"
    fi
    
    cat /proc/cpuinfo > "${DIR}/cpuinfo" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save cpu information"
    else
    	log_success_msg "> saved cpu information"
    fi
    
    cat /proc/meminfo > "${DIR}/meminfo" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save memory information"
    else
    	log_success_msg "> saved memory information"
    fi
    
    cat /proc/partitions > "${DIR}/partitions" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save the partition list"
    else
    	log_success_msg "> saved the partition list"
    fi
    
    # chrooted commands
    # actually lsblk, lscpu and dmidecode work without chroot
    # but i think it is more sane to not depend on that
    mount -t proc proc ${TARGET}/proc
    if [ $? != 0 ]; then
    	log_warning_msg "> could not mount proc on the target, this might produce false results"
    fi
    mount -t sysfs sysfs ${TARGET}/sys
    if [ $? != 0 ]; then
    	log_warning_msg "> could not mount sysfs on the target, this might produce false results"
    fi
    
    chroot ${TARGET} lspci -mm > "${DIR}/lspci" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save listing of pci devices"
    else
    	log_success_msg "> saved listing of pci devices"
    fi
    
    chroot ${TARGET} lsblk > "${DIR}/lsblk" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save listing of block devices"
    else
    	log_success_msg "> saved listing of block devices"
    fi
    
    chroot ${TARGET} lscpu > "${DIR}/lscpu" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save listing of cpus"
    else
    	log_success_msg "> saved listing of cpus"
    fi
    
    chroot ${TARGET} dmidecode > "${DIR}/dmidecode" 2>&1
    if [ $? != 0 ]; then
    	log_failure_msg "> could not save decoded dmi table"
    else
    	log_success_msg "> saved decoded dmi table"
    fi
    
    chroot ${TARGET} lsusb > "${DIR}/lsusb" 2>&1
    if [ $? != 0 ]; then
    	grep "unable to initialize libusb: -99" "${DIR}/lsusb"
    	if [ $? != 0 ]; then
    		log_failure_msg "> could not save listing of usb devices"
    	else
    		echo "no usb controller found" > "${DIR}/lsusb" 2>&1
    		log_success_msg "> saved listing of usb devices"
    	fi
    else
    	log_success_msg "> saved listing of usb devices"
    fi
    
    umount ${TARGET}/sys
    if [ $? != 0 ]; then
    	log_warning_msg "> could not unmount sysfs on the target, this might cause some trouble"
    fi
    umount ${TARGET}/proc
    if [ $? != 0 ]; then
    	log_warning_msg "> could not unmount proc on the target, this might cause some trouble"
    fi
    # chrooted commands
    
    sync
    if [ $? != 0 ]; then
    	log_failure_msg "> could not flush filesystem buffers"
    else
    	log_success_msg "> flushed filesystem buffers"
    fi
    
    mount -o remount,ro ${LIPSTICK}
    if [ $? != 0 ]; then
    	log_failure_msg "> could not remount lipstick ro"
    else
    	log_success_msg "> remounted lipstick ro"
    fi
    
    log_success_msg "lipnsa.sh has finished, thank you for your cooperation"