maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   General (https://talk.maemo.org/forumdisplay.php?f=7)
-   -   TrueCrypt Mounter/Unmounter Script (Help Needed) (https://talk.maemo.org/showthread.php?t=66555)

fareed_xtreme 2010-12-04 16:52

TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Dear All,
I am quite a noob when it comes to Linux. I used to write advanced scripts in Windows Powershell and now I want to do the same in Linux.

The following is a script I wrote but I have no clue on how to make it executable and how can i make an icon for it to launch a script. If someone would be kind to pass a few links, will be helpful for me.

I tried to run this in my N900 and it kinda screwed up the device as I am sure i did somethin wrong. had to reflash it. So would be really honoured if omeone could help a lil so tht I can do my contribution to this forum as well.

Code:

#!/bin/bash
echo **********************************************
echo *          TrueCrypt Assistant              *
echo **********************************************
echo
choice=3
echo Please choose the approriate task.
Echo  1. Mount Crypt Drive.
Echo  2. Unmount all Drives.
while [$choice -eq 3 ]; do
read choice
if [$choice -eq 1 ] ; then
echo Mounting Crypt Drive. you may be asked for authorization password.
truecrypt -k "" --protect-hidden=no /media/mmc1/TrueCrypt /media/Crypt
tracker-processes -r
exit
else
if [$choice -eq 2 ] ; then
echo Unmounting all Crypt Drives.
truecrypt -d
tracker-processes -r
exit
else
echo Please choose either "1" or "2".
fi
fi
done

Does Linux Scripts support GOTO and Labels? Also I had referred a few sites over google to come up with this.. Hope someone helps with corrections.

j.s 2010-12-04 18:17

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by fareed_xtreme (Post 889207)
The following is a script I wrote but I have no clue on how to make it executable and how can i make an icon for it to launch a script. If someone would be kind to pass a few links, will be helpful for me.

Code:

chmod +x filename
makes a file executable. The file system needs to be mounted with the exec option. The Mydocs partition is mounted noexec by default, so your script should be stored someplace else if it is on Mydocs.
Quote:

Originally Posted by fareed_xtreme (Post 889207)
Does Linux Scripts support GOTO and Labels? Also I had referred a few sites over google to come up with this.. Hope someone helps with corrections.

For elaborate logic flow, you might want to consider perl or python. perl can invoke OS commands with
Code:

system "command options arguments";
or
Code:

`command options arguments`;

fareed_xtreme 2010-12-04 19:03

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by j.s (Post 889263)
Code:

chmod +x filename
makes a file executable. The file system needs to be mounted with the exec option. The Mydocs partition is mounted noexec by default, so your script should be stored someplace else if it is on Mydocs.


For elaborate logic flow, you might want to consider perl or python. perl can invoke OS commands with
Code:

system "command options arguments";
or
Code:

`command options arguments`;

Thanks a lot for your assistance on this. I wil try it out in a few minutes and hope I can get it to work.

mooglez 2010-12-04 20:28

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by fareed_xtreme (Post 889283)
Thanks a lot for your assistance on this. I wil try it out in a few minutes and hope I can get it to work.

If you do get it working, would you mind posting your final script here for the general public, as this could be something that would make Truecrypt usage a lot easier for the general N900 user base?

fareed_xtreme 2010-12-05 10:24

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by mooglez (Post 889333)
If you do get it working, would you mind posting your final script here for the general public, as this could be something that would make Truecrypt usage a lot easier for the general N900 user base?

Well I have been waiting for someone to create some script for a long time as typing each time was a headache for me. lol. Then I realised why not give it a try. Well lets see how it turns out.

Saturn 2010-12-05 11:22

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Hi fareed_xtreme,

Here some example code that might be useful to you.

To make a selection menu:

Code:

#!/bin/sh

selection=
until [ "$selection" = "0" ]; do
    echo ""
    echo "MENU"
    echo "1 - first command"
    echo "2 - second command"
    echo "3 - third command"
    echo ""
    echo "0 - exit program"
    echo ""
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
        0) exit ;;
        1) cd /home/user/;;
        2) ls -al;;
        3) ssh user@192.168.0.3;;
        *) echo "Please enter 1, 2, or 0"
    esac
done


The .desktop file should be put here:
Code:

/usr/share/applications/hildon/myScript.desktop
and the contents should look like this:
Code:

