Unmount encrypted USB drive

This commit is contained in:
Bob Mottram 2015-06-08 19:42:11 +01:00
parent 4f1dc23a26
commit 860ae1a833
1 changed files with 28 additions and 1 deletions

View File

@ -1574,9 +1574,13 @@ function create_backup_script {
echo '' >> /usr/bin/$BACKUP_SCRIPT_NAME echo '' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "umount -f $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME echo "umount -f $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "mkdir $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME echo "mkdir $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'if [ -f /dev/mapper/encrypted_usb ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rm -rf /dev/mapper/encrypted_usb' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'cryptsetup luksClose encrypted_usb' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'cryptsetup luksOpen $USB_DRIVE encrypted_usb' >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'cryptsetup luksOpen $USB_DRIVE encrypted_usb' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'if [ "$?" = "0" ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'if [ "$?" = "0" ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' USB_DRIVE=/dev/mapper/encrypted_usb' >> /usr/bin/$BACKUP_SCRIPT_NAME echo ' USB_DRIVE=/dev/mapper/encrypted_usb' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo -n 'mount $USB_DRIVE ' >> /usr/bin/$BACKUP_SCRIPT_NAME echo -n 'mount $USB_DRIVE ' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "$USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME echo "$USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
@ -2151,6 +2155,15 @@ function create_backup_script {
echo ' exit 46994' >> /usr/bin/$BACKUP_SCRIPT_NAME echo ' exit 46994' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo "rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME echo "rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' echo "Unmount encrypted USB"' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' cryptsetup luksClose encrypted_usb' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'if [ -f /dev/mapper/encrypted_usb ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo ' rm -rf /dev/mapper/encrypted_usb' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'echo "Backup to USB drive is complete. You can now unplug it."' >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'echo "Backup to USB drive is complete. You can now unplug it."' >> /usr/bin/$BACKUP_SCRIPT_NAME
echo 'exit 0' >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'exit 0' >> /usr/bin/$BACKUP_SCRIPT_NAME
chmod 400 /usr/bin/$BACKUP_SCRIPT_NAME chmod 400 /usr/bin/$BACKUP_SCRIPT_NAME
@ -2185,6 +2198,10 @@ function create_restore_script {
echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo "if [ ! -d $USB_MOUNT ]; then" >> /usr/bin/$RESTORE_SCRIPT_NAME echo "if [ ! -d $USB_MOUNT ]; then" >> /usr/bin/$RESTORE_SCRIPT_NAME
echo " mkdir $USB_MOUNT" >> /usr/bin/$RESTORE_SCRIPT_NAME echo " mkdir $USB_MOUNT" >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ -f /dev/mapper/encrypted_usb ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rm -rf /dev/mapper/encrypted_usb' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' cryptsetup luksClose encrypted_usb' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' cryptsetup luksOpen $USB_DRIVE encrypted_usb' >> /usr/bin/$RESTORE_SCRIPT_NAME echo ' cryptsetup luksOpen $USB_DRIVE encrypted_usb' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' if [ "$?" = "0" ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME echo ' if [ "$?" = "0" ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' USB_DRIVE=/dev/mapper/encrypted_usb' >> /usr/bin/$RESTORE_SCRIPT_NAME echo ' USB_DRIVE=/dev/mapper/encrypted_usb' >> /usr/bin/$RESTORE_SCRIPT_NAME
@ -2839,6 +2856,16 @@ function create_restore_script {
echo 'echo "Setting permissions"' >> /usr/bin/$RESTORE_SCRIPT_NAME echo 'echo "Setting permissions"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo "chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME" >> /usr/bin/$RESTORE_SCRIPT_NAME echo "chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME" >> /usr/bin/$RESTORE_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo 'if [[ $USB_DRIVE == /dev/mapper/encrypted_usb ]]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' echo "Unmount encrypted USB"' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' cryptsetup luksClose encrypted_usb' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo 'if [ -f /dev/mapper/encrypted_usb ]; then' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo ' rm -rf /dev/mapper/encrypted_usb' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo 'fi' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo '' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo 'echo "Restore from USB drive is complete. You can now remove it."' >> /usr/bin/$RESTORE_SCRIPT_NAME echo 'echo "Restore from USB drive is complete. You can now remove it."' >> /usr/bin/$RESTORE_SCRIPT_NAME
echo 'exit 0' >> /usr/bin/$RESTORE_SCRIPT_NAME echo 'exit 0' >> /usr/bin/$RESTORE_SCRIPT_NAME
chmod 400 /usr/bin/$RESTORE_SCRIPT_NAME chmod 400 /usr/bin/$RESTORE_SCRIPT_NAME