freedombone-format 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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-2016 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 Affero 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 Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero 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. if [[ "$1" == "/dev/"* ]]; then
  38. USB_DRIVE=$1
  39. else
  40. USB_DRIVE=/dev/${1}1
  41. fi
  42. LABEL="${PROJECT_NAME}"
  43. echo $'Partitioning drive'
  44. echo "o
  45. d
  46. 2
  47. d
  48. 1
  49. n
  50. p
  51. 1
  52. a
  53. 1
  54. w
  55. " | fdisk /dev/${1};mkfs.ext4 -L "$LABEL" /dev/${1}1
  56. echo $"Formatting $USB_DRIVE as LUKS"
  57. cryptsetup -y -v luksFormat ${USB_DRIVE}
  58. if [ ! "$?" = "0" ]; then
  59. echo $"Failed to format $USB_DRIVE as LUKS"
  60. exit 36823
  61. fi
  62. cryptsetup luksOpen ${USB_DRIVE} encrypted_usb
  63. if [ ! "$?" = "0" ]; then
  64. echo $"Failed to open LUKS formatted drive $USB_DRIVE"
  65. exit 37232
  66. fi
  67. mkfs.ext4 /dev/mapper/encrypted_usb -L "$LABEL"
  68. if [ ! "$?" = "0" ]; then
  69. cryptsetup luksClose encrypted_usb
  70. echo $'Format of drive $USB_DRIVE failed'
  71. exit 73218
  72. fi
  73. sleep 2
  74. cryptsetup luksClose encrypted_usb
  75. if [ -f /dev/mapper/encrypted_usb ]; then
  76. rm -rf /dev/mapper/encrypted_usb
  77. fi
  78. echo $'Format completed'
  79. exit 0