usbmount/mount.d/00_create_model_symlink
author ft
Tue, 04 Nov 2014 14:58:00 +0100
changeset 2 ee0797f46473
parent 0 60bc07f3f415
permissions -rwxr-xr-x
changed some things
ft@0
     1
#!/bin/sh
ft@0
     2
# This script creates the model name symlink in /var/run/usbmount.
ft@0
     3
# Copyright (C) 2005 Martin Dickopp
ft@0
     4
#
ft@0
     5
# This file is free software; the copyright holder gives unlimited
ft@0
     6
# permission to copy and/or distribute it, with or without
ft@0
     7
# modifications, as long as this notice is preserved.
ft@0
     8
#
ft@0
     9
# This file is distributed in the hope that it will be useful,
ft@0
    10
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
ft@0
    11
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
ft@0
    12
# PARTICULAR PURPOSE.
ft@0
    13
#
ft@0
    14
set -e
ft@0
    15
ft@2
    16
log()
ft@2
    17
{
ft@2
    18
	if [ $1 != debug ] || expr "$VERBOSE" : "[yY]" > /dev/null; then
ft@2
    19
		logger -p user.$1 -t "usbmount[$$]" -- "$2"
ft@2
    20
	fi
ft@2
    21
}
ft@2
    22
ft@2
    23
getRemoteIp ()
ft@2
    24
{
ft@2
    25
	ip_address=$(ifconfig eth0 | grep "inet " | awk '{ print $2 }' | cut -d ":" -f 2)
ft@2
    26
	ip_netmask=$(ifconfig eth0 | grep "inet " | awk '{ print $4 }' | cut -d ":" -f 2)
ft@2
    27
	remote_ip=$(ipcalc $ip_address/$ip_netmask | grep HostMin | awk '{ print $2}')
ft@2
    28
ft@2
    29
	echo $remote_ip
ft@2
    30
}
ft@2
    31
ft@2
    32
ft@0
    33
# Replace spaces with underscores, remove special characters in vendor
ft@0
    34
# and model name.
ft@0
    35
UM_VENDOR=`echo "$UM_VENDOR" | sed 's/ /_/g; s/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-]//g'`
ft@0
    36
UM_MODEL=`echo "$UM_MODEL" | sed 's/ /_/g; s/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-]//g'`
ft@0
    37
ft@0
    38
# Exit if both vendor and model name are empty.
ft@0
    39
test -n "$UM_VENDOR" || test -n "$UM_MODEL" || exit 0
ft@0
    40
ft@0
    41
# Build symlink name.
ft@0
    42
if test -n "$UM_VENDOR" && test -n "$UM_MODEL"; then
ft@0
    43
    name="${UM_VENDOR}_$UM_MODEL"
ft@0
    44
else
ft@0
    45
    name="$UM_VENDOR$UM_MODEL"
ft@0
    46
fi
ft@0
    47
ft@0
    48
# Append partition number, if any, to the symlink name.
ft@0
    49
partition=`echo "$UM_DEVICE" | sed 's/^.*[^0123456789]\([0123456789]*\)/\1/'`
ft@0
    50
if test -n "$partition"; then
ft@0
    51
    name="${name}_$partition"
ft@0
    52
fi
ft@0
    53
ft@2
    54
set +e
ft@2
    55
#if [ -f "/media/usb0/opensecurity.tc" ]
ft@2
    56
#then
ft@2
    57
#	log info "Found Truecrypt file on Stick. Try to mount"
ft@2
    58
#	wget -q -T 3 -t 1 -O /dev/null http://$(getRemoteIp):8090/password?text=Please+enter+the+password
ft@2
    59
#	if [ "$?" != "0" ]
ft@2
    60
#	then
ft@2
    61
#		log err "ERROR: Connection to http://$(getRemoteIp):8090/password?text=Please+enter+the+password failed"
ft@2
    62
#		exit 1
ft@2
    63
#	fi
ft@2
    64
#
ft@2
    65
#	log info "Password notification sended, wait for response"
ft@2
    66
#	mkdir -p "/media/encrypted"
ft@2
    67
#	/usr/bin/encryptionprovider.py -m eth0 58080 /media/usb0/opensecurity.tc /media/encrypted
ft@2
    68
#	if [ "$?" != "0" ]
ft@2
    69
#	then
ft@2
    70
#		log err "Stick removed. exit"
ft@2
    71
#		exit 1
ft@2
    72
#	fi
ft@2
    73
#	mkdir -p "/var/run/usbmount/encrypted"
ft@2
    74
#	/usr/bin/osecfs /etc/osecfs/osecfs_usb.cfg "/var/run/usbmount/encrypted" rw
ft@2
    75
#	log info "Encrypted stick mounted"
ft@2
    76
#else
ft@2
    77
#	mkdir -p "/var/run/usbmount/$name"
ft@2
    78
	chattr -i "/tmp/usbmount"
ft@2
    79
	mkdir -p "/tmp/usbmount/$name"
ft@2
    80
	osecfs /etc/osecfs/osecfs_usb.cfg /tmp/usbmount/$name ro
ft@2
    81
	encryptionprovider.py -i eth0 58081 "$UM_DEVICE" /media/usb0 &
ft@2
    82
	chattr +i "/tmp/usbmount"
ft@2
    83
	#run_initlistener.sh $UM_DEVICE &
ft@2
    84
#fi
ft@0
    85
ft@0
    86
ft@0
    87
exit 0