Tidying
This commit is contained in:
parent
127d6431b4
commit
ff48df3dab
|
@ -13,7 +13,7 @@
|
|||
# License
|
||||
# =======
|
||||
#
|
||||
# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
|
||||
# Copyright (C) 2015-2017 Bob Mottram <bob@freedombone.net>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
|
@ -50,41 +50,41 @@ function show_help {
|
|||
|
||||
while [[ $# > 1 ]]
|
||||
do
|
||||
key="$1"
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
-h|--help)
|
||||
show_help
|
||||
;;
|
||||
-u|--user)
|
||||
case $key in
|
||||
-h|--help)
|
||||
show_help
|
||||
;;
|
||||
-u|--user)
|
||||
shift
|
||||
MY_USERNAME="$1"
|
||||
;;
|
||||
-d|--dev)
|
||||
shift
|
||||
if [[ "${1}" != '/dev/'* ]]; then
|
||||
USB_DRIVE=/dev/${1}1
|
||||
else
|
||||
USB_DRIVE=${1}
|
||||
fi
|
||||
;;
|
||||
-m|--master)
|
||||
shift
|
||||
MASTER_DRIVE="$1"
|
||||
;;
|
||||
-n|--fragments)
|
||||
shift
|
||||
KEY_FRAGMENTS=$1
|
||||
;;
|
||||
-f|--format)
|
||||
shift
|
||||
FORMAT="yes"
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
MY_USERNAME="$1"
|
||||
;;
|
||||
-d|--dev)
|
||||
shift
|
||||
if [[ "${1}" != '/dev/'* ]]; then
|
||||
USB_DRIVE=/dev/${1}1
|
||||
else
|
||||
USB_DRIVE=${1}
|
||||
fi
|
||||
;;
|
||||
-m|--master)
|
||||
shift
|
||||
MASTER_DRIVE="$1"
|
||||
;;
|
||||
-n|--fragments)
|
||||
shift
|
||||
KEY_FRAGMENTS=$1
|
||||
;;
|
||||
-f|--format)
|
||||
shift
|
||||
FORMAT="yes"
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ ! $MY_USERNAME ]; then
|
||||
|
@ -98,118 +98,118 @@ if [ ! -d /home/$MY_USERNAME ]; then
|
|||
fi
|
||||
|
||||
if [ ! -b $USB_DRIVE ]; then
|
||||
echo $'Please attach a USB drive'
|
||||
exit 65743
|
||||
echo $'Please attach a USB drive'
|
||||
exit 65743
|
||||
fi
|
||||
|
||||
umount -f $USB_MOUNT
|
||||
if [ ! -d $USB_MOUNT ]; then
|
||||
mkdir $USB_MOUNT
|
||||
mkdir $USB_MOUNT
|
||||
fi
|
||||
if [ -f /dev/mapper/encrypted_usb ]; then
|
||||
rm -rf /dev/mapper/encrypted_usb
|
||||
rm -rf /dev/mapper/encrypted_usb
|
||||
fi
|
||||
cryptsetup luksClose encrypted_usb
|
||||
|
||||
# optionally format the drive
|
||||
if [[ $FORMAT == "yes" ]]; then
|
||||
${PROJECT_NAME}-format ${USB_DRIVE::-1}
|
||||
if [ ! "$?" = "0" ]; then
|
||||
exit 36823
|
||||
fi
|
||||
${PROJECT_NAME}-format ${USB_DRIVE::-1}
|
||||
if [ ! "$?" = "0" ]; then
|
||||
exit 36823
|
||||
fi
|
||||
fi
|
||||
|
||||
cryptsetup luksOpen $USB_DRIVE encrypted_usb
|
||||
if [ "$?" = "0" ]; then
|
||||
USB_DRIVE=/dev/mapper/encrypted_usb
|
||||
USB_DRIVE=/dev/mapper/encrypted_usb
|
||||
fi
|
||||
mount $USB_DRIVE $USB_MOUNT
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo $"There was a problem mounting the USB drive to $USB_MOUNT"
|
||||
rm -rf $USB_MOUNT
|
||||
exit 78543
|
||||
echo $"There was a problem mounting the USB drive to $USB_MOUNT"
|
||||
rm -rf $USB_MOUNT
|
||||
exit 78543
|
||||
fi
|
||||
|
||||
# optionally create a master drive which contains the full GPG keyring
|
||||
if [[ $MASTER_DRIVE == "yes" || $MASTER_DRIVE == "y" || $MASTER_DRIVE == "1" ]]; then
|
||||
if [ ! -d /home/$MY_USERNAME/.gnupg ]; then
|
||||
echo $"No .gnupg directory was found for $MY_USERNAME"
|
||||
umount -f $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
exit 73025
|
||||
fi
|
||||
if [ ! -d /home/$MY_USERNAME/.gnupg ]; then
|
||||
echo $"No .gnupg directory was found for $MY_USERNAME"
|
||||
umount -f $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
exit 73025
|
||||
fi
|
||||
|
||||
# export the gpg key and backup key as text
|
||||
# so that it may be imported at the beginning of new installs
|
||||
GPG_TTY=$(tty)
|
||||
export GPG_TTY
|
||||
# export the gpg key and backup key as text
|
||||
# so that it may be imported at the beginning of new installs
|
||||
GPG_TTY=$(tty)
|
||||
export GPG_TTY
|
||||
|
||||
USER_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
|
||||
GPG_ID=$(su -m root -c "gpg --list-keys $USER_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//'" - $MY_USERNAME)
|
||||
GPG_BACKUP_ID=$(su -m root -c "gpg --list-keys \"(backup key)\" | sed -n '2p' | sed 's/^[ \t]*//'" - $MY_USERNAME)
|
||||
USER_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
|
||||
GPG_ID=$(su -m root -c "gpg --list-keys $USER_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//'" - $MY_USERNAME)
|
||||
GPG_BACKUP_ID=$(su -m root -c "gpg --list-keys \"(backup key)\" | sed -n '2p' | sed 's/^[ \t]*//'" - $MY_USERNAME)
|
||||
|
||||
gpgerrstr=$'error'
|
||||
gpgkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export $GPG_ID)
|
||||
if [[ "$gpgkey" == *"$gpgerrstr"* ]]; then
|
||||
echo $'Problem exporting public gpg key'
|
||||
echo "$gpgkey"
|
||||
exit 735282
|
||||
fi
|
||||
echo ''
|
||||
echo $'Enter your gpg private key passphrase:'
|
||||
gpgprivkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export-secret-key $GPG_ID)
|
||||
if [[ "$gpgprivkey" == *"$gpgerrstr"* ]]; then
|
||||
echo $'Problem exporting private gpg key'
|
||||
echo "$gpgprivkey"
|
||||
gpgprivkey=
|
||||
exit 629362
|
||||
fi
|
||||
gpgerrstr=$'error'
|
||||
gpgkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export $GPG_ID)
|
||||
if [[ "$gpgkey" == *"$gpgerrstr"* ]]; then
|
||||
echo $'Problem exporting public gpg key'
|
||||
echo "$gpgkey"
|
||||
exit 735282
|
||||
fi
|
||||
echo ''
|
||||
echo $'Enter your gpg private key passphrase:'
|
||||
gpgprivkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export-secret-key $GPG_ID)
|
||||
if [[ "$gpgprivkey" == *"$gpgerrstr"* ]]; then
|
||||
echo $'Problem exporting private gpg key'
|
||||
echo "$gpgprivkey"
|
||||
gpgprivkey=
|
||||
exit 629362
|
||||
fi
|
||||
|
||||
# Dummy password to get around not being able to create a key without passphrase
|
||||
BACKUP_DUMMY_PASSWORD='backup'
|
||||
# Dummy password to get around not being able to create a key without passphrase
|
||||
BACKUP_DUMMY_PASSWORD='backup'
|
||||
|
||||
backupgpgkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export $GPG_BACKUP_ID)
|
||||
if [[ "$backupgpgkey" == *"$gpgerrstr"* ]]; then
|
||||
echo $'Problem exporting public gpg backup key'
|
||||
echo "$backupgpgkey"
|
||||
exit 735282
|
||||
fi
|
||||
backupgpgprivkey=$(echo "$BACKUP_DUMMY_PASSWORD" | gpg --batch --passphrase-fd 0 --homedir=/home/$MY_USERNAME/.gnupg --armor --export-secret-key $GPG_BACKUP_ID)
|
||||
if [[ "$backupgpgprivkey" == *"$gpgerrstr"* ]]; then
|
||||
echo $'Problem exporting private gpg backup key'
|
||||
echo "$backupgpgprivkey"
|
||||
backupgpgprivkey=
|
||||
exit 629362
|
||||
fi
|
||||
backupgpgkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export $GPG_BACKUP_ID)
|
||||
if [[ "$backupgpgkey" == *"$gpgerrstr"* ]]; then
|
||||
echo $'Problem exporting public gpg backup key'
|
||||
echo "$backupgpgkey"
|
||||
exit 735282
|
||||
fi
|
||||
backupgpgprivkey=$(echo "$BACKUP_DUMMY_PASSWORD" | gpg --batch --passphrase-fd 0 --homedir=/home/$MY_USERNAME/.gnupg --armor --export-secret-key $GPG_BACKUP_ID)
|
||||
if [[ "$backupgpgprivkey" == *"$gpgerrstr"* ]]; then
|
||||
echo $'Problem exporting private gpg backup key'
|
||||
echo "$backupgpgprivkey"
|
||||
backupgpgprivkey=
|
||||
exit 629362
|
||||
fi
|
||||
|
||||
echo "$gpgkey" > $USB_MOUNT/.mastergpgkey
|
||||
echo "$gpgprivkey" >> $USB_MOUNT/.mastergpgkey
|
||||
echo "$backupgpgkey" > $USB_MOUNT/.backupgpgkey
|
||||
echo "$backupgpgprivkey" >> $USB_MOUNT/.backupgpgkey
|
||||
echo "$gpgkey" > $USB_MOUNT/.mastergpgkey
|
||||
echo "$gpgprivkey" >> $USB_MOUNT/.mastergpgkey
|
||||
echo "$backupgpgkey" > $USB_MOUNT/.backupgpgkey
|
||||
echo "$backupgpgprivkey" >> $USB_MOUNT/.backupgpgkey
|
||||
|
||||
cp -rf /home/$MY_USERNAME/.gnupg $USB_MOUNT
|
||||
cp -rf /home/$MY_USERNAME/.gnupg $USB_MOUNT
|
||||
|
||||
if [ -d /etc/letsencrypt ]; then
|
||||
cp -rf /etc/letsencrypt $USB_MOUNT
|
||||
echo $"LetsEncrypt keys copied to $USB_DRIVE"
|
||||
fi
|
||||
if [ -d $USB_MOUNT/.gnupg ]; then
|
||||
echo $"GPG Keyring copied to $USB_DRIVE. You may now remove the drive."
|
||||
else
|
||||
echo $"Unable to copy gpg keyring to $USB_DRIVE"
|
||||
fi
|
||||
umount -f $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
exit 0
|
||||
if [ -d /etc/letsencrypt ]; then
|
||||
cp -rf /etc/letsencrypt $USB_MOUNT
|
||||
echo $"LetsEncrypt keys copied to $USB_DRIVE"
|
||||
fi
|
||||
if [ -d $USB_MOUNT/.gnupg ]; then
|
||||
echo $"GPG Keyring copied to $USB_DRIVE. You may now remove the drive."
|
||||
else
|
||||
echo $"Unable to copy gpg keyring to $USB_DRIVE"
|
||||
fi
|
||||
umount -f $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Don't use the USB drive if it already contains a full keyring
|
||||
if [ -d $USB_MOUNT/.gnupg ]; then
|
||||
echo $'A full GPG keyring already exists on the USB drive.'
|
||||
echo $'Either reformat the USB drive or use a different drive.'
|
||||
umount -f $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
exit 3392
|
||||
echo $'A full GPG keyring already exists on the USB drive.'
|
||||
echo $'Either reformat the USB drive or use a different drive.'
|
||||
umount -f $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
exit 3392
|
||||
fi
|
||||
|
||||
# Append the username as a subdirectory.
|
||||
|
@ -221,14 +221,14 @@ FRAGMENTS_DIR=$FRAGMENTS_DIR/$MY_USERNAME
|
|||
|
||||
# make a directory to contain the fragments
|
||||
if [ ! -d $FRAGMENTS_DIR ]; then
|
||||
mkdir -p $FRAGMENTS_DIR
|
||||
echo $"Made directory $FRAGMENTS_DIR"
|
||||
mkdir -p $FRAGMENTS_DIR
|
||||
echo $"Made directory $FRAGMENTS_DIR"
|
||||
fi
|
||||
if [ ! -d $FRAGMENTS_DIR ]; then
|
||||
echo $"There was a problem making the directory $FRAGMENTS_DIR"
|
||||
umount -f $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
exit 6843
|
||||
echo $"There was a problem making the directory $FRAGMENTS_DIR"
|
||||
umount -f $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
exit 6843
|
||||
fi
|
||||
|
||||
cd $FRAGMENTS_DIR
|
||||
|
|
Loading…
Reference in New Issue