toyotacorolla

vroom
git clone https://git.davidvoz.net/toyotacorolla.git
index
logs
tree

unmounter
1#!/bin/sh
2# $ ummounter
3# you will then be guided through the rest of the steps
4# works best with USB drives, not tested with other devices
5
6set -e
7
8sudo -v || exit 1
9
10mapped_devices=""
11for path in /dev/mapper/usb*; do
12 [ -e "$path" ] || continue
13 mapped_devices="$mapped_devices $(basename "$path")"
14done
15
16set -- $mapped_devices
17
18[ "$#" -eq 0 ] && exit 1
19
20echo "Devices Found"
21i=1
22for dev in "$@"; do
23 echo "[$i] /dev/mapper/$dev"
24 i=$((i + 1))
25done
26
27if [ $i -eq 2 ]; then
28 index=1
29else
30 printf "select a device to unmount [1-%d]: " $(( $# ))
31 read index
32
33 case "$index" in
34 ''|*[!1-9]*)
35 exit 1
36 ;;
37 esac
38
39 if [ "$index" -lt 1 ] || [ "$index" -ge "$#" ]; then
40 exit 1
41 fi
42fi
43
44i=1
45for dev in "$@"; do
46 [ "$i" -eq "$index" ] && name="$dev" && break
47 i=$((i + 1))
48done
49
50mount_point="/mnt/$name"
51
52if mountpoint -q "$mount_point" 2>/dev/null; then
53 echo "umounting $mount_point"
54 sudo umount "$mount_point"
55fi
56
57echo "cryptsetup closing $name"
58sudo cryptsetup close "$name"
59
60echo "/dev/mapper/$name unmounted successfully"