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