LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Simple Dislocker Script (https://www.linuxquestions.org/questions/slackware-14/simple-dislocker-script-4175600139/)

n4rf 02-19-2017 12:28 PM

Simple Dislocker Script
 
Hi, I've been trying to make a simple script to mount Windows® Bitlocker® locked partitions. (Because of my job, I have a few locked drives).
Hence, I ve been trying to make the mounting a bit easier.

I worte a simply (probably not very efficent) script, that once I attach I have to run manually, it has a couple lines and uses Zenity as GUI for passwords and selection.

Dislocker Unlock Script


Code:

#!/bin/bash
#requirementes: dislocker,zenity
DFILE_LOCATION="/tmp/DFILE"
DRIVE_MOUNTPOINT="/mnt/UnlockedDrive"
 
 
if ! type zenity > /dev/null; then
  echo "Please install 'Zenity'";
  exit;
fi
 
 
if ! type dislocker > /dev/null; then
  zenity --error --tittle="Dislocker Not Found" --text="Dislocker has not been found on your system. Please install, and retry."
  exit;
fi
 
#If everythng seems to be OK, continue.
 
SUPASSWORD=$(zenity --password --title="Authenticate" --text="In order to continue, SuperUser Passwrod is required")
 
 
#Check if exists, otherwise create a folder to mount dislocker-image
 
if [ ! -d $DFILE_LOCATION ]; then
  # Control will enter here if $DIRECTORY doesn't exist.
  echo $SUPASSWORD | sudo -S mkdir $DFILE_LOCATION
fi
 
if [ ! -d $DRIVE_MOUNTPOINT ]; then
  # Control will enter here if $DIRECTORY doesn't exist.
  echo $SUPASSWORD | sudo -S mkdir $DRIVE_MOUNTPOINT
fi
 
 
lockedDrive=$(find /dev -mindepth 1 -maxdepth 1  -name "*[sh]d[a-z][0-9]"  | sort | awk '{ printf "FALSE""\0"$0"\0" }' | \
xargs -0 zenity --list --title="Root Partition" --text="Select the locked partition to unlock." \
--radiolist --multiple --column ' ' --column 'Partitions')
 
lockedDrivePSW=$(zenity --password --title="Locked Drive" --text="Please type Locked Drive Password")
 
if [ ! -f "$DFILE_LOCATION"/dislocker-file ]; then
  # Control will enter here if file does not.
  echo $SUPASSWORD | sudo -S dislocker -v -V $lockedDrive  -u$lockedDrivePSW -- $DFILE_LOCATION
  echo $SUPASSWORD | sudo -S mount -o loop $DFILE_LOCATION/dislocker-file $DRIVE_MOUNTPOINT
fi

The script works fine, it gets the job done.

But, Im looking for a way in wich the script will pop when I attach a locked drive.

Is that even possible?? Probably will pop every single time I attach a drive, but since I know it is or it i not locked, I will just cancel and keep going.

Anyways,

I was wondering if there is a way under udev rules to detect a drive has been attached, run the script, and would be a killer if once its detached destroys the dislocker-file.

phenixia2003 02-19-2017 12:44 PM

Hello,

Quote:

Originally Posted by n4rf (Post 5673148)
But, Im looking for a way in wich the script will pop when I attach a locked drive.

Is that even possible?? Probably will pop every single time I attach a drive, but since I know it is or it i not locked, I will just cancel and keep going.

Anyways,

I was wondering if there is a way under udev rules to detect a drive has been attached, run the script, and would be a killer if once its detached destroys the dislocker-file.

I guess this post from Arch forum could help you on this.

--
SeB

Lestrad 10-12-2019 04:59 AM

Question on your script
 
Quote:

Hi, I've been trying to make a simple script to mount Windows® Bitlocker® locked partitions. ...
The script works fine, it gets the job done.

Hi. When I run your script, I get the following error:

Code:

bash: ./dislocker_unlock_script.sh: /bin/bash^M: bad interpreter: No such file or directory
If I run it this way:
Code:

bash dislocker_unlock_script.sh
I get these errors:
Code:

dislocker_unlock_script.sh: line 5: $'\r': command not found
dislocker_unlock_script.sh: line 6: $'\r': command not found
dislocker_unlock_script.sh: line 46: syntax error near unexpected token `fi'
dislocker_unlock_script.sh: line 46: `fi'


Do you have any idea what I'm doing wrong?

TIA
Les

ZhaoLin1457 10-12-2019 07:18 AM

Quote:

Originally Posted by Lestrad (Post 6046232)
Do you have any idea what I'm doing wrong?

Your script file is saved with the Windows style of end of line, which BASH does not like.

You should open it in a editor and save with the UNIX style of end of line.

Lestrad 10-12-2019 08:39 AM

Quote:

Originally Posted by ZhaoLin1457 (Post 6046252)
Your script file is saved with the Windows style of end of line, which BASH does not like.

You should open it in a editor and save with the UNIX style of end of line.

Ah! But in fact I downloaded the script directly from Pastebin by clicking "download." If I copy it and paste it into the xed editor will that work better?

Thanks very much!

PROBLEMCHYLD 10-12-2019 10:01 AM

I use this one with gui.

https://github.com/raryelcostasouza/zDislocker/releases


All times are GMT -5. The time now is 10:49 AM.