diff --git a/scripts/lipnsa-chroot.sh b/scripts/lipnsa-chroot.sh new file mode 100755 index 0000000000000000000000000000000000000000..81f39e13bcec977da6f3e0466fb33ac6d50affa0 --- /dev/null +++ b/scripts/lipnsa-chroot.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# lipnsa.sh -- collecting your data for a better world +# Lars Beckers, larsb@fsmpi.rwth-aachen.de, September 2014 + +if [ $# != 1 ]; then + echo "executes a command with proc and sysfs mounted" + echo "called by lipnsa.sh in a chroot environment" + echo "usage: chroot /root /lipnsa-chroot.sh cmd" + exit +fi + +PROCMNT=0 +if [ -f /proc/cmdline ]; then + PROCMNT=1 +fi +SYSFSMNT=0 +if [ -d /sys/class ]; then + SYSFSMNT=1 +fi + +if [ ${PROCMNT} == 0 ]; then + mount -t proc proc /proc +fi +if [ ${SYSFSMNT} == 0 ]; then + mount -t sysfs sysfs /sys +fi + +$1 + +if [ ${PROCMNT} == 0 ]; then + umount /proc +fi +if [ ${SYSFSMNT} == 0 ]; then + umount /sys +fi + diff --git a/scripts/lipnsa.sh b/scripts/lipnsa.sh new file mode 100755 index 0000000000000000000000000000000000000000..57a5cca2ddbf5bbbabae8e7e7e73b1c79a98ca9f --- /dev/null +++ b/scripts/lipnsa.sh @@ -0,0 +1,222 @@ +#!/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" + +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 "for that purpose lipnsa-chroot.sh is copied from the current directory to the target (${TARGET}) and deleted afterwards, but we do not remount the target" + 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 + +if [ -f /proc/cmdline ]; then + grep fnord /proc/cmdline + if [ $? == 0 ]; then + echo "lipnsa.sh has been deactivated. :(" + exit + fi +else + echo "It seems that /proc is not mounted. lipnsa.sh aborting." + exit +fi +if [ ! -d /sys/class ]; then + echo "It seems that /sys is not mounted. lipnsa.sh aborting." + exit +fi + +echo "This is lipnsa.sh -- collecting your data for a better world" + +UUID=`cat /sys/class/dmi/id/product_uuid` +if [ $? != 0 ]; then + echo "> dmi system-uuid is unavailable, using random uuid" + UUID=`cat /proc/sys/kernel/random/uuid` +fi +BOOTID=`cat /proc/sys/kernel/random/boot_id` +echo "> using ${UUID}/${BOOTID}" + +DIR="${LIPSTATS}/${UUID}/${BOOTID}" +mount -o remount,rw ${LIPSTICK} +mkdir -p "${DIR}" +if [ $? != 0 ]; then + echo "> could not create directory, aborting" + exit +fi +echo "> remounted lipstick rw, created directory" + +date +%s > "${DIR}/timestamp" 2>&1 +if [ $? != 0 ]; then + echo "> could not save timestamp" +else + echo "> saved timestamp" +fi + +uname -m > "${DIR}/architecture" 2>&1 +if [ $? != 0 ]; then + echo "> could not save architecture" +else + echo "> saved architecture" +fi + +ip link > "${DIR}/ip-link" 2>&1 +if [ $? != 0 ]; then + echo "> could not save ip devices" +else + echo "> saved ip devices" +fi + +kmod list > "${DIR}/kmod-list" 2>&1 +if [ $? != 0 ]; then + echo "> could not save the formatted module list" +else + echo "> saved the formatted module list" +fi + +blkid > "${DIR}/blkid" 2>&1 +if [ $? != 0 ]; then + echo "> could not save block device information" +else + echo "> 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 +fi +echo "> saved detection of efi and secureboot" + +cat /proc/cmdline > "${DIR}/cmdline" 2>&1 +if [ $? != 0 ]; then + echo "> could not save the kernel command line" +else + echo "> saved the kernel command line" +fi + +cat /proc/modules > "${DIR}/modules" 2>&1 +if [ $? != 0 ]; then + echo "> could not save the module list" +else + echo "> saved the module list" +fi + +cat /proc/cpuinfo > "${DIR}/cpuinfo" 2>&1 +if [ $? != 0 ]; then + echo "> could not save cpu information" +else + echo "> saved cpu information" +fi + +cat /proc/meminfo > "${DIR}/meminfo" 2>&1 +if [ $? != 0 ]; then + echo "> could not save memory information" +else + echo "> saved memory information" +fi + +cat /proc/partitions > "${DIR}/partitions" 2>&1 +if [ $? != 0 ]; then + echo "> could not save the partition list" +else + echo "> saved the partition list" +fi + +cp lipnsa-chroot.sh ${TARGET}/lipnsa-chroot.sh +if [ $? != 0 ]; then + echo "> could not copy into target, skipping chrooted commands" +else # chrooted commands +# actually lsblk, lscpu and dmidecode work without chroot +# but i think it is more sane to not depend on that + +chroot ${TARGET} /lipnsa-chroot.sh "lspci -mm" > "${DIR}/lspci" 2>&1 +if [ $? != 0 ]; then + echo "> could not save listing of pci devices" +else + echo "> saved listing of pci devices" +fi + +chroot ${TARGET} /lipnsa-chroot.sh lsblk > "${DIR}/lsblk" 2>&1 +if [ $? != 0 ]; then + echo "> could not save listing of block devices" +else + echo "> saved listing of block devices" +fi + +chroot ${TARGET} /lipnsa-chroot.sh lscpu > "${DIR}/lscpu" 2>&1 +if [ $? != 0 ]; then + echo "> could not save listing of cpus" +else + echo "> saved listing of cpus" +fi + +chroot ${TARGET} /lipnsa-chroot.sh dmidecode > "${DIR}/dmidecode" 2>&1 +if [ $? != 0 ]; then + echo "> could not save decoded dmi table" +else + echo "> saved decoded dmi table" +fi + +chroot ${TARGET} /lipnsa-chroot.sh lsusb > "${DIR}/lsusb" 2>&1 +if [ $? != 0 ]; then + grep "unable to initialize libusb: -99" "${DIR}/lsusb" + if [ $? != 0 ]; then + echo "> could not save listing of usb devices" + else + echo "no usb controller found" > "${DIR}/lsusb" 2>&1 + echo "> saved listing of usb devices" + fi +else + echo "> saved listing of usb devices" +fi + +rm ${TARGET}/lipnsa-chroot.sh +fi # chrooted commands + +sync +if [ $? != 0 ]; then + echo "> could not flush filesystem buffers" +else + echo "> flushed filesystem buffers" +fi + +mount -o remount,ro ${LIPSTICK} +if [ $? != 0 ]; then + echo "> could not remount lipstick ro" +else + echo "> remounted lipstick ro" +fi + +echo "lipnsa.sh has finished, thank you for your cooperation" +