From: Andrew Sichevoi Date: Tue, 1 May 2012 10:48:49 +0000 (+0400) Subject: Initial version X-Git-Tag: v0.1~2 X-Git-Url: http://git.thekondor.net/?p=truecrypt-extra.git;a=commitdiff_plain;h=a40539a6799cbf5fff83b79d477b9a4445267f16 Initial version --- a40539a6799cbf5fff83b79d477b9a4445267f16 diff --git a/etc.default.truecrypt b/etc.default.truecrypt new file mode 100644 index 0000000..bb56fe8 --- /dev/null +++ b/etc.default.truecrypt @@ -0,0 +1,35 @@ +### TrueCrypt Extra root configuration +### This file is a part of `truecrypt-extra` +### +### (c) Andrew Sichevoi, http://thekondor.net +### Distributed in the terms of GNU GPL v3.0+ license +### +### The latest version is available on http://git.thekondor.net + +### application: [common] +### description: specifies a path to TrueCrypt binary +### default : /usr/bin/truecrypt +TRUECRYPT_BINARY=/usr/bin/truecrypt + +### application: truecrypt-mount +### description: specifies user's root directory where all TC's volumes to are mounted in +### %username% is substituted with a name of the user +### default : /home/%username%/.mount/encrypted +USER_MOUNT_ROOT=/home/%username%/.mount/encrypted + +### application: truecrypt-mount +### description: specifies should be a newly mounted TC's volume immediately shown +### in the File Browser or not. +### default : true +EXPLORE_MOUNTED_VOLUME=true + +### application: truecrypt-mount +### description: specifies the way errors are reported while mounting TC's volumes. +### %error% is substituted with the real error message +### default : to the console, throuh /bin/echo +ERROR_REPORTING_CHANNEL='/usr/bin/zenity --error --no-markup --title=TrueCrypt --text="%error%"' + +### Alternative ways: +### ERROR_REPORTING_CHANNEL='/bin/echo %error%' +### ERROR_REPORTING_CHANNEL='/usr/bin/notify-send --app-name=TrueCrypt --icon=error "TrueCrypt mount error" "%error%"' + diff --git a/usr.bin.truecrypt-mount b/usr.bin.truecrypt-mount new file mode 100755 index 0000000..85fd468 --- /dev/null +++ b/usr.bin.truecrypt-mount @@ -0,0 +1,137 @@ +#!/bin/sh + +### TrueCrypt Mount wrapper +### This file is a part of `truecrypt-extra` +### +### (c) Andrew Sichevoi, http://thekondor.net +### Distributed in the terms of GNU GPL v3.0+ license +### +### The latest version is available on http://git.thekondor.net + +if [ -f /etc/default/truecrypt ]; then + . /etc/default/truecrypt +fi + +run_textual_truecrypt() +{ + ${TRUECRYPT_BINARY} --text --non-interactive $@ 2>/dev/null +} + +run_regular_truecrypt() +{ + ${TRUECRYPT_BINARY} $@ +} + +setup_defaults_if_not_available() +{ + DEFAULT_USER_MOUNT_ROOT=/home/%username%/.mount/encrypted + + if [ -z "${USER_MOUNT_ROOT}" ]; then + USER_MOUNT_ROOT=${DEFAULT_USER_MOUNT_ROOT} + fi + + DEFAULT_TRUECRYPT_BINARY=/usr/bin/truecrypt + if [ -z "${TRUECRYPT_BINARY}" ]; then + TRUECRYPT_BINARY=${DEFAULT_TRUECRYPT_BINARY} + fi + + DEFAULT_EXPLORE_MOUNTED_VOLUME=true + if [ -z "${EXPLORE_MOUNTED_VOLUME}" ]; then + EXPLORE_MOUNTED_VOLUME=${DEFAULT_EXPLORE_MOUNTED_VOLUME} + fi + + DEFAULT_ERROR_REPORTING_CHANNEL='/bin/echo %error%' + if [ -z "${ERROR_REPORTING_CHANNEL}" ]; then + ERROR_REPORTING_CHANNEL=${DEFAULT_ERROR_REPORTING_CHANNEL} + fi +} + +check_if_mount_point_already_used() +{ + _MOUNT_POINT_DIR=$1 + _IS_LISTED_IN_TRUECRYPT=$(run_textual_truecrypt --list | grep "${_MOUNT_POINT_DIR}" -c) + if [ 0 -eq $? -a ! 0 -eq ${_IS_LISTED_IN_TRUECRYPT} ]; then + raise_error "Error: mount point '${_MOUNT_POINT_DIR}' is already used by truecrypt. It cannot be used right now." + fi +} + +check_if_truecrypt_available() +{ + if [ ! -x "${TRUECRYPT_BINARY}" ]; then + raise_error "Error: Truecrypt (${TRUECRYPT_BINARY}) is not available" + fi +} + +raise_error() +{ + _ERROR_MESSAGE=$(/bin/echo -n "$@" | sed -e 's/\\/\\\\/g' | sed -e "s/\//::/g" | tr \" \') + _ERROR_CMD=$(/bin/echo ${ERROR_REPORTING_CHANNEL} | sed -e "s/%error%/${_ERROR_MESSAGE}/g") + eval "${_ERROR_CMD}" + exit 1 +} + +check_passed_arguments() +{ + if [ 1 != $# ]; then + raise_error "Usage: ${0} " + fi +} + +escape_mount_dir_name() +{ + /bin/echo $@ | /usr/bin/tr "[:cntrl:][:space:][:punct:]" "_" +} + +generate_mount_point_dir_name() +{ + escape_mount_dir_name $1 +} + +generate_mount_point() +{ + _MOUNT_POINT_DIR=$(/bin/echo ${USER_MOUNT_ROOT}/$(generate_mount_point_dir_name $1)) + _USERNAME_VAR=$(whoami) + _MOUNT_POINT_DIR=$(/bin/echo ${_MOUNT_POINT_DIR} | /bin/sed -e s/%username%/${_USERNAME_VAR}/g) + + /bin/echo ${_MOUNT_POINT_DIR} +} + +create_mount_point() +{ + _MOUNT_POINT_DIR=$1 + if [ ! -d "${_MOUNT_POINT_DIR}" ]; then + /bin/mkdir -p ${_MOUNT_POINT_DIR} + if [ ! 0 -eq $? ]; then + raise_error "Error: failed to create ${_MOUNT_POINT_DIR}" + fi + fi +} + +explore_mount_point() +{ + if [ ${EXPLORE_MOUNTED_VOLUME} ]; then + _MOUNT_POINT_DIR=${1} + /usr/bin/xdg-open ${_MOUNT_POINT_DIR} + fi +} + +mount_tc_volume() +{ + _TC_VOLUME=${1} + _MOUNT_POINT_DIR=$(generate_mount_point ${_TC_VOLUME}) + + check_if_mount_point_already_used ${_MOUNT_POINT_DIR} + create_mount_point ${_MOUNT_POINT_DIR} + + run_regular_truecrypt ${_TC_VOLUME} ${_MOUNT_POINT_DIR} + if [ ! 0 -eq $? ]; then + raise_error "Error: truecrypt execution error, code = ${?}" + fi + + explore_mount_point ${_MOUNT_POINT_DIR} +} + + +check_passed_arguments $@ +setup_defaults_if_not_available +mount_tc_volume $1