[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Terminal=true
Name=myScript
Exec=/usr/bin/osso-xterm "/home/user/myscripts/myScript.sh"
Icon=terminal
X-Osso-Type=application/x-executable

Good luck.

fareed_xtreme 2010-12-05 18:30

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by Saturn (Post 889663)
Hi fareed_xtreme,

Here some example code that might be useful to you.

To make a selection menu:

Code:

#!/bin/sh

selection=
until [ "$selection" = "0" ]; do
    echo ""
    echo "MENU"
    echo "1 - first command"
    echo "2 - second command"
    echo "3 - third command"
    echo ""
    echo "0 - exit program"
    echo ""
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
        0) exit ;;
        1) cd /home/user/;;
        2) ls -al;;
        3) ssh user@192.168.0.3;;
        *) echo "Please enter 1, 2, or 0"
    esac
done


The .desktop file should be put here:
Code:

/usr/share/applications/hildon/myScript.desktop
and the contents should look like this:
Code:

[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Terminal=true
Name=myScript
Exec=/usr/bin/osso-xterm "/home/user/myscripts/myScript.sh"
Icon=terminal
X-Osso-Type=application/x-executable

Good luck.

Just the thing I was searching for. Now Iet me get my lazy *** to work. :P maybe in a week or so ill try to get something ready :P

fareed_xtreme 2010-12-07 07:42

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
I noticed something Wierd. As I am running the script, the i get the following error

Code:

permission denied.
I have already run the following command as root as well as user.

Code:

chmod +x Filename.sh
Just as a trial I also ran

Code:

chmod 777 filename.sh
No errors while running these commands but on running script, it says permission denied.

Also the desktop file I had created had some problem and so i deleted it but in the menu, the icon still exists. What am i doing wrong here? How can I remove the icon and all?

Saturn 2010-12-07 08:10

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Maybe the permision denied comes from what you executed inside the script?
Can the commands you've put in the script be executed as user?

Use "ls -al" to view what priviledges you have set to a file.
Make a reboot and see if it is rmoved from the menu.

fareed_xtreme 2010-12-07 13:33

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by Saturn (Post 891272)
Maybe the permision denied comes from what you executed inside the script?
Can the commands you've put in the script be executed as user?

Use "ls -al" to view what priviledges you have set to a file.
Make a reboot and see if it is rmoved from the menu.

I have done the above. The functions inside the script are all executable as a user. i have done a full walkthrough of the script before i started the actual coding process. I just checked them all again and they work just fine if individual commands are given.

Secondly I rebooted 2 times already and still the icon still exists... I do not know what is the issue regarding. and really wish that you could assist me in cleaning this up without the need to format...

Saturn 2010-12-07 13:54

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by fareed_xtreme (Post 891444)
I have done the above. The functions inside the script are all executable as a user. i have done a full walkthrough of the script before i started the actual coding process. I just checked them all again and they work just fine if individual commands are given.

Secondly I rebooted 2 times already and still the icon still exists... I do not know what is the issue regarding. and really wish that you could assist me in cleaning this up without the need to format...

Well without the actual code, I'm just guessing..

as root you can use the find command to search for your scripts maybe you left something back there. eg:
Code:

find / -name *partOfTheScriptName*
Other common mistake is the:
case $selection in
0) exit ;;
notice the double semicolon

sacal 2010-12-07 15:34

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
This is what i did in my device to manage mounting and unmounting a "cryptedfile.tc" located in my SD card:

1 - Create the "cryptedfile.tc" and move it to your SD card (it may also be MyDocs or other folder)

2 - Install Truecrypt Disk Encryption (command line) from the repos

3 - Create the empty folder /media/mycrypt

4 - Create the following script in /usr/bin:

Code:

/usr/bin/truecrypt --protect-hidden=no -k= /media/mmc1/cryptedfile.tc /media/mycrypt
ossofilemanager
/usr/bin/truecrypt --dismount /media/mycrypt

(replace /media/mmc1/cryptedfile.tc if the location off the crypted file is different)

5 - Create the file tcrypt.desktop in /usr/share/applications/hildon with the following contents:

Code:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Tcrypt
GenericName=Tcrypt access
Comment=Access tcrypt
Exec=osso-xterm "/usr/bin/tcrypt"
Icon=tcrypt
X-Osso-Type=application/x-executable
X-HildonDesk-ShowInToolbar=true
Terminal=true
Type=Application
StartupNotify=true
Categories=ConsoleOnly;System;

