2015-11-04 21:34:31 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# Makes a USB drive containing a gpg key fragment
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
if [ ! $1 ]; then
|
|
|
|
echo 'Specify a drive, such as sdb, sdc, etc'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-11-04 22:05:24 +01:00
|
|
|
USB_DRIVE=/dev/${1}
|
2015-11-04 21:34:31 +01:00
|
|
|
|
|
|
|
echo "Formatting $USB_DRIVE as LUKS"
|
2015-11-04 22:05:24 +01:00
|
|
|
cryptsetup -y -v luksFormat ${USB_DRIVE}
|
2015-11-04 21:34:31 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
echo "Failed to format $USB_DRIVE as LUKS"
|
|
|
|
exit 36823
|
|
|
|
fi
|
2015-11-04 22:05:24 +01:00
|
|
|
cryptsetup luksOpen ${USB_DRIVE} encrypted_usb
|
2015-11-04 21:34:31 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
echo "Failed to open LUKS formatted drive $USB_DRIVE"
|
|
|
|
exit 37232
|
|
|
|
fi
|
2015-11-04 22:34:05 +01:00
|
|
|
mkfs.ext4 /dev/mapper/encrypted_usb -L Freedombone
|
2015-11-04 21:34:31 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
2015-11-04 22:05:24 +01:00
|
|
|
cryptsetup luksClose encrypted_usb
|
2015-11-04 21:34:31 +01:00
|
|
|
echo 'Format of drive $USB_DRIVE failed'
|
|
|
|
exit 73218
|
|
|
|
fi
|
2015-11-04 22:05:24 +01:00
|
|
|
sleep 2
|
2015-11-04 21:34:31 +01:00
|
|
|
cryptsetup luksClose encrypted_usb
|
|
|
|
if [ -f /dev/mapper/encrypted_usb ]; then
|
|
|
|
rm -rf /dev/mapper/encrypted_usb
|
|
|
|
fi
|
|
|
|
echo 'Format completed'
|
|
|
|
exit 0
|