#!/bin/sh # # disk s/n: S9BWOXA5K31HTRWZVE4H # LV_NAME1=01cf1174-2f42-45d2-b206-c146c4f42f49 LUKS_MNT1=luks-${LV_NAME1} UNLOCK_MNT1=/media/yazoo/luks-${LV_NAME1} # # Check if mount point exists, create if not if [ ! -d "$UNLOCK_MNT1" ]; then echo "Mount point $UNLOCK_MNT1 does not exist. Creating it..." sudo mkdir -p "$UNLOCK_MNT1" if [ $? -eq 0 ]; then echo "Mount point $UNLOCK_MNT1 created successfully." else echo "Failed to create mount point $UNLOCK_MNT1. Exiting." exit 1 fi fi # Unmount and close LUKS device if already mounted/opened sudo umount "$UNLOCK_MNT1" 2>/dev/null sudo cryptsetup luksClose "$LUKS_MNT1" 2>/dev/null # Open LUKS device echo "Unlocking QNAP disk TOSHIBA 4x2T ..." sudo cryptsetup luksOpen UUID=$LV_NAME1 "$LUKS_MNT1" if [ $? -eq 0 ]; then echo "LUKS device unlocked successfully." else echo "Failed to unlock LUKS device. Exiting." exit 1 fi # Mount the unlocked device echo "Mounting ..." sudo mount /dev/mapper/"$LUKS_MNT1" "$UNLOCK_MNT1" if [ $? -eq 0 ]; then echo "Device mounted successfully at $UNLOCK_MNT1." else echo "Failed to mount device. Closing LUKS device." sudo cryptsetup luksClose "$LUKS_MNT1" exit 1 fi # Optional: Remount with specific options (if needed) # sudo mount -o rw,remount /dev/mapper/"$LUKS_MNT1" "$UNLOCK_MNT1"