2015-11-04 21:34:31 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# Makes a USB drive containing a gpg key fragment
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2016-10-31 17:24:49 +01:00
|
|
|
# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
|
2015-11-04 21:34:31 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2016-02-13 23:09:27 +01:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2015-11-04 21:34:31 +01:00
|
|
|
# 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
|
2016-02-13 23:09:27 +01:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
2015-11-04 21:34:31 +01:00
|
|
|
#
|
2016-02-13 23:09:27 +01:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-11-04 21:34:31 +01:00
|
|
|
|
2015-11-27 12:42:16 +01:00
|
|
|
PROJECT_NAME='freedombone'
|
|
|
|
|
2015-11-27 17:52:23 +01:00
|
|
|
export TEXTDOMAIN=${PROJECT_NAME}-format
|
2015-11-27 12:42:16 +01:00
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
2015-11-04 21:34:31 +01:00
|
|
|
|
|
|
|
if [ ! $1 ]; then
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $'Specify a drive, such as sdb, sdc, etc'
|
2015-11-04 21:34:31 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-10-30 15:43:45 +01:00
|
|
|
USB_DRIVE_SHORT=${1}
|
2016-10-25 11:40:49 +02:00
|
|
|
if [[ "$1" == "/dev/"* ]]; then
|
|
|
|
USB_DRIVE=$1
|
2016-10-30 15:43:45 +01:00
|
|
|
USB_DRIVE_SHORT=$(echo "$USB_DRIVE" | awk -F '/' '{print $3}' | sed 's|1||g' | sed 's|2||g' | sed 's|3||g')
|
2016-10-25 11:40:49 +02:00
|
|
|
else
|
|
|
|
USB_DRIVE=/dev/${1}1
|
|
|
|
fi
|
|
|
|
|
2015-12-14 10:35:23 +01:00
|
|
|
LABEL="${PROJECT_NAME}"
|
2015-11-04 23:36:52 +01:00
|
|
|
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $'Partitioning drive'
|
2015-11-04 23:36:52 +01:00
|
|
|
echo "o
|
|
|
|
d
|
|
|
|
2
|
|
|
|
d
|
|
|
|
1
|
|
|
|
n
|
|
|
|
p
|
|
|
|
1
|
|
|
|
|
|
|
|
|
|
|
|
a
|
|
|
|
1
|
|
|
|
w
|
2016-10-30 15:43:45 +01:00
|
|
|
" | fdisk /dev/${USB_DRIVE_SHORT};mkfs.ext4 -L "$LABEL" /dev/${USB_DRIVE_SHORT}1
|
2015-11-04 21:34:31 +01:00
|
|
|
|
2015-11-27 16:29:43 +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
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"Failed to format $USB_DRIVE as LUKS"
|
2015-11-04 21:34:31 +01:00
|
|
|
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
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $"Failed to open LUKS formatted drive $USB_DRIVE"
|
2015-11-04 21:34:31 +01:00
|
|
|
exit 37232
|
|
|
|
fi
|
2015-12-14 10:35:23 +01:00
|
|
|
mkfs.ext4 /dev/mapper/encrypted_usb -L "$LABEL"
|
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-27 16:29:43 +01:00
|
|
|
echo $'Format of drive $USB_DRIVE failed'
|
2015-11-04 21:34:31 +01:00
|
|
|
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
|
2015-11-27 16:29:43 +01:00
|
|
|
echo $'Format completed'
|
2015-11-04 21:34:31 +01:00
|
|
|
exit 0
|