Mounting and unmounting the usb drive

This commit is contained in:
Bob Mottram 2016-10-27 15:08:28 +01:00
parent f57f273519
commit 750d83ffa8
1 changed files with 18 additions and 34 deletions

View File

@ -83,63 +83,48 @@ function interactive_gpg_from_usb {
exit 739836 exit 739836
fi fi
GPG_USB_MOUNT='/mnt/usb' backup_mount_drive ${USB_DRIVE} ${MY_USERNAME}
umount -f $GPG_USB_MOUNT
if [ ! -d $GPG_USB_MOUNT ]; then
mkdir -p $GPG_USB_MOUNT
fi
if [ -f /dev/mapper/encrypted_usb ]; then if [ ! -d $USB_MOUNT ]; then
rm -rf /dev/mapper/encrypted_usb
fi
cryptsetup luksClose encrypted_usb
cryptsetup luksOpen $USB_DRIVE encrypted_usb
if [ "$?" = "0" ]; then
USB_DRIVE=/dev/mapper/encrypted_usb
fi
mount $USB_DRIVE $GPG_USB_MOUNT
if [ ! "$?" = "0" ]; then
if (( GPG_CTR > 0 )); then if (( GPG_CTR > 0 )); then
rm -rf $GPG_USB_MOUNT backup_unmount_drive ${USB_DRIVE}
reconstruct_key reconstruct_key
return 0 return 0
fi fi
dialog --title $"Recover Encryption Keys" \ dialog --title $"Recover Encryption Keys" \
--msgbox $"There was a problem mounting the USB drive to $GPG_USB_MOUNT" 6 70 --msgbox $"There was a problem mounting the USB drive $USB_DRIVE to $USB_MOUNT" 6 70
rm -rf $GPG_USB_MOUNT backup_unmount_drive ${USB_DRIVE}
exit 74393 exit 74393
fi fi
if [ ! -d $GPG_USB_MOUNT/.gnupg ]; then if [ ! -d $USB_MOUNT/.gnupg ]; then
if [ ! -d $GPG_USB_MOUNT/.gnupg_fragments ]; then if [ ! -d $USB_MOUNT/.gnupg_fragments ]; then
if (( GPG_CTR > 0 )); then if (( GPG_CTR > 0 )); then
umount -f $GPG_USB_MOUNT backup_unmount_drive ${USB_DRIVE}
rm -rf $GPG_USB_MOUNT
reconstruct_key reconstruct_key
return 0 return 0
fi fi
dialog --title $"Recover Encryption Keys" \ dialog --title $"Recover Encryption Keys" \
--msgbox $"The directory $GPG_USB_MOUNT/.gnupg or $GPG_USB_MOUNT/.gnupg_fragments was not found" 6 70 --msgbox $"The directory $USB_MOUNT/.gnupg or $USB_MOUNT/.gnupg_fragments was not found" 6 70
umount -f $GPG_USB_MOUNT backup_unmount_drive ${USB_DRIVE}
rm -rf $GPG_USB_MOUNT
exit 723814 exit 723814
fi fi
fi fi
if [ -d $GPG_USB_MOUNT/letsencrypt ]; then if [ -d $USB_MOUNT/letsencrypt ]; then
if [ ! -d /etc/letsencrypt ]; then if [ ! -d /etc/letsencrypt ]; then
mkdir /etc/letsencrypt mkdir /etc/letsencrypt
fi fi
echo $'Recovering LetsEncrypt keys' echo $'Recovering LetsEncrypt keys'
cp -r $GPG_USB_MOUNT/letsencrypt/* /etc/letsencrypt cp -r $USB_MOUNT/letsencrypt/* /etc/letsencrypt
fi fi
if [ -d $GPG_USB_MOUNT/.gnupg ]; then if [ -d $USB_MOUNT/.gnupg ]; then
if [ ! -d $HOME_DIR/.gnupg ]; then if [ ! -d $HOME_DIR/.gnupg ]; then
mkdir $HOME_DIR/.gnupg mkdir $HOME_DIR/.gnupg
fi fi
echo $'Recovering GPG keys' echo $'Recovering GPG keys'
cp -r $GPG_USB_MOUNT/.gnupg/* $HOME_DIR/.gnupg cp -r $USB_MOUNT/.gnupg/* $HOME_DIR/.gnupg
GPG_LOADING="no" GPG_LOADING="no"
dialog --title $"Recover Encryption Keys" \ dialog --title $"Recover Encryption Keys" \
--msgbox $"GPG Keyring loaded to $HOME_DIR" 6 70 --msgbox $"GPG Keyring loaded to $HOME_DIR" 6 70
@ -147,23 +132,22 @@ function interactive_gpg_from_usb {
if [ ! -d $HOME_DIR/.gnupg_fragments ]; then if [ ! -d $HOME_DIR/.gnupg_fragments ]; then
mkdir $HOME_DIR/.gnupg_fragments mkdir $HOME_DIR/.gnupg_fragments
fi fi
cp -r $GPG_USB_MOUNT/.gnupg_fragments/* $HOME_DIR/.gnupg_fragments cp -r $USB_MOUNT/.gnupg_fragments/* $HOME_DIR/.gnupg_fragments
fi fi
if [[ $SSH_IMPORTED == "no" ]]; then if [[ $SSH_IMPORTED == "no" ]]; then
if [ -d $GPG_USB_MOUNT/.ssh ]; then if [ -d $USB_MOUNT/.ssh ]; then
if [ ! -d $HOME_DIR/.ssh ]; then if [ ! -d $HOME_DIR/.ssh ]; then
mkdir $HOME_DIR/.ssh mkdir $HOME_DIR/.ssh
fi fi
cp $GPG_USB_MOUNT/.ssh/* $HOME_DIR/.ssh cp $USB_MOUNT/.ssh/* $HOME_DIR/.ssh
dialog --title $"Recover Encryption Keys" \ dialog --title $"Recover Encryption Keys" \
--msgbox $"ssh keys imported" 6 70 --msgbox $"ssh keys imported" 6 70
SSH_IMPORTED="yes" SSH_IMPORTED="yes"
fi fi
fi fi
umount -f $GPG_USB_MOUNT backup_unmount_drive ${USB_DRIVE}
rm -rf $GPG_USB_MOUNT
if [[ $GPG_LOADING == "yes" ]]; then if [[ $GPG_LOADING == "yes" ]]; then
dialog --title $"Recover Encryption Keys" \ dialog --title $"Recover Encryption Keys" \
--msgbox $"Now remove the USB drive. Insert the next drive containing a key fragment, or select Ok to finish" 6 70 --msgbox $"Now remove the USB drive. Insert the next drive containing a key fragment, or select Ok to finish" 6 70