LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-19-2017, 12:28 PM   #1
n4rf
Member
 
Registered: Nov 2013
Location: Córdoba, Argentina
Distribution: Slackware64 14.2
Posts: 36

Rep: Reputation: Disabled
Question 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.
 
Old 02-19-2017, 12:44 PM   #2
phenixia2003
Senior Member
 
Registered: May 2006
Location: France
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
Hello,

Quote:
Originally Posted by n4rf View Post
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
 
Old 10-12-2019, 04:59 AM   #3
Lestrad
Member
 
Registered: Mar 2015
Posts: 43

Rep: Reputation: Disabled
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

Last edited by Lestrad; 10-12-2019 at 05:09 AM.
 
Old 10-12-2019, 07:18 AM   #4
ZhaoLin1457
Member
 
Registered: Jan 2018
Posts: 997

Rep: Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175
Quote:
Originally Posted by Lestrad View Post
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.
 
Old 10-12-2019, 08:39 AM   #5
Lestrad
Member
 
Registered: Mar 2015
Posts: 43

Rep: Reputation: Disabled
Quote:
Originally Posted by ZhaoLin1457 View Post
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!
 
Old 10-12-2019, 10:01 AM   #6
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Rep: Reputation: Disabled
I use this one with gui.

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


Reply

Tags
scripting, slackware 14.2


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Simple script to wait for another script Maverick1182 Linux - Newbie 4 11-05-2007 03:45 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Need help with a simple script shell script WindowBreaker Linux - Software 2 12-15-2005 12:45 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration