Merge pull request #228 from PartialVolume/Exclude_shredos_boot_disc

Exclude FAT boot disc from erasure.
This commit is contained in:
PartialVolume
2024-03-02 22:23:21 +00:00
committed by GitHub
4 changed files with 178 additions and 76 deletions

View File

@@ -1 +1 @@
2023.08.2_25.2_x86-64_0.35
2023.08.2_25.3_x86-64_0.35

View File

@@ -42,63 +42,63 @@ archive_drive_directory="/archive_drive"
sent_directory="/sent"
# From all the drives on the system, try to locate the ShredOS boot disc
drive=$(find_shredos_boot_disc.sh)
drive_partition=$(find_shredos_boot_disc.sh)
if [ "$drive" == "" ]; then
printf "archive_log.sh: No ShredOS/Ventoy exFAT/FAT32 boot drive found, unable to archive nwipe log files to USB\n"
if [ "$drive_partition" == "" ]; then
printf "[`date`] archive_log.sh: No exFAT/FAT32 drive found, unable to archive nwipe log files to USB\n" 2>&1 | tee -a transfer.log
exit 1
else
printf "Archiving nwipe logs to $drive\n"
printf "[`date`] Archiving nwipe logs to $drive_partition\n" 2>&1 | tee -a transfer.log
fi
# Create the temporary directory we will mount the FAT32 partition onto.
if [ ! -d "$archive_drive_directory" ]; then
mkdir "$archive_drive_directory"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to create the temporary mount directory $archive_drive_directory\n"
printf "[`date`] archive_log.sh: FAILED to create the temporary mount directory $archive_drive_directory\n" 2>&1 | tee -a transfer.log
exit_code=2
fi
fi
# mount the FAT32 partition onto the temporary directory
mount $drive $archive_drive_directory
mount $drive_partition $archive_drive_directory
status=$?
if [ $status != 0 ] && [ $status != 32 ]; then
# exit only if error, except code 32 which means already mounted
printf "archive_log.sh: Unable to mount the FAT32 partition $drive to $archive_drive_directory\n"
printf "[`date`] archive_log.sh: FAILED to mount the FAT32 partition $drive_partition to $archive_drive_directory\n" 2>&1 | tee -a transfer.log
exit_code=3
else
printf "archive_log.sh: exFAT/FAT32 partition $drive is now mounted to $archive_drive_directory\n"
printf "[`date`] archive_log.sh: exFAT/FAT32 partition $drive_partition is now mounted to $archive_drive_directory\n" 2>&1 | tee -a transfer.log
# Copy the dmesg.txt and PDF files over to the exFAT/FAT32 partition
dmesg > dmesg.txt
cp /dmesg.txt "$archive_drive_directory/"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to copy the dmesg.txt file to the root of $drive:/\n"
printf "[`date`] archive_log.sh: FAILED to copy the dmesg.txt file to the root of $drive_partition:/\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Sucessfully copied dmesg.txt to $drive:/\n"
printf "[`date`] archive_log.sh: Copied dmesg.txt to $drive_partition:/\n" 2>&1 | tee -a transfer.log
fi
# Copy the PDF certificates over to the exFAT/FAT32 partition
cp /nwipe_report_*pdf "$archive_drive_directory/"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to copy the nwipe_report...pdf file to the root of $drive:/\n"
printf "[`date`] archive_log.sh: Unable to copy the nwipe_report...pdf file to the root of $drive_partition:/\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Sucessfully copied nwipe_report...pdf to $drive:/\n"
printf "[`date`] archive_log.sh: Copied nwipe_report...pdf to $drive_partition:/\n" 2>&1 | tee -a transfer.log
fi
# Copy the nwipe log files over to the exFAT/FAT32 partition
cp /nwipe_log* "$archive_drive_directory/"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to copy the nwipe log files to the root of $drive:/\n"
printf "[`date`] archive_log.sh: Unable to copy the nwipe log files to the root of $drive_partition:/\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Successfully copied the nwipe logs to $drive:/\n"
printf "[`date`] archive_log.sh: Copied the nwipe logs to $drive_partition:/\n" 2>&1 | tee -a transfer.log
# Create the temporary sent directory we will move log files that have already been copied
if [ ! -d "$sent_directory" ]; then
mkdir "$sent_directory"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to create the temporary directory $sent_directory on the RAM disc\n"
printf "[`date`] archive_log.sh: FAILED to create the temporary directory $sent_directory on the RAM disc\n" 2>&1 | tee -a transfer.log
exit_code=5
fi
fi
@@ -107,17 +107,17 @@ else
# Move the nwipe logs into the RAM disc sent directory
mv /nwipe_log* "$sent_directory/"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to move the nwipe logs into the $sent_directory on the RAM disc\n"
printf "[`date`] archive_log.sh: Unable to move the nwipe logs into the $sent_directory on the RAM disc\n" 2>&1 | tee -a transfer.log
exit_code=6
else
printf "archive_log.sh: Moved the nwipe logs into the $sent_directory\n"
printf "[`date`] archive_log.sh: Moved the nwipe logs into the $sent_directory\n" 2>&1 | tee -a transfer.log
fi
# Move the nwipe PDF certificates into the RAM disc sent directory
mv /nwipe_report*pdf "$sent_directory/"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to move the PDF certificates into the $sent_directory on the RAM disc\n"
printf "[`date`] archive_log.sh: Unable to move the PDF certificates into the $sent_directory on the RAM disc\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Moved the PDF certificates into the $sent_directory\n"
printf "[`date`] archive_log.sh: Moved the PDF certificates into the $sent_directory\n" 2>&1 | tee -a transfer.log
fi
fi
fi
@@ -131,9 +131,9 @@ else
then
mkdir "/etc/nwipe"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to create directory /etc/nwipe on ShredOS ram drive\n"
printf "[`date`] archive_log.sh: FAILED to create directory /etc/nwipe on ShredOS ram drive\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Successfully created directory /etc/nwipe on ShredOS ram drive\n"
printf "[`date`] archive_log.sh: Created directory /etc/nwipe on ShredOS ram drive\n" 2>&1 | tee -a transfer.log
fi
fi
if [[ "$mode" == "read" ]]; then
@@ -144,9 +144,9 @@ else
# Copy nwipe.conf from USB flash to ShredOS ram disc
cp "$archive_drive_directory/etc/nwipe/nwipe.conf" /etc/nwipe/nwipe.conf
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to copy $drive:/etc/nwipe/nwipe.conf to ShredOS's ram disc\n"
printf "[`date`] archive_log.sh: FAILED to copy $drive_partition:/etc/nwipe/nwipe.conf to ShredOS's ram disc\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Sucessfully copied $drive:/etc/nwipe/nwipe.conf to ShredOS's ram disc\n"
printf "[`date`] archive_log.sh: Copied $drive_partition:/etc/nwipe/nwipe.conf to ShredOS's ram disc\n" 2>&1 | tee -a transfer.log
fi
fi
@@ -157,9 +157,9 @@ else
# Copy nwipe.conf from USB flash to ShredOS ram disc
cp "$archive_drive_directory/etc/nwipe/nwipe_customers.csv" /etc/nwipe/nwipe_customers.csv
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to copy $drive:/etc/nwipe/nwipe_customers.csv to /etc/nwipe/nwipe_customers.csv\n"
printf "[`date`] archive_log.sh: FAILED to copy $drive_partition:/etc/nwipe/nwipe_customers.csv to /etc/nwipe/nwipe_customers.csv\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Sucessfully copied $drive:/etc/nwipe/nwipe_customers.csv to /etc/nwipe/nwipe_customers.csv\n"
printf "[`date`] archive_log.sh: Copied $drive_partition:/etc/nwipe/nwipe_customers.csv to /etc/nwipe/nwipe_customers.csv\n" 2>&1 | tee -a transfer.log
fi
fi
fi
@@ -173,9 +173,9 @@ else
then
mkdir "$archive_drive_directory/etc"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to create directory /etc on $drive:/\n"
printf "[`date`] archive_log.sh: FAILED to create directory /etc on $drive_partition:/\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Successfully created directory /etc on $drive:/\n"
printf "[`date`] archive_log.sh: Created directory /etc on $drive_partition:/\n" 2>&1 | tee -a transfer.log
fi
fi
@@ -184,9 +184,9 @@ else
then
mkdir "$archive_drive_directory/etc/nwipe"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to create directory /etc/nwipe on $drive:/\n"
printf "[`date`] archive_log.sh: FAILED to create directory /etc/nwipe on $drive_partition:/\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Successfully created directory /etc/nwipe on $drive:/\n"
printf "[`date`] archive_log.sh: Created directory /etc/nwipe on $drive_partition:/\n" 2>&1 | tee -a transfer.log
fi
fi
if [[ "$mode" == "write" ]]; then
@@ -196,9 +196,9 @@ else
then
cp /etc/nwipe/nwipe.conf "$archive_drive_directory/etc/nwipe/nwipe.conf"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to copy /etc/nwipe/nwipe.conf to $drive:/etc/nwipe/nwipe.conf\n"
printf "[`date`] archive_log.sh: FAILED to copy /etc/nwipe/nwipe.conf to $drive_partition:/etc/nwipe/nwipe.conf\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Successfully copied /etc/nwipe/nwipe.conf to $drive:/etc/nwipe/nwipe.conf\n"
printf "[`date`] archive_log.sh: Copied /etc/nwipe/nwipe.conf to $drive_partition:/etc/nwipe/nwipe.conf\n" 2>&1 | tee -a transfer.log
fi
fi
@@ -208,9 +208,9 @@ else
then
cp /etc/nwipe/nwipe_customers.csv "$archive_drive_directory/etc/nwipe/nwipe_customers.csv"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to copy /etc/nwipe/nwipe_customers.csv file to the root of $drive:/etc/nwipe/nwipe_customers.csv\n"
printf "[`date`] archive_log.sh: FAILED to copy /etc/nwipe/nwipe_customers.csv file to the root of $drive_partition:/etc/nwipe/nwipe_customers.csv\n" 2>&1 | tee -a transfer.log
else
printf "archive_log.sh: Successfully copied /etc/nwipe/nwipe_customers.csv to $drive:/etc/nwipe/nwipe_customers.csv\n"
printf "[`date`] archive_log.sh: Copied /etc/nwipe/nwipe_customers.csv to $drive_partition:/etc/nwipe/nwipe_customers.csv\n" 2>&1 | tee -a transfer.log
fi
fi
fi
@@ -220,13 +220,13 @@ fi
sleep 1
umount "$archive_drive_directory"
if [ $? != 0 ]; then
printf "archive_log.sh: Unable to unmount the FAT32 partition\n"
printf "[`date`] archive_log.sh: FAILED to unmount the FAT partition\n" 2>&1 | tee -a transfer.log
exit_code=7
else
printf "archive_log.sh: Successfully unmounted $archive_drive_directory ($drive)\n"
printf "[`date`] archive_log.sh: Unmounted $archive_drive_directory ($drive_partition)\n" 2>&1 | tee -a transfer.log
fi
if [ $exit_code != 0 ]; then
printf "archive_log.sh: Failed to copy nwipe log files to $drive, exit code $exit_code\n"
printf "[`date`] archive_log.sh: FAILED to copy nwipe log files to $drive_partition, exit code $exit_code\n" 2>&1 | tee -a transfer.log
fi
exit $exit_code

