maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Can't get script executable (https://talk.maemo.org/showthread.php?t=27733)

Palmleavr 2009-03-21 17:45

Can't get script executable
 
Hi,
I've been trying to write scripts to run the Garnet VM. I've been following the directions from Mara's post on creating executable scripts:

http://www.internettablettalk.com/wi..._using_OS_2008

My problem: after copying the *.sh files over to /home/user/MyDocs, the chmod +x doesn't seem to do anything. I assumed that *.desktop files would be created automatically, but I seem to be mistaken. After I execute "chmod" for each file, there are no visible changes in the /home/user/MyDocs folder.

I typed up the scripts using TextWrangler (a donateware text editor on the Mac that is friendly to programmers). I've started off by creating these scripts to backup, restore and launch the Garnet VM:

To Launch (saved as GLaunch.sh):
Code:

/usr/bin/gvm/gvm -S --rotated=no --fullscreen=no --deviceid=D050 --serialnum XXXXXXXXXXXX-X --hotsyncid=XXX XXX
Note: D050 is the device ID for a Palm TX, the serialnum argument did not list an "=" after the argument in TA-T3's post, so I didn't add one. The serial number is supposed to be 12 digits; I took mine off of my Palm TX (found via FileEZ) which as 12 digits followed by a dash and one letter.

To Backup the gvm.store (saved as GBackup.sh):
Code:

tar cvf /media/mmc2/gvm-backup.tar .gvm
To Restore gvm.store from the backup (saved as GRestore.sh):
Code:

tar xvf /media/mmc2/gvm-backup.tar
I copied these three files to the /home/user/MyDocs folder using emelfm2. Then:

