From 60203948cfc5a343dec3c3766209d4dafce0805e Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 15 Jan 2018 01:34:29 +0100 Subject: Init crypted mount scripts --- cmount.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 cmount.sh (limited to 'cmount.sh') diff --git a/cmount.sh b/cmount.sh new file mode 100755 index 0000000..a6580c5 --- /dev/null +++ b/cmount.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +if [ -z "$1" ] ; then + echo 'Need a name to mount (if you know what i mean 💋)' + exit 1 +fi + +name="${1}" + + +device=$(sudo cat /etc/crypttab | grep -v "^#" | grep '.' | tr -s ' ' | grep "^${name} " | cut -d' ' -f 2) +rootkey=$(sudo cat /etc/crypttab | grep -v "^#" | grep '.' | tr -s ' ' | grep "^${name} " | cut -d' ' -f 3) + +res=0 +if [ -n "${device}" ] ; then + res=$(echo -e "${device}" | wc -l) +fi + +if [ "${res}" -gt 1 ] ; then + echo 'Too many crypted part with that name, sry baby' + exit 2 +elif [ "${res}" -eq 0 ] ; then + echo "Didn't found that babe" + exit 3 +elif [ "${res}" -eq 1 ] ; then +# echo '🍌 🍩' + + if [ -n "${rootkey}" -a "${rootkey}" != 'none' ] ; then + sudo cryptsetup luksOpen --key-file "${rootkey}" "${device}" "${name}" + res=${?} + if [ "${res}" -ne 0 ] ; then + echo 'Error with the key-file' "${rootkey}" + echo 'Trying without' + res=0 + rootkey="" + fi + fi + + if [ -z "${rootkey}" -o "${rootkey}" = 'none' ] ; then + sudo cryptsetup luksOpen "${device}" "${name}" + res=${?} + fi + + if [ "${res}" -eq 0 ] ; then + if sudo mount "/dev/mapper/${name}" ; then + echo 'Finish' + exit + else + echo 'Error while mounting' + echo 'undecrypting' + if sudo cryptsetup luksClose "${device}" "${name}" ; then + echo 'undecrypted' + exit 4 + else + echo 'Shit, i fail' + exit 5 + fi + fi + else + echo 'Error while decrypting' + exit 6 + fi +else + echo "I don't know why, but i can't mount him" + exit 7 +fi + -- cgit v1.2.3