staging.inyokaproject.org

Script für erstellung und verwaltung versch. LUKS Containerdatein

Status: Ungelöst | Ubuntu-Version: Ubuntu GNOME 16.04 (Xenial Xerus)
Antworten |

itoss

Avatar von itoss

Anmeldungsdatum:
4. April 2014

Beiträge: 419

Ausgehend von dem Thread (https://forum.ubuntuusers.de/topic/script-soll-erst-nach-schliessung-von-aufgeruf/) besteht vllt noch Interesse des Ein oder Anderen an einem Mountscript zur Verwaltung versch. LUKS Containerdateien. Ein lauffähiges Script habe ich bereits , fertig ist es noch nicht.

für Tipps und Tricks wäre ich dankbar 😉

  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
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#
# name          : mount-crypt-con.sh
# desciption    : mount shortcut for LUKS container
# autor         : itoss
# licence       : (CC) BY-NC-SA
# version	: 1.1
# infosource	: https://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger#Abschneiden-von-Mustern and various
#
# dependencies	: cryptsetup awk sed pcmanfm gnome-commander midnight-commander

########################
### define variables ###
########################

containerfile=$(echo $2|awk -F/ '{print $NF}')						# Filename extracted from complete input
containerfilepath=$(echo $2 | sed s/"$containerfile"//g 2>/dev/null) 			# Pathname extracted from complete input
containerfilesystem=ext4
mountpoint=/mnt/crypt-con/$(echo $containerfile)					# Call Containerfile <NAME>.<extention> e.g. backup.crypt
loopdevice=$(sudo losetup -f)
filemanager=${3:--f1}
color1=1
REDBAR="$(tput setaf $color1)|$(tput sgr0)"

# TD => auflistung verfügbarer container in containerverzeichnis
# TD => ssh / sshfs funktion implementieren // ssh abfrage remote verzeichnis sshfs remote container mount

########################
### define functions ###
########################
#-----------------------------------------------------------------------------------------------------------
function usage()
{
echo $(tput setaf $color1)+------------------------------------------------------------------------------------+$(tput sgr0)
echo "$REDBAR $(basename $0) [-option] [/path/to/file.crypt] [-filemanager] 		     $REDBAR"
echo "$REDBAR 										     $REDBAR"
echo "$REDBAR available options: -a  => auto ( mount / open filemanager / unmount )		     $REDBAR"
echo "$REDBAR 		     -m  => mount				     		     $REDBAR"
echo "$REDBAR 		     -u  => unmount				     		     $REDBAR"
echo "$REDBAR 		     -c  => create containerfile		     		     $REDBAR"
echo "$REDBAR 		     -s  => export LUKS header to file		     		     $REDBAR"
echo "$REDBAR 		     -p  => change / add container password 	     		     $REDBAR"
echo "$REDBAR 										     $REDBAR"
echo "$REDBAR Filemanager        -f1 => pcmanfm	       ( xserver ) default    		     $REDBAR"
echo "$REDBAR 		     -f2 => gnome commander    ( xserver )	 	             $REDBAR"
echo "$REDBAR 		     -f3 => midnight commander ( ncurses )	     		     $REDBAR"
echo "$REDBAR 										     $REDBAR"
echo $(tput setaf $color1)+------------------------------------------------------------------------------------+$(tput sgr0)
sudo rmdir -p $mountpoint 2>/dev/null									# remove mountpoint
exit
}
#-----------------------------------------------------------------------------------------------------------
function showparameter()
{
echo ""													# list parameter while passphase input
echo $(tput setaf $color1)+------------------------------------------------------------------------------------+$(tput sgr0)
echo "$REDBAR"
echo "$REDBAR containerfile		=> $containerfile"
echo "$REDBAR containerfilepath	=> ${containerfilepath:-$(eval pwd)}"
echo "$REDBAR mountpoint		=> $mountpoint"
echo "$REDBAR containerfilesystem 	=> $containerfilesystem"
echo "$REDBAR"
echo $(tput setaf $color1)+------------------------------------------------------------------------------------+$(tput sgr0)
}
#-----------------------------------------------------------------------------------------------------------
function mount_luks_container()
{
showparameter												# show parameter while passphase input
echo -e "\nstarting mount process ... \n"
sudo losetup $loopdevice $containerfilepath$containerfile						# mount loopdevice
sudo cryptsetup luksOpen $loopdevice $containerfile							# open luks encrypted container
sudo mount -t ext4 /dev/mapper/$containerfile $mountpoint						# mount filesystem
echo -e "\nloopdevice mounted => $(sudo losetup -a)"							# show used loop device
echo -e "filesysstem mounted => $(mount -l |  grep $containerfile | cut -d : -f2)\n"			# show mounted filesystem
}
#-----------------------------------------------------------------------------------------------------------
function umount_luks_container()
{
echo -e "\nstarting unmount process ... \n"
sudo umount $mountpoint											# umount filesystem
sudo cryptsetup luksClose $containerfile								# close luks encrypted container
sudo losetup -d $(sudo losetup -a | grep $containerfile | cut -d : -f1)					# unmount loopdevice
echo -e "\nloopdevice mounted => $(sudo losetup -a)"							# show used loop device
echo -e "filesysstem mounted => $(mount -l |  grep $containerfile | cut -d : -f2)\n"			# show mounted filesystem
sudo rmdir -p $mountpoint 2>/dev/null									# remove mountpoint
}
#-----------------------------------------------------------------------------------------------------------
function auto_mount ()
{
mount_luks_container
echo -e "starting filemanager"
case $filemanager in
-f1) pcmanfm $mountpoint 2>/dev/null ;;
-f2) gnome-commander $mountpoint 2>/dev/null ;;
-f3) mc $mountpoint;;
esac
umount_luks_container
}
#------------------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------------------
############################
###     start script     ###
############################
### check if container is allready mounted
## lock containerfile ? write manifestfile to $containerfilepath, check if any container is locked
#------------------------------------------------------------------------------------------------------------