1. I opened XTerm and did "sudo gainroot"
2. I did "cd /home/user/MyDocs"
3. I did "ls" to make sure the script files were present
4. I did "chmod +x *.sh" for each of the script files (where "*" is the name of each of the files
5. I then did "ls" again to see if there were any changes in the directories, but there were none. I even checked to see if there were hidden files (checking the green "H" in emelfm2).

I started to manually create *.desktop files for these scripts, but I realized that I didn't know the syntax for such files. I've taken the following example from one of burmashave's posts. For someone who is more experienced, will this do?

Code:

[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Script
Name=GLaunch
Exec=/home/user/MyDocs/GLaunch.sh
Comment=to launch GVM using set parameters

So, can someone help me figure out:
1. Why the chmod command doesn't seem to be working for me
2. Can I just create *.desktop files manually as above and transfer these to /usr/share/applications/hildon and have the executable show up in "Extras"?
3. If the *.desktop file looks okay, will it then execute my chmod'd *.sh files as they are now?

Thanks!

By the way, I'm running Diablo on an n810.

Update:
Well, I went ahead and double-checked the form for a *.desktop file on the wiki and wrote one in TextWrangler and copied it over to /usr/shared/applications/hildon. Sure enough, it showed up in Extras, but, when I clicked on it, nothing happened. Here is the code I used for the GLaunch.desktop file:

[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Name=GLaunch
Exec=/home/user/MyDocs/GLaunch.sh
X-Osso-Type=application/x-executable
Comment=to launch GVM using set parameters

qwerty12 2009-03-21 17:47

Re: Can't get script executable
 
Code:

Type=Script
should be Type=Application

And add "#!/bin/sh" (w/out quotes) to the top of your scripts.

Palmleavr 2009-03-22 02:48

Re: Can't get script executable
 
Thanks qwerty12 (Faheem),
However, I tried your suggestion, and chmod still doesn't work for me.

I opened my *.sh files using Leafpad on the n810 and added the line you suggested: #!/bin/sh

I then did a "Save As..." for each file using Leafpad then copied the files into the /home/user/MyDocs folder as above. After that, when I did "chmod +x *.sh" for each of the files, nothing happened. I tried installing my GLaunch.desktop file (using Type=Application) into /usr/share/applications/hildon--but, when I tapped the icon in Extras, there was no response, not even an error message.

I appreciate any help!

Palmleavr 2009-03-22 03:11

Re: Can't get script executable
 
Update: well here's something bizarre.
I decided that the problem, perhaps, was in the GLaunch.sh script, so I typed up a GBackup.desktop file and copied that into the ~/hildon folder. When I executed the GBackup from Extras, I got a gvm-backup.tar file that was only 10 kb in size.

I then deleted that file and executed the command directly in XTerm:
tar cvf /media/mmc2/gvm-backup.tar .gvm

After that, I got a gvm-backup.tar file that was 576 mb in size (the command also backed up my eight alternate gvm.store files).

Now this script and *.desktop file thing has got me really confused!

slvr32 2009-03-22 03:55

Re: Can't get script executable
 
You probably want to make the script run in a subshell, and take advantage of your environment to make sure you're sitting in the appropriate directory...

for example...

Code:

#!/bin/sh

dest=/media/mmc2/gvm-backup.tar

(
    cd $HOME
    tar cvf $dest .gvm
)


and...

Code:

#!/bin/sh

src=/media/mmc2/gvm-backup.tar

(
    cd $HOME
    if [ -f $src ]; then
        tar xvf $src
    else
        echo "$src doesn't exist"
    fi
)

Also, 'ls -l' should show you the permissions on the scripts after you chmod +x them, and you'll probably see something like

-rwxr-xr-x (755 permissions, for example)

where the parentheses in each script cause the code in parentheses run in a subshell, cd to the home directory, run the other commands, etc... without changing the directory outside of the context of that subshell.

Palmleavr 2009-03-22 10:03

Re: Can't get script executable
 
slvr32, thanks!
I retyped my scripts in Leafpad on my n810 using your tips. I then tried out chmod a+x which, from what I understand from one of TA-t3's posts, should function pretty much as chmod +x. This is what happened (I've "bolded" my inputs to make this easier to read):

Code:

BusyBox v1.6.1 (2008-09-18 09:43:17 EEST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

~ $ sudo gainroot
Root shell enabled


BusyBox v1.6.1 (2008-09-18 09:43:17 EEST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

/home/user # cd /home/user/MyDocs
/home/user/MyDocs # ls -l
drwxr-xr-x    2 user    users        8192 Mar 17 23:21 Books
-rw-r--r--    1 user    users          77 Mar 22 17:27 GBackup.sh
-rw-r--r--    1 user    users        125 Mar 22 17:26 GLaunch.sh
-rw-r--r--    1 user    users        135 Mar 22 17:28 GRestore.sh
/home/user/MyDocs # chmod a+x GLaunch.sh
/home/user/MyDocs # chmod a+x GBackup.sh
/home/user/MyDocs # chmod a+x GRestore.sh
/home/user/MyDocs # ls -l
drwxr-xr-x    2 user    users        8192 Mar 17 23:21 Books
-rwxr-xr-x    1 user    users          77 Mar 22 17:27 GBackup.sh
-rwxr-xr-x    1 user    users        125 Mar 22 17:26 GLaunch.sh
-rwxr-xr-x    1 user    users        135 Mar 22 17:28 GRestore.sh
/home/user/MyDocs #

It looks like the chmod command had no effect on any of the script files. Any hints about what I'm doing wrong?

codeMonkey 2009-03-22 12:17

Re: Can't get script executable
 
Palm: You can see there that the chmod command did add the executable permission for all of your .sh scripts.
Code:

-rw-r--r--    1 user    users          77 Mar 22 17:27 GBackup.sh
-rw-r--r--    1 user    users        125 Mar 22 17:26 GLaunch.sh
-rw-r--r--    1 user    users        135 Mar 22 17:28 GRestore.sh

read/write

Code:

-rwxr-xr-x    1 user    users          77 Mar 22 17:27 GBackup.sh
-rwxr-xr-x    1 user    users        125 Mar 22 17:26 GLaunch.sh
-rwxr-xr-x    1 user    users        135 Mar 22 17:28 GRestore.sh

read/write/execute

Palmleavr 2009-03-22 15:45

Re: Can't get script executable
 
Codemonkey,
Whoa, yes! Thanks for pointing that out! I missed the "x" because I was looking for some stuff in parentheses on the line.

I tried out the .desktop file I wrote to backup the gvm.store and that worked now. The script that I wrote to launch the GVM with Hotsync ID, serial number, etc. information still won't execute. I suspect it's a problem with the script, so I'm going to post over at the Palm OS forum for that issue.

Thanks for everyone who helped me finally get the script thing to work!

TA-t3 2009-03-23 12:27

Re: Can't get script executable
 
Have you tested your scripts manually, that is, from an xterm?
If they don't work, check that you have not accidentally created scripts with carriage return/line feed line endings instead of just line feed line endings. Shell scripts with cr/lf won't work.

If there are cr/lf line endings then the script can be fixed by passing it through 'tr -d "\r"', e.g. cat script.sh | tr -d "\r" > newscript.sh

Palmleavr 2009-03-25 11:26

Re: Can't get script executable
 
TA-t3,
Thanks for your post! I've left you lots of thanks for all the script suggestions I've lifted from your work!

To answer your question, no, I didn't try to launch the scripts manually from XTerm until after I saw your post. I tried just launching a Palm app (Pleco Dict) using the following script:
Code:

#!/bin/sh
/usr/bin/gvm/gvm -O yes -z 1.5 -f yes -i D050 -a PLDE -u "Xxx Xxx:1107" -S

When I tried running this with the "-S" option, I got this error:

HTML Code:

/home/user/MyDocs # sh Pleco.sh
Garnet (tm) VM v1.0 (Prod-Release) - Build 611976 (Nov 25 2008-18:07:55)
GVM:  Unknown option -S

After I eliminated the -S option, the VM did launch. However, it launched directly to the Prefs screen in Portrait mode. None of my installed apps showed up when I hit the home button.
When I exited that GVM and launched the GVM launcher from the menu, I was able to see all my installed apps just fine, but the Hotsync ID was still set to: 0. Even when I changed the App Creator ID to Filz (Filez), I got the same result.

I originally used TextWrangler on my Mac with line endings set to Unix mode. The latest scripts were typed on LeafPad on my n810, so I assume there should be no carriage return problem.

I also tried writing the script with all "short" OR all "long" options (i.e., "-f" versus "--fullscreen"), but that didn't change the outcome. Any ideas why I can't get the GVM to launch correctly?

TA-t3 2009-03-25 11:50

Re: Can't get script executable
 
When you use the short codes, don't use yes or no, they are for the long forms.
So: /usr/bin/gvm/gvm -O -z 1.5 -f -i D050 -a PLDE -u "Xxx Xxx:1107"
I know it's a bit confusing because _some_ of the short options need the parameter (e.g. -z).

Palmleavr 2009-03-25 16:39

Re: Can't get script executable
 
TA-t3,
Thanks! It worked this time--well, actually, the GVM crashed the first time and I lost my setup, but I was able to get it restored and working finally!

Next-up, setting up eight gvm.store's and seeing if I can get them working well enough for me to have access to my most important Palm TX apps on the n810!

Palmleavr 2009-03-27 19:04

Re: Can't get script executable
 
Hello all,
Just for future reference, here's the longest chain of options after the "gvm" command that I've gotten to work (in a script):

Code:

#!/bin/sh#!/bin/sh
/usr/bin/gvm/gvm -a IMGE -O -f -i D050 -n XXXXXXXXXXXX -u "Xxx Xxx:1107" -z 1.5 -L 0x0000,0x0000,0x0000 -g gvm.store_1

/usr/bin/gvm is where the "gvm" command is located

-a IMGE launches Resco Explorer

-O sets rotation

-f sets fullscreen

-i D050 is the Device ID for a Palm TX

-n XXXX... sets the serial number. I found mine using the information tab in Filez (I suspect it might affect the device number that Mobipocket generates, but I haven't tried it yet). In Filez, my serial number came with an "-N" at the end. For the gvm command, just leave the "-N" off.

-u "Xxx Xxx:1107" sets the Hotsync ID. The four-digit number after the Hotsync ID is optional, as far as I understand. I found "1107" within one of the files that is similar to where the Hotsync ID is stored (sorry, I forgot where, but you can look around with Resco Explorer)

-z 1.5 sets the magnication

-L 0x0000,0x0000,0x0000 sets the background to black [Thanks, dfinch!]

-g gvm.store_1 launches from a specified gvm.store file located within /home/user/.gvm [Thanks, burmashave!] so you can have multiple Palm VM's

Now, to find out if I can launch the gvm-launcher program with a Hotsync ID option!


All times are GMT. The time now is 21:39.

vBulletin® Version 3.8.8