View File

@@ -1,51 +1,134 @@
#!/bin/bash
#
# This program looks for any exfat or fat32 filesystems, it then
# This program looks for any exfat, fat32 or fat16 filesystem, it then
# examines the filesystem, looking for a kernel file or .img or .iso
# file that has the same version number as the booted ShredOS. Once
# the boot USB has been found this script outputs the drive name in
# the following form, example being /dev/sdc etc
# the following form, example being /dev/sdc etc.
#
# If there is no FAT drive found the script fails silently
# producing no output.
#
# If a ShredOS boot device is found it's name is output to the file boot_device.txt
# as well as output to stdout (with no return)
#
# If a ShredOS boot device is not present boot_device.txt is deleted.
#
version=$(cat /etc/shredos/version.txt)
drive_dir="boot_tmp"
drive=""
first_drive=""
boot_disk_found="0"
# Create a directory to mount the USB stick onto.
test -d "$drive_dir"
if [ $? != 0 ]
then
mkdir "$drive_dir"
mkdir "$drive_dir" 2>&1 | tee -a transfer.log
fi
#
# Search every disc on the system for a exfat or fat32 filesystem, mount each
# in turn and see if it could be our boot disc by examining the version on the
# disc against the booted version. Supports vanila ShredOS and Ventoy boot discs.
#
fdisk -l | grep -i "exfat\|fat16\|fat32" | awk '{print $1}' | while read drive ;
do
mount $drive $drive_dir
# Check for correct version of ShredOS on a vanilla ShredOS USB drive
test -f "$drive_dir/boot/version.txt"
if [ $? == 0 ]
then
# Remove any previously existing exclusion file
if [ -f "/exclude_disc.txt" ]
then
rm "/exclude_disc.txt"
fi
# Remove any previously existing file that showed a boot device
if [ -f "/boot_device.txt" ]
then
rm "/boot_device.txt"
fi
# ----
# Search every disc on the system for a exfat/fat32/fat16 filesystems, mount each
# in turn and see if it could be our boot disc by examining the version on the
# disc against the booted version. Supports vanila ShredOS, Ventoy and Rufus boot discs.
#
while read drive ;
do
if [[ "$first_drive" == "" ]]
then
first_drive=$drive
fi
if [[ "$drive" != "" ]]
then
mount $drive $drive_dir 2>&1 | tee -a transfer.log
# Check the partion for the file /etc/shredos/shredos_exclude_disc,
# If the file is found it indicates that the user considers that
# this disc is the ShredOS boot disc and should be excluded from nwipe's
# enumeration.
test -f "$drive_dir/etc/shredos/shredos_exclude_disc"
if [ $? == 0 ]
then
# output drive & partition, i.e /dev/sdb1 to stdout
printf "$drive"
# Strip out partition id from drive and write drive to file i.e /dev/sdb
printf "$drive" | tr -d '0-9' > /exclude_disc.txt
# Strip out partition id from drive and write drive to file i.e /dev/sdb
printf "$drive" | tr -d '0-9' > /boot_device.txt
boot_disk_found="1"
umount $drive_dir 2>&1 | tee -a transfer.log
break
fi
# Check for correct version of ShredOS on a vanilla ShredOS or Rufus etc USB drive
test -f "$drive_dir/boot/version.txt"
if [ $? == 0 ]
then
version_on_USB=$(cat "$drive_dir/boot/version.txt")
if [[ "$version" == "$version_on_USB" ]]
then
# output drive & partition, i.e /dev/sdb1 to stdout
printf "$drive"
umount $drive_dir
break;
# Strip out partition id from drive and write drive to file i.e /dev/sdb
printf "$drive" | tr -d '0-9' > /boot_device.txt
boot_disk_found="1"
umount $drive_dir 2>&1 | tee -a transfer.log
break
fi
fi
# Check each filename for the correct ShredOS version on a Ventoy USB drive
for filename in $drive_dir/*;
do
if [[ "$filename" == *"$version"* ]]
then
# output drive & partition, i.e /dev/sdb1 to stdout
printf "$drive"
# Strip out partition id from drive and write drive to file i.e /dev/sdb
printf "$drive" | tr -d '0-9' > /boot_device.txt
boot_disk_found="1"
umount $drive_dir 2>&1 | tee -a transfer.log
break
fi
done
if [[ "$boot_disk_found" == "1" ]]
then
break
fi
umount $drive_dir 2>&1 | tee -a transfer.log
fi
done <<< $(fdisk -l | grep -i "exfat\|fat16\|fat32" | awk '{print $1}')
# Check for correct version of a ShredOS .img or .iso on a Ventoy USB drive
test -f "$drive_dir/shredos-$version"*
if [ $? == 0 ]
then
printf "$drive"
umount $drive_dir
break;
fi
umount $drive_dir
done
# If no boot disc has been found that contains the version of ShredOS
# that is running, then output the first FAT formatted drive we came across.
#
if [[ "$boot_disk_found" == "0" ]]
then
printf "$first_drive"
if [ -f "/boot_device.txt" ]; then
rm /boot_device.txt
fi
fi

View File

@@ -29,7 +29,7 @@ while (( loop_count_total > 0 )); do
fi
previous_sha1=$sha1
while (( loop_count_check > 0 )); do
printf "Waiting for all USB devices to be initialised, timeout $loop_count_total\r"
printf "Waiting for all USB devices to be initialised, timeout $loop_count_total \r"
((loop_count_total--))
((loop_count_check--))
sleep 1
@@ -81,20 +81,39 @@ if [ ! -d "exported" ]; then
printf "[`date`] FAILED to create the /exported directory\n" 2>&1 | tee -a transfer.log
fi
fi
printf "nwipe_launcher: Searching for ShredOS/Ventoy exFAT/FAT32 boot drive that matches the booted ShredOS version.\n"
# From all the drives on the system, try to locate the ShredOS boot disc
drive=$(find_shredos_boot_disc.sh)
if [ "$drive" == "" ]; then
printf "nwipe_launcher: No ShredOS/Ventoy exFAT/FAT32 boot drive found with matching version.\n"
# Try to locate the ShredOS exFAT/FAT32/FAT16 formatted boot disc. If the program
# 'find_shredos_boot_disc.sh' can't find the boot disc then it returns the first
# exFAT/FAT32/FAT16 drive it comes across. If it doesn't find any exFAT/FAT32/FAT16
# drive then it reurns "".
#
printf "[`date`] nwipe_launcher: Searching for exFAT/FAT32/FAT16 USB drive.\n" 2>&1 | tee -a transfer.log
drive_partition=$(find_shredos_boot_disc.sh)
if [ "$drive_partition" == "" ]; then
printf "[`date`] nwipe_launcher: No exFAT/FAT32/FAT16 USB drive found: Unable to archive PDF/logs $drive.\n" 2>&1 | tee -a transfer.log
else
printf "Found a ShredOS/Ventoy exFAT/FAT32 boot drive with the correct version of ShredOS $drive\n"
printf "[`date`] nwipe_launcher: Found a exFAT/FAT32/FAT16 USB drive $drive\n" 2>&1 | tee -a transfer.log
if [ -f /boot_device.txt ]
then
drive=$(cat /boot_device.txt)
fi
fi
shredos_config_string=$(kernel_cmdline_extractor shredos_exclude_boot_disc)
# Has shredos_exclude_boot_disc="yes" been placed on the kernel command line?
exclude_boot_disc_cmd=""
exclude_boot_disc_status=$(kernel_cmdline_extractor shredos_exclude_boot_disc)
if [ $? == 0 ]
then
exclude_boot_disc=1
if [[ "${exclude_boot_disc_status,,}" == "yes" ]]
then
exclude_boot_disc_cmd="--exclude=$drive"
fi
else
if [ -f "/exclude_disc.txt" ]
then
exclude_boot_disc_cmd="--exclude=$drive"
fi
fi
# ----
@@ -363,9 +382,9 @@ while true
do
if [ $nwipe_options_flag == 0 ]
then
/usr/bin/nwipe --logfile=$logfile
/usr/bin/nwipe --logfile=$logfile $exclude_boot_disc_cmd
else
/usr/bin/nwipe --logfile=$logfile $nwipe_options_string
/usr/bin/nwipe --logfile=$logfile $nwipe_options_string $exclude_boot_disc_cmd
fi
# ----