90 lines
2.8 KiB
Bash
90 lines
2.8 KiB
Bash
|
#!/bin/bash
|
||
|
# script to open a LUKS encrypted container file (use close_container.sh to close)
|
||
|
# -must be run with root privileges
|
||
|
# -start it without any or with 2 arguments: ./open_container.sh /path/to/container /path/to/mount_point
|
||
|
# written by Christian Ulrich (based on a script from http://wiki.ubuntuusers.de/LUKS/Containerdatei)
|
||
|
# version: 0.2
|
||
|
# date: 2011/09/13
|
||
|
|
||
|
run=1
|
||
|
choice=
|
||
|
CRYPTNAME=container
|
||
|
FS=ext4
|
||
|
LOOPDEV=`losetup -f`
|
||
|
|
||
|
if test $# -ne 0; then
|
||
|
if test $# -ne 2; then
|
||
|
echo "Aufruf des Skripts entweder ohne Argumante oder: ./open_container /Pfad/zum/Container /Pfad/zum/Mountpoint"
|
||
|
exit 1
|
||
|
else
|
||
|
SAFE=$1
|
||
|
MNT=$2
|
||
|
fi
|
||
|
else
|
||
|
SAFE=/home/christian/privat/encrypted
|
||
|
MNT=/home/christian/mnt
|
||
|
fi
|
||
|
|
||
|
echo "open_container.sh v0.2 (by Christian Ulrich)
|
||
|
---------------------------------------------"
|
||
|
|
||
|
while [ $run -ne 0 ]; do
|
||
|
echo
|
||
|
echo "Bitte wählen:"
|
||
|
echo "-------------"
|
||
|
echo "[1] Pfad zum Container ändern ($SAFE)"
|
||
|
echo "[2] Dateiname in /dev/mapper/ ändern ($CRYPTNAME)"
|
||
|
echo "[3] Mount-Pfad ändern ($MNT)"
|
||
|
echo "[4] Dateisystem ändern ($FS)"
|
||
|
echo "---------------------------------------------------"
|
||
|
echo "[o] Container öffnen"
|
||
|
echo "[q] Script beenden"
|
||
|
read choice
|
||
|
case $choice in
|
||
|
1 ) echo "Neuen Pfad eingeben oder <return> um abzubrechen (aktueller Pfad: $SAFE):"
|
||
|
SAFE_tmp=
|
||
|
read SAFE_tmp
|
||
|
if [[ -n "$SAFE_tmp" ]]; then #if only <return> was pressed
|
||
|
SAFE=$SAFE_tmp
|
||
|
fi
|
||
|
;;
|
||
|
2 ) echo "Neuen Dateinamen eingeben oder <return> um abzubrechen (aktueller Dateiname: $CRYPTNAME):"
|
||
|
CRYPTNAME_tmp=
|
||
|
read CRYPTNAME_tmp
|
||
|
if [[ -n "$CRYPTNAME_tmp" ]]; then
|
||
|
CRYPTNAME=$CRYPTNAME_tmp
|
||
|
fi
|
||
|
;;
|
||
|
3 ) echo "Neuen Mount-Pfad eingeben oder <return> um abzubrechen (aktueller Pfad: $MNT):"
|
||
|
MNT_tmp=
|
||
|
read MNT_tmp
|
||
|
if [[ -n "$MNT_tmp" ]]; then
|
||
|
MNT=$MNT_tmp
|
||
|
fi
|
||
|
;;
|
||
|
4 ) echo "Neues Dateisystem eingeben oder <return> um abzubrechen (aktuelles Dateisystem: $FS)"
|
||
|
FS_tmp=
|
||
|
read FS_tmp
|
||
|
if [[ -n "$FS_tmp" ]]; then
|
||
|
FS=$FS_tmp
|
||
|
fi
|
||
|
;;
|
||
|
'o' ) run=0
|
||
|
echo "Container öffnen"
|
||
|
if [ "`losetup -a | grep -c "$SAFE"`" != "0" ]; then
|
||
|
echo "bereits eingehängt"
|
||
|
exit
|
||
|
fi
|
||
|
losetup $LOOPDEV $SAFE
|
||
|
cryptsetup luksOpen $LOOPDEV $CRYPTNAME
|
||
|
mount -t $FS /dev/mapper/$CRYPTNAME $MNT
|
||
|
echo "Verschlüsseltes Dateisystem ist jetzt unter $MNT gemountet und kann mit dem Skript close_container.sh wieder unmountet werden. Aufruf wie folgt:"
|
||
|
echo "######################## cut here ###########################"
|
||
|
echo "sudo ./close_container.sh $SAFE $CRYPTNAME $MNT"
|
||
|
echo "######################## cut here ###########################"
|
||
|
;;
|
||
|
'q' ) run=0;;
|
||
|
* ) echo "Falsche Eingabe!";;
|
||
|
esac
|
||
|
done
|