6 - Create a 48x48 png icon named tcrypt.png and move it to /home/usr/share/icons/hicolor/scalable/hildon.
I used the easycrypt icon

Whenever i need to use the crypt file i go to the applications menu and i select the truecrytp icon.
When x-terminal opens i input the crypt password and then filemanager opens with mycrypt mounted and ready for use.
As long as i keep filemanager running mycrypt remains mounted.
As soon as i close filemanger mycrypt folder is automatically unmounted.

fareed_xtreme 2010-12-07 15:36

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
1 Attachment(s)
Quote:

Originally Posted by Saturn (Post 891455)
Well without the actual code, I'm just guessing..

as root you can use the find command to search for your scripts maybe you left something back there. eg:
Code:

find / -name *partOfTheScriptName*
Other common mistake is the:
case $selection in
0) exit ;;
notice the double semicolon

My bad about the icon... I had pasted the following .desktop file in 2 different locations. I realised after connecting through ssh and got the icon removed now. phew. But the script code, is still drivin me nuts. I am really not getting as to why is it still cranky on the permissions.

fareed_xtreme 2010-12-07 15:41

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by sacal (Post 891519)
This is what i did in my device to manage mounting and unmounting a "cryptedfile.tc" located in my SD card:

1 - Create the "cryptedfile.tc" and move it to your SD card (it may also be MyDocs or other folder)

2 - Install Truecrypt Disk Encryption (command line) from the repos

3 - Create the empty folder /media/mycrypt

4 - Create the following script in /usr/bin:

Code:

/usr/bin/truecrypt --protect-hidden=no -k= /media/mmc1/cryptedfile.tc /media/mycrypt
ossofilemanager
/usr/bin/truecrypt --dismount /media/mycrypt

(replace /media/mmc1/cryptedfile.tc if the location off the crypted file is different)

5 - Create the file tcrypt.desktop in /usr/share/applications/hildon with the following contents:

Code:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Tcrypt
GenericName=Tcrypt access
Comment=Access tcrypt
Exec=osso-xterm "/usr/bin/tcrypt"
Icon=tcrypt
X-Osso-Type=application/x-executable
X-HildonDesk-ShowInToolbar=true
Terminal=true
Type=Application
StartupNotify=true
Categories=ConsoleOnly;System;

6 - Create a 48x48 png icon named tcrypt.png and move it to /home/usr/share/icons/hicolor/scalable/hildon.
I used the easycrypt icon

Whenever i need to use the crypt file i go to the applications menu and i select the truecrytp icon.
When x-terminal opens i input the crypt password and then filemanager opens with mycrypt mounted and ready for use.
As long as i keep filemanager running mycrypt remains mounted.
As soon as i close filemanger mycrypt folder is automatically unmounted.

Now this is what i call scripting..heehee... Awesome man.. but i really gotta get my first script to work so that I can learn more about linux scripting and make my device a powerhouse of scripts :P

BTW,What is a .tc file?Is it a TrueCrypt container file?

sacal 2010-12-07 16:01

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by fareed_xtreme (Post 891526)
..... BTW,What is a .tc file?Is it a TrueCrypt container file?

Yes. It is a 2gb container.
I have the same file in all my windows and linux machines with all the confidential docs and info i may need.
Before N900 i used to carry a pen with the crypted container and a portable app to access it.
I needed to find a pc for that but now, with a computer that makes calls in my pocket, i can do it anywhere. :)

fareed_xtreme 2010-12-07 16:10

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
Quote:

Originally Posted by sacal (Post 891548)
Yes. It is a 2gb container.
I have the same file in all my windows and linux machines with all the confidential docs and info i may need.
Before N900 i used to carry a pen with the crypted container and a portable app to access it.
I needed to find a pc for that but now, with a computer that makes calls in my pocket, i can do it anywhere. :)

I know whatyou mean as I am having a 1GB Container on my MicroSD 8 GB. Just trying to develop a script which i can call as my own personal achievement :P. Well I really would need to add a 7 minute dimount timer or something :P as i tend to beforgetful at times.

fareed_xtreme 2010-12-08 12:38

Re: TrueCrypt Mounter/Unmounter Script (Help Needed)
 
EUREKA. Finally got it working.

Follow this link for the complete setup procedure
http://talk.maemo.org/showthread.php...975#post893975


All times are GMT. The time now is 14:53.

vBulletin® Version 3.8.8