summaryrefslogtreecommitdiff
path: root/.local/bin/cryptusb/create-cryptusb
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2021-11-06 20:25:45 -0400
committerSam Chudnick <sam@chudnick.com>2021-11-06 20:25:45 -0400
commit82df70eff06e7b44ee84283070d7f801f7fc1d92 (patch)
treed17ea9cc6e012b16ff0cdeffcf4a97b5e5cd2d11 /.local/bin/cryptusb/create-cryptusb
initial commit
Diffstat (limited to '.local/bin/cryptusb/create-cryptusb')
-rwxr-xr-x.local/bin/cryptusb/create-cryptusb34
1 files changed, 34 insertions, 0 deletions
diff --git a/.local/bin/cryptusb/create-cryptusb b/.local/bin/cryptusb/create-cryptusb
new file mode 100755
index 0000000..e0f49fe
--- /dev/null
+++ b/.local/bin/cryptusb/create-cryptusb
@@ -0,0 +1,34 @@
1#!/bin/sh
2# Prompts for and creates a LUKS encrypted partition on a device
3
4# Get disks connected to the system that are hotpluggable (USBs)
5devices="$(lsblk -lp -o NAME,SIZE,HOTPLUG,TYPE | grep "1 disk" | awk '{print $1,"-",$2}')"
6[ "$devices" = "" ] && echo "no devices available" && exit 0
7
8# Prompt for device selection from the user
9select=$(echo "$devices" | dmenu -i -p "Select a device")
10[ "$select" = "" ] && echo "no device selected" && exit 0
11
12# Get confirmation since this is a potentially dangerous operation
13yn=$(echo "No\nYes" | dmenu -i -p "Create encrypted partition on $select")
14[ "$yn" != "Yes" ] && exit 0
15
16# Get device path from selection string
17usb=$(echo $select | cut -d ' ' -f 1)
18echo $usb
19
20# Create LUKS partition on selected device (user will be promted for password to encrypt)
21sudo cryptsetup --type luks2 luksFormat "$usb"
22
23# Open device and create filesystem on partition
24echo "creating filesystem"
25map_name="crypt-create"
26sudo cryptsetup open "$usb" "$map_name"
27sudo mkfs.ext4 "/dev/mapper/$map_name"
28
29# Close device after creating filesystem
30sudo cryptsetup close "$map_name"
31
32echo "done"
33
34