From 750d83ffa80506136a2efd62413c88460c39d514 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 27 Oct 2016 15:08:28 +0100 Subject: [PATCH] Mounting and unmounting the usb drive --- src/freedombone-utils-keys | 52 +++++++++++++------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/src/freedombone-utils-keys b/src/freedombone-utils-keys index 01c3dac9..9aecaae5 100755 --- a/src/freedombone-utils-keys +++ b/src/freedombone-utils-keys @@ -83,63 +83,48 @@ function interactive_gpg_from_usb { exit 739836 fi - GPG_USB_MOUNT='/mnt/usb' - umount -f $GPG_USB_MOUNT - if [ ! -d $GPG_USB_MOUNT ]; then - mkdir -p $GPG_USB_MOUNT - fi + backup_mount_drive ${USB_DRIVE} ${MY_USERNAME} - if [ -f /dev/mapper/encrypted_usb ]; 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 [ ! -d $USB_MOUNT ]; then if (( GPG_CTR > 0 )); then - rm -rf $GPG_USB_MOUNT + backup_unmount_drive ${USB_DRIVE} reconstruct_key return 0 fi dialog --title $"Recover Encryption Keys" \ - --msgbox $"There was a problem mounting the USB drive to $GPG_USB_MOUNT" 6 70 - rm -rf $GPG_USB_MOUNT + --msgbox $"There was a problem mounting the USB drive $USB_DRIVE to $USB_MOUNT" 6 70 + backup_unmount_drive ${USB_DRIVE} exit 74393 fi - if [ ! -d $GPG_USB_MOUNT/.gnupg ]; then - if [ ! -d $GPG_USB_MOUNT/.gnupg_fragments ]; then + if [ ! -d $USB_MOUNT/.gnupg ]; then + if [ ! -d $USB_MOUNT/.gnupg_fragments ]; then if (( GPG_CTR > 0 )); then - umount -f $GPG_USB_MOUNT - rm -rf $GPG_USB_MOUNT + backup_unmount_drive ${USB_DRIVE} reconstruct_key return 0 fi dialog --title $"Recover Encryption Keys" \ - --msgbox $"The directory $GPG_USB_MOUNT/.gnupg or $GPG_USB_MOUNT/.gnupg_fragments was not found" 6 70 - umount -f $GPG_USB_MOUNT - rm -rf $GPG_USB_MOUNT + --msgbox $"The directory $USB_MOUNT/.gnupg or $USB_MOUNT/.gnupg_fragments was not found" 6 70 + backup_unmount_drive ${USB_DRIVE} exit 723814 fi fi - if [ -d $GPG_USB_MOUNT/letsencrypt ]; then + if [ -d $USB_MOUNT/letsencrypt ]; then if [ ! -d /etc/letsencrypt ]; then mkdir /etc/letsencrypt fi echo $'Recovering LetsEncrypt keys' - cp -r $GPG_USB_MOUNT/letsencrypt/* /etc/letsencrypt + cp -r $USB_MOUNT/letsencrypt/* /etc/letsencrypt fi - if [ -d $GPG_USB_MOUNT/.gnupg ]; then + if [ -d $USB_MOUNT/.gnupg ]; then if [ ! -d $HOME_DIR/.gnupg ]; then mkdir $HOME_DIR/.gnupg fi echo $'Recovering GPG keys' - cp -r $GPG_USB_MOUNT/.gnupg/* $HOME_DIR/.gnupg + cp -r $USB_MOUNT/.gnupg/* $HOME_DIR/.gnupg GPG_LOADING="no" dialog --title $"Recover Encryption Keys" \ --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 mkdir $HOME_DIR/.gnupg_fragments fi - cp -r $GPG_USB_MOUNT/.gnupg_fragments/* $HOME_DIR/.gnupg_fragments + cp -r $USB_MOUNT/.gnupg_fragments/* $HOME_DIR/.gnupg_fragments fi if [[ $SSH_IMPORTED == "no" ]]; then - if [ -d $GPG_USB_MOUNT/.ssh ]; then + if [ -d $USB_MOUNT/.ssh ]; then if [ ! -d $HOME_DIR/.ssh ]; then mkdir $HOME_DIR/.ssh fi - cp $GPG_USB_MOUNT/.ssh/* $HOME_DIR/.ssh + cp $USB_MOUNT/.ssh/* $HOME_DIR/.ssh dialog --title $"Recover Encryption Keys" \ --msgbox $"ssh keys imported" 6 70 SSH_IMPORTED="yes" fi fi - umount -f $GPG_USB_MOUNT - rm -rf $GPG_USB_MOUNT + backup_unmount_drive ${USB_DRIVE} if [[ $GPG_LOADING == "yes" ]]; then 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