URI: 
       tnew key on usb usb key detection tested on ubuntu 10.04 - tomb - the crypto undertaker
  HTML git clone git://parazyd.org/tomb.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit f39b6e5cf7f0796a14f953e73cf8cb42b4772e84
   DIR parent cd9b16667bc72d4666e3b44b3ea0f25aed89f87d
  HTML Author: Jaromil <jaromil@dyne.org>
       Date:   Mon, 10 Jan 2011 20:41:28 +0100
       
       new key on usb
       usb key detection tested on ubuntu 10.04
       
       Diffstat:
         M src/tomb                            |      66 +++++++++++++++++++++++++++++--
       
       1 file changed, 62 insertions(+), 4 deletions(-)
       ---
   DIR diff --git a/src/tomb b/src/tomb
       t@@ -47,6 +47,60 @@ else
            DD=dd
        fi
        
       +# usb auto detect
       +# tested on ubuntu 10.04 - please test and patch on other systems if you can
       +ask_usbkey() {
       +    echo "looking for key $1 on usb"
       +    echo -n "please insert your usb key "
       +
       +    plugged=false
       +    while [ "$plugged" != "true" ]; do
       +        dmesg | tail -n 12 | grep -q 'new.*USB device'
       +        if [ $? = 0 ]; then plugged=true; fi
       +        echo -n "."
       +        sleep .5
       +    done
       +
       +    echo
       +    echo -n "usb key inserted, attaching "
       +    
       +    attached=false
       +    while [ "$attached" != "true" ]; do
       +        dmesg | tail -n 3| grep -q 'Attached.*removable disk'
       +        if [ $? = 0 ]; then attached=true; fi
       +        echo -n "."
       +        sleep  .5
       +    done
       +
       +    # get the first partition
       +    usbpart=`dmesg |tail -n 4 |awk '/  sd.:/ { print $3 }'`
       +
       +    echo
       +    echo -n "usb key attached, mounting "
       +    # what that it is mounted
       +    mounted=false
       +    while [ "$mounted" != "true" ]; do
       +        cat /proc/mounts | tail -n2 | grep -q "^/dev/$usbpart"
       +        if [ $? = 0 ]; then mounted=true; fi
       +        echo -n "."
       +        sleep .5
       +    done
       +
       +    # check where it is mounted
       +    usbmount=`cat /proc/mounts | awk -v p=$usbpart '{ if( $1 == "/dev/" p) print $2 }'`
       +    echo
       +    echo "usb key mounted on $usbmount"
       +    # check if the key is there
       +    if [ -r ${usbmount}/$1 ]; then
       +        echo "key found!"
       +        export enc_key="${usbmount}/${1}"
       +        return 0
       +    else
       +        echo "key not found on usb"
       +    fi
       +    return 1
       +}
       +
        # user interface (just to ask the password)
        ask_password() {
        
       t@@ -270,11 +324,15 @@ mount_tomb() {
                
                # check if key file is present
                if ! [ -r "${enc_key}" ]; then
       -            error "encryption key ${enc_key} not found"
       +            error "encryption key ${enc_key} not found on disk"
                    error "use -k option to specify which key to use"
       -            losetup -d ${nstloop}
       -            sleep 5
       -            return
       +            error "or provide a usb key, or press ctrl-c to abort"
       +            ask_usbkey ".tomb/$enc_key"
       +            if ! [ -r "${enc_key}" ]; then
       +                losetup -d ${nstloop}
       +                sleep 5
       +                return
       +            fi
                fi
                
                modprobe dm-crypt