From 82df70eff06e7b44ee84283070d7f801f7fc1d92 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sat, 6 Nov 2021 20:25:45 -0400 Subject: initial commit --- .local/bin/cryptusb/create-cryptusb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 .local/bin/cryptusb/create-cryptusb (limited to '.local/bin/cryptusb/create-cryptusb') 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 @@ +#!/bin/sh +# Prompts for and creates a LUKS encrypted partition on a device + +# Get disks connected to the system that are hotpluggable (USBs) +devices="$(lsblk -lp -o NAME,SIZE,HOTPLUG,TYPE | grep "1 disk" | awk '{print $1,"-",$2}')" +[ "$devices" = "" ] && echo "no devices available" && exit 0 + +# Prompt for device selection from the user +select=$(echo "$devices" | dmenu -i -p "Select a device") +[ "$select" = "" ] && echo "no device selected" && exit 0 + +# Get confirmation since this is a potentially dangerous operation +yn=$(echo "No\nYes" | dmenu -i -p "Create encrypted partition on $select") +[ "$yn" != "Yes" ] && exit 0 + +# Get device path from selection string +usb=$(echo $select | cut -d ' ' -f 1) +echo $usb + +# Create LUKS partition on selected device (user will be promted for password to encrypt) +sudo cryptsetup --type luks2 luksFormat "$usb" + +# Open device and create filesystem on partition +echo "creating filesystem" +map_name="crypt-create" +sudo cryptsetup open "$usb" "$map_name" +sudo mkfs.ext4 "/dev/mapper/$map_name" + +# Close device after creating filesystem +sudo cryptsetup close "$map_name" + +echo "done" + + -- cgit v1.2.3