usr/share/usbmount/async_usbmount
changeset 2 ee0797f46473
parent 0 60bc07f3f415
     1.1 --- a/usr/share/usbmount/async_usbmount	Thu Feb 27 17:12:59 2014 +0100
     1.2 +++ b/usr/share/usbmount/async_usbmount	Tue Nov 04 14:58:00 2014 +0100
     1.3 @@ -38,6 +38,14 @@
     1.4      return 1
     1.5  }
     1.6  
     1.7 +getRemoteIp ()
     1.8 +{
     1.9 +        ip_address=$(ifconfig eth0 | grep "inet " | awk '{ print $2 }' | cut -d ":" -f 2)
    1.10 +        ip_netmask=$(ifconfig eth0 | grep "inet " | awk '{ print $4 }' | cut -d ":" -f 2)
    1.11 +        remote_ip=$(ipcalc $ip_address/$ip_netmask | grep HostMin | awk '{ print $2}')
    1.12 +
    1.13 +        echo $remote_ip
    1.14 +}
    1.15  
    1.16  ######################################################################
    1.17  # Main program
    1.18 @@ -72,6 +80,11 @@
    1.19      log debug "creating /var/run/usbmount directory"
    1.20  fi
    1.21  
    1.22 +if [ ! -e /tmp/usbmount ]; then
    1.23 +    mkdir -p /tmp/usbmount
    1.24 +    log debug "creating /tmp/usbmount directory"
    1.25 +fi
    1.26 +
    1.27  umask 022
    1.28  
    1.29  if [ "$1" = add ]; then
    1.30 @@ -94,24 +107,29 @@
    1.31      then
    1.32  	log info "blkid -p $DEVNAME has retured with $BLKID_RESULT"
    1.33  	log info "Stick is maybe encrypted. Try decrypt"
    1.34 -	wget -q -T 3 -t 1 -O /dev/null http://192.168.56.1:8090/password?text=Please+send+me+the+password
    1.35 +	wget -q -T 3 -t 1 -O /dev/null http://$(getRemoteIp):8090/password?text=Please+enter+the+password
    1.36  	if [ "$?" != "0" ]
    1.37  	then
    1.38 -		log err "Connection to http://192.168.56.1:8090/password?text=Please+send+me+the+password failed"
    1.39 +		log err "Connection to \"http://$(getRemoteIp):8090/password?text=Please+enter+the+password\" failed"
    1.40  		exit 1
    1.41  	fi
    1.42  	log info "Password notification sended, wait for response"
    1.43  
    1.44 -	/usr/bin/osecvm-password-receiver.py eth0 58080 $DEVNAME /media/usb0
    1.45 +	/usr/bin/encryptionprovider.py -m eth0 58080 $DEVNAME /media/usb0
    1.46  	if [ "$?" != "0" ]
    1.47  	then
    1.48  		log err "Stick removed. exit"
    1.49  		exit 1
    1.50  	fi
    1.51  
    1.52 -	mkdir -p "/var/run/usbmount/encrypted"
    1.53 -	/usr/bin/osecfs /etc/osecfs/osecfs_usb.cfg "/var/run/usbmount/encrypted" rw
    1.54 +	chattr -i "/tmp/usbmount"
    1.55 +	mkdir -p "/tmp/usbmount/encrypted"
    1.56 +	/usr/bin/osecfs /etc/osecfs/osecfs_usb.cfg "/tmp/usbmount/encrypted" rw
    1.57  	log info "Encrypted stick mounted"
    1.58 +
    1.59 +	#run_initlistener.sh $DEVNAME &
    1.60 +	encryptionprovider.py -i eth0 58081 "$DEVNAME" /media/usb0 &
    1.61 +	chattr +i "/tmp/usbmount"
    1.62          exit 0
    1.63      fi
    1.64      set -e
    1.65 @@ -212,15 +230,16 @@
    1.66  
    1.67      # A block or partition device has been removed.
    1.68      # Test if it is mounted.
    1.69 -    for device in $(/usr/bin/truecrypt -l | awk '{ print $2}')
    1.70 +    for device in $(/usr/bin/encryptionprovider.py -g)
    1.71      do
    1.72  	if [ "$DEVNAME" = "$device" ]
    1.73  	then
    1.74 -	    log info "encrypted device was removed"
    1.75 -	    umount "/var/run/usbmount/encrypted"
    1.76 -	    rmdir "/var/run/usbmount/encrypted"
    1.77 -	    log info "/usr/bin/truecrypt -d $DEVNAME"
    1.78 -	    /usr/bin/truecrypt -d "$DEVNAME"
    1.79 +	    log info "umout encrypted device"
    1.80 +	    chattr -i "/tmp/usbmount"
    1.81 +	    umount "/tmp/usbmount/encrypted"
    1.82 +	    rmdir "/tmp/usbmount/encrypted"
    1.83 +	    log info "/usr/bin/encryptionprovider.py -u $DEVNAME"
    1.84 +	    /usr/bin/encryptionprovider.py -u "$DEVNAME"
    1.85  	    log info "everything done"
    1.86  	fi
    1.87      done