freedombone-format 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Makes a USB drive containing a gpg key fragment
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-format
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. if [ ! $1 ]; then
  34. echo $'Specify a drive, such as sdb, sdc, etc'
  35. exit 1
  36. fi
  37. USB_DRIVE=/dev/${1}1
  38. LABEL='Freedombone'
  39. echo $'Partitioning drive'
  40. echo "o
  41. d
  42. 2
  43. d
  44. 1
  45. n
  46. p
  47. 1
  48. a
  49. 1
  50. w
  51. " | fdisk /dev/${1};mkfs.ext4 -L "$LABEL" /dev/${1}1
  52. echo $"Formatting $USB_DRIVE as LUKS"
  53. cryptsetup -y -v luksFormat ${USB_DRIVE}
  54. if [ ! "$?" = "0" ]; then
  55. echo $"Failed to format $USB_DRIVE as LUKS"
  56. exit 36823
  57. fi
  58. cryptsetup luksOpen ${USB_DRIVE} encrypted_usb
  59. if [ ! "$?" = "0" ]; then
  60. echo $"Failed to open LUKS formatted drive $USB_DRIVE"
  61. exit 37232
  62. fi
  63. mkfs.ext4 /dev/mapper/encrypted_usb -L Freedombone
  64. if [ ! "$?" = "0" ]; then
  65. cryptsetup luksClose encrypted_usb
  66. echo $'Format of drive $USB_DRIVE failed'
  67. exit 73218
  68. fi
  69. sleep 2
  70. cryptsetup luksClose encrypted_usb
  71. if [ -f /dev/mapper/encrypted_usb ]; then
  72. rm -rf /dev/mapper/encrypted_usb
  73. fi
  74. echo $'Format completed'
  75. exit 0