aboutsummaryrefslogtreecommitdiff
path: root/cumount.sh
blob: 3a45c06844c449976fa3c6f4d38b293828171ffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh

if [ -z "$1" ] ; then
    echo 'Need a name to umount'
    exit 1
fi

name="${1}"

mountpoint=$(lsblk -lo NAME,MOUNTPOINT | grep "${1}" | tr -s ' ' | cut -d' ' -f 2)

if [ -z "${mountpoint}" ] ; then
    echo "${name} not found"
    exit 1
fi

if sudo umount "${mountpoint}" ; then
    if sudo cryptsetup luksClose "${name}" ; then
        echo 'Finish'
    else
        echo "Error : ${name} can't be closed"
        exit 2
    fi
else
    echo "Error : ${mountpoint} can't be umounted"
    exit 3
fi