diff options
Diffstat (limited to '.local/bin/cryptusb')
-rwxr-xr-x | .local/bin/cryptusb/create-cryptusb | 34 | ||||
-rwxr-xr-x | .local/bin/cryptusb/handle-cryptusb | 8 | ||||
-rwxr-xr-x | .local/bin/cryptusb/mount-cryptusb | 5 | ||||
-rwxr-xr-x | .local/bin/cryptusb/sync-cryptusb | 6 | ||||
-rwxr-xr-x | .local/bin/cryptusb/umount-cryptusb | 5 |
5 files changed, 58 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) | ||
5 | devices="$(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 | ||
9 | select=$(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 | ||
13 | yn=$(echo "No\nYes" | dmenu -i -p "Create encrypted partition on $select") | ||
14 | [ "$yn" != "Yes" ] && exit 0 | ||
15 | |||
16 | # Get device path from selection string | ||
17 | usb=$(echo $select | cut -d ' ' -f 1) | ||
18 | echo $usb | ||
19 | |||
20 | # Create LUKS partition on selected device (user will be promted for password to encrypt) | ||
21 | sudo cryptsetup --type luks2 luksFormat "$usb" | ||
22 | |||
23 | # Open device and create filesystem on partition | ||
24 | echo "creating filesystem" | ||
25 | map_name="crypt-create" | ||
26 | sudo cryptsetup open "$usb" "$map_name" | ||
27 | sudo mkfs.ext4 "/dev/mapper/$map_name" | ||
28 | |||
29 | # Close device after creating filesystem | ||
30 | sudo cryptsetup close "$map_name" | ||
31 | |||
32 | echo "done" | ||
33 | |||
34 | |||
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 @@ | |||
1 | #!/bin/sh | ||
2 | # Single script for easy handling of encrypted USB | ||
3 | # Calls mount, sync, and umount scripts to automatically handle what is commonly | ||
4 | # run for encrypted USBs | ||
5 | |||
6 | mount-cryptusb && notify-send "Encrypted USB mounted" | ||
7 | sync-cryptusb && notify-send "Encrypted USB synced" | ||
8 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | # Mounts LUKS encrypted USB | ||
3 | |||
4 | sudo cryptsetup open /dev/sdc cryptusb | ||
5 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | # Syncs important files to encrypted USB | ||
3 | |||
4 | rsync -avP --exclude=".steam*" --exclude="virtual_machines*" --exclude="media*" \ | ||
5 | --exclude="*.iso" --exclude="*.qcow2" \ | ||
6 | $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 @@ | |||
1 | #!/bin/sh | ||
2 | # Unmounts LUKS encrypted USB | ||
3 | |||
4 | sudo umount /mnt/cryptusb | ||
5 | sudo cryptsetup close cryptusb | ||