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 ++++++++++++++++++++++++++++++++++ .local/bin/cryptusb/handle-cryptusb | 8 ++++++++ .local/bin/cryptusb/mount-cryptusb | 5 +++++ .local/bin/cryptusb/sync-cryptusb | 6 ++++++ .local/bin/cryptusb/umount-cryptusb | 5 +++++ 5 files changed, 58 insertions(+) create mode 100755 .local/bin/cryptusb/create-cryptusb create mode 100755 .local/bin/cryptusb/handle-cryptusb create mode 100755 .local/bin/cryptusb/mount-cryptusb create mode 100755 .local/bin/cryptusb/sync-cryptusb create mode 100755 .local/bin/cryptusb/umount-cryptusb (limited to '.local/bin/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" + + diff --git a/.local/bin/cryptusb/handle-cryptusb b/.local/bin/cryptusb/handle-cryptusb new file mode 100755 index 0000000..63d6ef4 --- /dev/null +++ b/.local/bin/cryptusb/handle-cryptusb @@ -0,0 +1,8 @@ +#!/bin/sh +# Single script for easy handling of encrypted USB +# Calls mount, sync, and umount scripts to automatically handle what is commonly +# run for encrypted USBs + +mount-cryptusb && notify-send "Encrypted USB mounted" +sync-cryptusb && notify-send "Encrypted USB synced" +umount-cryptusb && notify-send "Encrypted USB unmounted" diff --git a/.local/bin/cryptusb/mount-cryptusb b/.local/bin/cryptusb/mount-cryptusb new file mode 100755 index 0000000..882734c --- /dev/null +++ b/.local/bin/cryptusb/mount-cryptusb @@ -0,0 +1,5 @@ +#!/bin/sh +# Mounts LUKS encrypted USB + +sudo cryptsetup open /dev/sdc cryptusb +sudo mount /dev/mapper/cryptusb /mnt/cryptusb diff --git a/.local/bin/cryptusb/sync-cryptusb b/.local/bin/cryptusb/sync-cryptusb new file mode 100755 index 0000000..e9d3f1a --- /dev/null +++ b/.local/bin/cryptusb/sync-cryptusb @@ -0,0 +1,6 @@ +#!/bin/sh +# Syncs important files to encrypted USB + +rsync -avP --exclude=".steam*" --exclude="virtual_machines*" --exclude="media*" \ + --exclude="*.iso" --exclude="*.qcow2" \ + $HOME/ /mnt/cryptusb/$USER@$(hostname)/ diff --git a/.local/bin/cryptusb/umount-cryptusb b/.local/bin/cryptusb/umount-cryptusb new file mode 100755 index 0000000..c3c4b93 --- /dev/null +++ b/.local/bin/cryptusb/umount-cryptusb @@ -0,0 +1,5 @@ +#!/bin/sh +# Unmounts LUKS encrypted USB + +sudo umount /mnt/cryptusb +sudo cryptsetup close cryptusb -- cgit v1.2.3