#------------------------------------------------------------------------------------------------------------
## check containerfile access and parameter input							TD => errorlog erstellen
if [[ $1 == "" ]] ;then echo -e "\n $(tput setaf $color1)No option specified $(tput sgr0)\n" && usage ;fi
if [[ $2 == "" ]] ;then echo -e "\n $(tput setaf $color1)No containerfile specified $(tput sgr0)\n" && usage ;fi
if ! test -e  $containerfilepath$containerfile ;then echo -e "\n $(tput setaf $color1)Containerfile does not exist $(tput sgr0)\n" && usage ;fi
case $filemanager in
-f1|-f2|-f3) ;;
	  *) echo -e "$(tput setaf $color1)\n filemanager $filemanager is not available $(tput sgr0)\n" && usage ;;
esac
#------------------------------------------------------------------------------------------------------------
## create mountpoint
sudo mkdir -p $mountpoint
#------------------------------------------------------------------------------------------------------------
# start mount process
case $1 in
 -a)	auto_mount;;
 -m)	mount_luks_container;;
 -u)	umount_luks_container;;
  *)	echo -e "$(tput setaf $color1)\n $1 option is not available $(tput sgr0)\n" && usage ;;
esac
#------------------------------------------------------------------------------------------------------------

rklm Team-Icon

Projektleitung

Anmeldungsdatum:
16. Oktober 2011

Beiträge: 13242

itoss schrieb:

für Tipps und Tricks wäre ich dankbar 😉

Hast Du doch schon bekommen.

itoss

(Themenstarter)
Avatar von itoss

Anmeldungsdatum:
4. April 2014

Beiträge: 419

Jepp danke an dieser stelle nochmal 😉

Ich habe eine neuen Thread aufgemacht, denn hier gehts um das script, nicht nur das "nemo" Problem.

Antworten |