#!/bin/sh

DEVICE="$1"

# This script makes sure that the stick is unmounted and unused
# Run this Script before the init process

# make sure to have "/dev/sdb" (not "/dev/sdb1")
#DEVICE="${DEVICE:0:8}" the bash way does not work in dash -.-
DEVICE="$(echo "$DEVICE" | awk '{print substr($1,0,9)}')"

# make sure the device is not mounted
chattr -i "/tmp/usbmount"
umount /tmp/usbmount/*
sleep 1
rmdir /tmp/usbmount/*
umount /media/usb*

# search for already encrypted volumes
device=$(encryptionprovider.py -g)

if [ "$?" = "0" ]
then
	encryptionprovider.py -u $device
fi