#!/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