[plug] Self encrypting drives

Brad Campbell brad at fnarfbargle.com
Wed Jan 25 15:27:16 AWST 2017


On 25/01/17 08:52, Brad Campbell wrote:
> On 24/01/17 23:31, David Godfrey wrote:
>> Hi Brad,
>>
>> I believe this didn't go through last time, something about html content.
>> So lets try again
>
> Sorry, yes it did go through and I plonked your snippet into a quick
> test file and ran it up.
>
> root at bkmac:/home/brad# ./test.sh
> root at bkmac:/home/brad#
>
> root at bkmac:/home/brad# bash -x ./test.sh
> + SEDU=/usr/local/bin/sedutil-cli
> + do_start
> + read -t5 Line
> ++ /usr/local/bin/sedutil-cli --scan
> + Dev=
> + [[ '' =~ \\/dev\\/ ]]
> + read -t5 Line
> + Dev=Scanning
> + [[ Scanning =~ \\/dev\\/ ]]
> + read -t5 Line
> + Dev=/dev/sda
> + [[ /dev/sda =~ \\/dev\\/ ]]
> + read -t5 Line
> + Dev=/dev/sdb
> + [[ /dev/sdb =~ \\/dev\\/ ]]
> + read -t5 Line
> + Dev=/dev/sdc
> + [[ /dev/sdc =~ \\/dev\\/ ]]
> + read -t5 Line
> + Dev=/dev/sdd
> + [[ /dev/sdd =~ \\/dev\\/ ]]
> + read -t5 Line
> + Dev=No
> + [[ No =~ \\/dev\\/ ]]
> + read -t5 Line
>
> I haven't had time to dig into it to see why it doesn't work though.
>

Right. Now I have.

It wasn't matching the regex on /dev/ due to single quotes around it. 
Don't ask me, I've never used bash for regex before, but removing the 
quotes fixed it.

It also wasn't printing the drive was already unlocked as $wasLocked 
needed negation in the test. Now it works.

Thanks for the lesson in bash. Several tips in there that are guarantee 
to be useful!

do_start () {
     while read -t5 Line; do
         Dev=${Line%% *}
         if [[ $Dev =~ \/dev\/ ]] ; then <--- removed single quotes
             wasLocked=false
             while read -t5 qLine; do
                 if [[ $qLine =~ 'Locked = Y' ]] ; then
                     echo "$Dev Locked"
                     if [ -z "$KEY" ] ; then
                         KEY=`get-key-script`
                     fi;
                     $SEDU --setlockingrange 0 rw $KEY $Dev
                     $SEDU --setMBRDone on $KEY $Dev
                     /sbin/blockdev --rereadpt $Dev
                     wasLocked=true;
                 fi
             done < <($SEDU --query $Dev)
             if ! $wasLocked; then <--- NOT waslocked
                 echo "$Dev Already Unlocked"
             fi;
         fi
     done < <( $SEDU --scan )
}

Regards,
Brad


More information about the plug mailing list