From b199fb98fd8c0ecdf004510f1f5d8e10c6c7d66b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 4 Nov 2015 20:34:31 +0000 Subject: [PATCH] Command to format drives as LUKS --- Makefile | 4 +++ man/freedombone-format.1.gz | Bin 0 -> 519 bytes src/freedombone-format | 60 ++++++++++++++++++++++++++++++++++++ src/freedombone-keydrive | 16 +--------- 4 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 man/freedombone-format.1.gz create mode 100755 src/freedombone-format diff --git a/Makefile b/Makefile index c7111153..16f24ffa 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,7 @@ install: install -m 755 src/${APP}-addsipuser ${DESTDIR}${PREFIX}/bin install -m 755 src/${APP}-rmsipuser ${DESTDIR}${PREFIX}/bin install -m 755 src/${APP}-sipfreeext ${DESTDIR}${PREFIX}/bin + install -m 755 src/${APP}-format ${DESTDIR}${PREFIX}/bin mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/${APP}.1.gz ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/${APP}-keydrive.1.gz ${DESTDIR}${PREFIX}/share/man/man1 @@ -73,6 +74,7 @@ install: install -m 644 man/${APP}-logging.1.gz ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/${APP}-addsipuser.1.gz ${DESTDIR}${PREFIX}/share/man/man1 install -m 644 man/${APP}-rmsipuser.1.gz ${DESTDIR}${PREFIX}/share/man/man1 + install -m 644 man/${APP}-format.1.gz ${DESTDIR}${PREFIX}/share/man/man1 uninstall: rm -f ${PREFIX}/share/man/man1/${APP}.1.gz rm -f ${PREFIX}/share/man/man1/${APP}-keydrive.1.gz @@ -102,6 +104,7 @@ uninstall: rm -f ${PREFIX}/share/man/man1/${APP}-logging.1.gz rm -f ${PREFIX}/share/man/man1/${APP}-addsipuser.1.gz rm -f ${PREFIX}/share/man/man1/${APP}-rmsipuser.1.gz + rm -f ${PREFIX}/share/man/man1/${APP}-format.1.gz rm -rf ${PREFIX}/share/${APP} rm -f ${PREFIX}/bin/${APP} rm -f ${PREFIX}/bin/zeronetavahi @@ -135,6 +138,7 @@ uninstall: rm -f ${PREFIX}/bin/${APP}-addsipuser rm -f ${PREFIX}/bin/${APP}-rmsipuser rm -f ${PREFIX}/bin/${APP}-sipfreeext + rm -f ${PREFIX}/bin/${APP}-format clean: rm -f \#* \.#* debian/*.substvars debian/*.log rm -fr deb.* debian/${APP} diff --git a/man/freedombone-format.1.gz b/man/freedombone-format.1.gz new file mode 100644 index 0000000000000000000000000000000000000000..c6a792182553c88947e0b6520fa42ed5edc06596 GIT binary patch literal 519 zcmV+i0{HzOiwFRzYdTf{19ei{Zrd;nefL)oepw4Fc9U&D8w|tZ&P{^mhS*-Q+kX$IOUr$%@bh&Vyxa0(x5`xJbPU-Yg;>zr6p0TRhLlOno&m{q6ruVhM+=C;( z#HuDR3TmwkW(HE0Z5s}Hh!qH&hK>XFbU39vJyU~ZY=^PNT4~!)Q&?BV@d7A~scGo@1vh1rde*w1 zGAecE|0m~jq6X=CwqXdPS+u;E?N$H!?L`MH&ok7fg=ZBWL| z{Ys5CtmK9lEtnTl>9&DdV_R9HuwU8%OZ?sIG^ItiCoMWHY0>G3Fl%9re5Lb)La$~- zHgf*6Q4&v3Ug(QW&%E@D*dcgstnJ_Yqp+IpByjM&T72!?N$yU9Npax!gsev zG~h-c9ae4#!Mr!fo|;kwyRZ31Ps*A49_LiwZy%AzN+(Fs?8th;ba-4cyJMHNoWC1x Jw|yxD007?A`IG +# +# 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 . + + +if [ ! $1 ]; then + echo 'Specify a drive, such as sdb, sdc, etc' + exit 1 +fi + +USB_DRIVE=/dev/$1 + +echo "Formatting $USB_DRIVE as LUKS" +cryptsetup -y -v luksFormat $USB_DRIVE +if [ ! "$?" = "0" ]; then + echo "Failed to format $USB_DRIVE as LUKS" + exit 36823 +fi +cryptsetup luksOpen $USB_DRIVE encrypted_usb +if [ ! "$?" = "0" ]; then + echo "Failed to open LUKS formatted drive $USB_DRIVE" + exit 37232 +fi +mkfs.ext4 /dev/mapper/encrypted_usb +if [ ! "$?" = "0" ]; then + echo 'Format of drive $USB_DRIVE failed' + exit 73218 +fi +cryptsetup luksClose encrypted_usb +if [ -f /dev/mapper/encrypted_usb ]; then + rm -rf /dev/mapper/encrypted_usb +fi +echo 'Format completed' +exit 0 diff --git a/src/freedombone-keydrive b/src/freedombone-keydrive index 54e6c225..e40ed1c3 100755 --- a/src/freedombone-keydrive +++ b/src/freedombone-keydrive @@ -105,24 +105,10 @@ cryptsetup luksClose encrypted_usb # optionally format the drive if [[ $FORMAT == "yes" ]]; then - echo "Formatting ${USB_DRIVE::-1} as LUKS" - cryptsetup -y -v luksFormat ${USB_DRIVE::-1} + freedombone-format ${USB_DRIVE::-1} if [ ! "$?" = "0" ]; then exit 36823 fi - cryptsetup luksOpen ${USB_DRIVE::-1} encrypted_usb - if [ ! "$?" = "0" ]; then - exit 37232 - fi - mkfs.ext4 /dev/mapper/encrypted_usb - if [ ! "$?" = "0" ]; then - exit 73218 - fi - cryptsetup luksClose encrypted_usb - if [ -f /dev/mapper/encrypted_usb ]; then - rm -rf /dev/mapper/encrypted_usb - fi - echo 'Format completed' fi cryptsetup luksOpen $USB_DRIVE encrypted_usb