Improve card ID handling 🐒

This commit is contained in:
Dmitri Popov
2018-01-08 18:46:38 +01:00
parent 091ae136ac
commit e409e19bc8

View File

@@ -52,18 +52,17 @@ if [ ! -z $CARD_READER ]; then
mount /dev/$CARD_DEV $CARD_MOUNT_POINT
# # Set the ACT LED to blink at 500ms to indicate that the card has been mounted
sudo sh -c "echo 500 > /sys/class/leds/led0/delay_on"
# Create the CARD_ID file containing a random 8-digit identifier if doesn't exist
if [ ! -f $CARD_MOUNT_POINT/CARD_ID ]; then
< /dev/urandom tr -cd 0-9 | head -c 8 > $CARD_MOUNT_POINT/CARD_ID
# Create a .id random identifier file if doesn't exist
if [ ! -f $CARD_MOUNT_POINT/*.id ]; then
ID=$RANDOM
touch $ID."id"
fi
# Set the backup path
BACKUP_PATH=$STORAGE_MOUNT_POINT/"$ID"
# Log the output of the lsblk command for troubleshooting
sudo lsblk > lsblk.log
# Read the 8-digit identifier number from the CARD_ID file on the card
# and use it as a directory name in the backup path
read -r ID < $CARD_MOUNT_POINT/CARD_ID
BACKUP_PATH=$STORAGE_MOUNT_POINT/"$ID"
# Perform backup using rsync
rsync -avh $CARD_MOUNT_POINT/ $BACKUP_PATH