Created
June 7, 2012 20:39
-
-
Save menski/2891412 to your computer and use it in GitHub Desktop.
udev truecrypt automount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KERNEL!="sd[c-z]*", GOTO="mounttruecrypt_end" | |
# devices | |
ATTRS{serial}=="5743415A4131373736393036", ENV{dir_name}="ext" | |
ATTRS{serial}=="NA056AG5", KERNEL=="sd?1", ENV{dir_name}="mobile" | |
# mounttruecrypt | |
ACTION=="add", ENV{dir_name}!="", SYMLINK+="%E{dir_name}", RUN+="/usr/sbin/mounttruecrypt -u menski /dev/%E{dir_name}" | |
ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/sbin/mounttruecrypt -u menski /media/%E{dir_name} --remove" | |
# exit | |
LABEL="mounttruecrypt_end" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# automount of the favorite truecrypt-volumes | |
TEXTDOMAIN=mounttruecrypt | |
VERSION="0.1" | |
NAME="mounttruecrypt" | |
USAGE=$"Use \"${NAME} --help\" for more help." | |
# Check if truecrypt is present, install if necessary | |
if [ ! -f /usr/bin/truecrypt ]; then | |
echo $"Unable to find truecrypt, please install." | |
echo "pacman -S truecrypt" | |
exit 1 | |
fi | |
# HELP | |
if [ "$1" == "--help" ]; then | |
echo "${NAME} - Version: ${VERSION}" | |
echo $"Usage:" | |
echo " ${NAME} --help" | |
echo $" ${NAME} -u User Path [--remove]" | |
echo "" | |
echo $" -u User" | |
echo $" User used to mount device." | |
echo "" | |
echo $" Path" | |
echo $" Device path (i.e. \"/dev/Backup\" or \"/dev/sdd1\")" | |
exit 0 | |
fi | |
if [ "$1" != "-u" ]; then | |
echo $"No user given, ${USAGE}" | |
exit 1 | |
fi | |
shift | |
targetuser=$1 | |
if [ -z $targetuser ]; then | |
echo $"No user given, ${USAGE}" | |
exit 1 | |
fi | |
shift | |
dev=$1 | |
if [ -z $dev ]; then | |
echo $"No path given, ${USAGE}" | |
fi | |
shift | |
remove=$1 | |
if [ -z $remove ]; then | |
tmp=`ls -l $dev | awk -F " " '{ print $NF }'` | |
if test -L $dev; then | |
device="/dev/${tmp}" | |
else | |
device=$tmp | |
fi | |
else | |
device=$dev | |
fi | |
if [ -n $device ]; then | |
target=$(echo "${dev}" | awk -F "/" '{ print $NF }') | |
if [ -z $remove ]; then | |
# add | |
if [ $USER != "root" ]; then | |
if test -L $dev; then | |
sudo mkdir -p /media/${target} | |
sudo chmod go+w /media/${target}/ | |
/usr/bin/truecrypt ${device} /media/${target} | |
else | |
/usr/bin/truecrypt ${device} | |
fi | |
else | |
set -x | |
export DISPLAY=:0.0 | |
xhost local:${targetuser} | |
if test -L $dev; then | |
mkdir -p /media/${target} | |
chmod go+w /media/${target}/ | |
su ${targetuser} -c "/usr/bin/truecrypt ${device} /media/${target}" | |
else | |
su ${targetuser} -c "/usr/bin/truecrypt ${device}" | |
fi | |
fi | |
else | |
# remove | |
if [ $USER != "root"]; then | |
if [ -d $device ]; then | |
/usr/bin/truecrypt -t -d $device | |
sudo rmdir $device | |
fi | |
else | |
if [ -d $device ]; then | |
set -x | |
export DISPLAY=:0.0 | |
xhost local:${targetuser} | |
su ${targetuser} -c "/usr/bin/truecrypt -t -d ${device}" | |
rmdir $device | |
fi | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment