Auto generated code done by ChatGPT
#!/bin/bash
# Mounted SSD
# Use your mounted device
DEVICE_NAME=/dev/sda1
# Device folder name
FOLDER_NAME=RPi3_Backup_image
# Get the current day of the month
current_day=$(date +%-d)
# Get the current month
current_month=$(date +%-m)
# Check if the current day is the first day of the month and if the current month is a multiple of 3
if [ $current_day -eq 1 ] && [ $((current_month % 3)) -eq 0 ]; then
# Image name
IMAGE_NAME=bullsey_$(date +%Y%m%d).img
# Check if the SSD is mounted
if mount | grep $DEVICE_NAME > /dev/null; then
echo "Device is already mounted"
else
echo "Error: Device is not mounted at $DEVICE_NAME"
exit 1
fi
# Check if the image file already exists in the destination folder
if [ -f $DEVICE_NAME/$FOLDER_NAME/$IMAGE_NAME ]; then
echo "Image file already exists in destination folder. Do you want to overwrite it? (y/n)"
read -r choice
if [ "$choice" != "y" ]; then
echo "Exiting script"
exit 1
fi
fi
# Create full image of Raspberry Pi3 bullseye
echo "Creating image file, please wait..."
start=$(date +%s)
# Exclude the SSD partition from the image file
sudo dd if=/dev/mmcblk0 bs=1M | pv -s $(blockdev --getsize64 /dev/mmcblk0) | dd of=$DEVICE_NAME/$FOLDER_NAME/$IMAGE_NAME bs=1M conv=notrunc,noerror iflag=fullblock oflag=direct
end=$(date +%s)
echo "Image creation completed in $((end-start)) seconds"
else
echo "Current day is not the first day of the month or current month is not a multiple of 3. Skipping image creation."
fi