Skip to content
Snippets Groups Projects
Commit 749da45c authored by Lars Beckers's avatar Lars Beckers
Browse files

lipnsa: rm chroot script; use casper log functions

parent 0aa52048
Branches
No related tags found
No related merge requests found
#!/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
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
LIPSTICK="/cdrom" LIPSTICK="/cdrom"
LIPSTATS="${LIPSTICK}/lipstats" LIPSTATS="${LIPSTICK}/lipstats"
TARGET="/root" TARGET="/root"
LOGFUNCTIONSSOURCE="/scripts/casper-functions"
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
echo "collects system information, i.e. hardware and what the kernel thinks about it" echo "collects system information, i.e. hardware and what the kernel thinks about it"
...@@ -17,7 +18,6 @@ if [ $# -gt 0 ]; then ...@@ -17,7 +18,6 @@ if [ $# -gt 0 ]; then
echo "${LIPSTICK} is remounted rw in the process, remounted ro at the end" 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 "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 "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 ""
echo "currently lipnsa.sh collects the following:" echo "currently lipnsa.sh collects the following:"
echo " running architecture" echo " running architecture"
...@@ -37,73 +37,75 @@ if [ $# -gt 0 ]; then ...@@ -37,73 +37,75 @@ if [ $# -gt 0 ]; then
exit exit
fi fi
source ${LOGFUNCTIONSSOURCE}
if [ -f /proc/cmdline ]; then if [ -f /proc/cmdline ]; then
grep fnord /proc/cmdline grep fnord /proc/cmdline
if [ $? == 0 ]; then if [ $? == 0 ]; then
echo "lipnsa.sh has been deactivated. :(" log_warning_msg "lipnsa.sh has been deactivated. :("
exit exit
fi fi
else else
echo "It seems that /proc is not mounted. lipnsa.sh aborting." log_failure_msg "It seems that /proc is not mounted. lipnsa.sh aborting."
exit exit
fi fi
if [ ! -d /sys/class ]; then if [ ! -d /sys/class ]; then
echo "It seems that /sys is not mounted. lipnsa.sh aborting." log_failure_msg "It seems that /sys is not mounted. lipnsa.sh aborting."
exit exit
fi fi
echo "This is lipnsa.sh -- collecting your data for a better world" log_success_msg "This is lipnsa.sh -- collecting your data for a better world"
UUID=`cat /sys/class/dmi/id/product_uuid` UUID=`cat /sys/class/dmi/id/product_uuid`
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> dmi system-uuid is unavailable, using random uuid" log_warning_msg "> dmi system-uuid is unavailable, using random uuid"
UUID=`cat /proc/sys/kernel/random/uuid` UUID=`cat /proc/sys/kernel/random/uuid`
fi fi
BOOTID=`cat /proc/sys/kernel/random/boot_id` BOOTID=`cat /proc/sys/kernel/random/boot_id`
echo "> using ${UUID}/${BOOTID}" log_success_msg "> using ${UUID}/${BOOTID}"
DIR="${LIPSTATS}/${UUID}/${BOOTID}" DIR="${LIPSTATS}/${UUID}/${BOOTID}"
mount -o remount,rw ${LIPSTICK} mount -o remount,rw ${LIPSTICK}
mkdir -p "${DIR}" mkdir -p "${DIR}"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not create directory, aborting" log_failure_msg "> could not create directory, aborting"
exit exit
fi fi
echo "> remounted lipstick rw, created directory" log_success_msg "> remounted lipstick rw, created directory"
date +%s > "${DIR}/timestamp" 2>&1 date +%s > "${DIR}/timestamp" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save timestamp" log_failure_msg "> could not save timestamp"
else else
echo "> saved timestamp" log_success_msg "> saved timestamp"
fi fi
uname -m > "${DIR}/architecture" 2>&1 uname -m > "${DIR}/architecture" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save architecture" log_failure_msg "> could not save architecture"
else else
echo "> saved architecture" log_success_msg "> saved architecture"
fi fi
ip link > "${DIR}/ip-link" 2>&1 ip link > "${DIR}/ip-link" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save ip devices" log_failure_msg "> could not save ip devices"
else else
echo "> saved ip devices" log_success_msg "> saved ip devices"
fi fi
kmod list > "${DIR}/kmod-list" 2>&1 kmod list > "${DIR}/kmod-list" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save the formatted module list" log_failure_msg "> could not save the formatted module list"
else else
echo "> saved the formatted module list" log_success_msg "> saved the formatted module list"
fi fi
blkid > "${DIR}/blkid" 2>&1 blkid > "${DIR}/blkid" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save block device information" log_failure_msg "> could not save block device information"
else else
echo "> saved block device information" log_success_msg "> saved block device information"
fi fi
if [ -d /sys/firmware/efi ]; then if [ -d /sys/firmware/efi ]; then
...@@ -115,108 +117,121 @@ if [ -d /sys/firmware/efi ]; then ...@@ -115,108 +117,121 @@ if [ -d /sys/firmware/efi ]; then
fi fi
else else
echo "no" > "${DIR}/efi" 2>&1 echo "no" > "${DIR}/efi" 2>&1
echo "not found" > "${DIR}/secureboot" 2>&1
fi fi
echo "> saved detection of efi and secureboot" log_success_msg "> saved detection of efi and secureboot"
cat /proc/cmdline > "${DIR}/cmdline" 2>&1 cat /proc/cmdline > "${DIR}/cmdline" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save the kernel command line" log_failure_msg "> could not save the kernel command line"
else else
echo "> saved the kernel command line" log_success_msg "> saved the kernel command line"
fi fi
cat /proc/modules > "${DIR}/modules" 2>&1 cat /proc/modules > "${DIR}/modules" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save the module list" log_failure_msg "> could not save the module list"
else else
echo "> saved the module list" log_success_msg "> saved the module list"
fi fi
cat /proc/cpuinfo > "${DIR}/cpuinfo" 2>&1 cat /proc/cpuinfo > "${DIR}/cpuinfo" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save cpu information" log_failure_msg "> could not save cpu information"
else else
echo "> saved cpu information" log_success_msg "> saved cpu information"
fi fi
cat /proc/meminfo > "${DIR}/meminfo" 2>&1 cat /proc/meminfo > "${DIR}/meminfo" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save memory information" log_failure_msg "> could not save memory information"
else else
echo "> saved memory information" log_success_msg "> saved memory information"
fi fi
cat /proc/partitions > "${DIR}/partitions" 2>&1 cat /proc/partitions > "${DIR}/partitions" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save the partition list" log_failure_msg "> could not save the partition list"
else else
echo "> saved the partition list" log_success_msg "> saved the partition list"
fi fi
cp lipnsa-chroot.sh ${TARGET}/lipnsa-chroot.sh # chrooted commands
if [ $? != 0 ]; then
echo "> could not copy into target, skipping chrooted commands"
else # chrooted commands
# actually lsblk, lscpu and dmidecode work without chroot # actually lsblk, lscpu and dmidecode work without chroot
# but i think it is more sane to not depend on that # 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} /lipnsa-chroot.sh "lspci -mm" > "${DIR}/lspci" 2>&1 chroot ${TARGET} lspci -mm > "${DIR}/lspci" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save listing of pci devices" log_failure_msg "> could not save listing of pci devices"
else else
echo "> saved listing of pci devices" log_success_msg "> saved listing of pci devices"
fi fi
chroot ${TARGET} /lipnsa-chroot.sh lsblk > "${DIR}/lsblk" 2>&1 chroot ${TARGET} lsblk > "${DIR}/lsblk" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save listing of block devices" log_failure_msg "> could not save listing of block devices"
else else
echo "> saved listing of block devices" log_success_msg "> saved listing of block devices"
fi fi
chroot ${TARGET} /lipnsa-chroot.sh lscpu > "${DIR}/lscpu" 2>&1 chroot ${TARGET} lscpu > "${DIR}/lscpu" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save listing of cpus" log_failure_msg "> could not save listing of cpus"
else else
echo "> saved listing of cpus" log_success_msg "> saved listing of cpus"
fi fi
chroot ${TARGET} /lipnsa-chroot.sh dmidecode > "${DIR}/dmidecode" 2>&1 chroot ${TARGET} dmidecode > "${DIR}/dmidecode" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save decoded dmi table" log_failure_msg "> could not save decoded dmi table"
else else
echo "> saved decoded dmi table" log_success_msg "> saved decoded dmi table"
fi fi
chroot ${TARGET} /lipnsa-chroot.sh lsusb > "${DIR}/lsusb" 2>&1 chroot ${TARGET} lsusb > "${DIR}/lsusb" 2>&1
if [ $? != 0 ]; then if [ $? != 0 ]; then
grep "unable to initialize libusb: -99" "${DIR}/lsusb" grep "unable to initialize libusb: -99" "${DIR}/lsusb"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not save listing of usb devices" log_failure_msg "> could not save listing of usb devices"
else else
echo "no usb controller found" > "${DIR}/lsusb" 2>&1 echo "no usb controller found" > "${DIR}/lsusb" 2>&1
echo "> saved listing of usb devices" log_success_msg "> saved listing of usb devices"
fi fi
else else
echo "> saved listing of usb devices" log_success_msg "> saved listing of usb devices"
fi fi
rm ${TARGET}/lipnsa-chroot.sh umount ${TARGET}/sys
fi # chrooted commands 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 sync
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not flush filesystem buffers" log_failure_msg "> could not flush filesystem buffers"
else else
echo "> flushed filesystem buffers" log_success_msg "> flushed filesystem buffers"
fi fi
mount -o remount,ro ${LIPSTICK} mount -o remount,ro ${LIPSTICK}
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "> could not remount lipstick ro" log_failure_msg "> could not remount lipstick ro"
else else
echo "> remounted lipstick ro" log_success_msg "> remounted lipstick ro"
fi fi
echo "lipnsa.sh has finished, thank you for your cooperation" log_success_msg "lipnsa.sh has finished, thank you for your cooperation"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment