freedombone-format 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. if [ ! $1 ]; then
  31. echo 'Specify a drive, such as sdb, sdc, etc'
  32. exit 1
  33. fi
  34. USB_DRIVE=/dev/${1}1
  35. LABEL='Freedombone'
  36. echo 'Partitioning drive'
  37. echo "o
  38. d
  39. 2
  40. d
  41. 1
  42. n
  43. p
  44. 1
  45. a
  46. 1
  47. w
  48. " | fdisk /dev/${1};mkfs.ext4 -L "$LABEL" /dev/${1}1
  49. echo "Formatting $USB_DRIVE as LUKS"
  50. cryptsetup -y -v luksFormat ${USB_DRIVE}
  51. if [ ! "$?" = "0" ]; then
  52. echo "Failed to format $USB_DRIVE as LUKS"
  53. exit 36823
  54. fi
  55. cryptsetup luksOpen ${USB_DRIVE} encrypted_usb
  56. if [ ! "$?" = "0" ]; then
  57. echo "Failed to open LUKS formatted drive $USB_DRIVE"
  58. exit 37232
  59. fi
  60. mkfs.ext4 /dev/mapper/encrypted_usb -L Freedombone
  61. if [ ! "$?" = "0" ]; then
  62. cryptsetup luksClose encrypted_usb
  63. echo 'Format of drive $USB_DRIVE failed'
  64. exit 73218
  65. fi
  66. sleep 2
  67. cryptsetup luksClose encrypted_usb
  68. if [ -f /dev/mapper/encrypted_usb ]; then
  69. rm -rf /dev/mapper/encrypted_usb
  70. fi
  71. echo 'Format completed'
  72. exit 0