Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 23 Oct 2019, 19:23
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
ROX turns script into image [SOLVED]
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
MochiMoppel


Joined: 26 Jan 2011
Posts: 1921
Location: Japan

PostPosted: Sun 27 Mar 2016, 08:01    Post subject:  ROX turns script into image [SOLVED]  

It's spooky. Here is what happened:

I was writing a script which - somewhere in the middle - contains a routine to echo some svg tags to a file to create a svg image file. Nothing special. Suddenly I can't execute the script anymore by clicking on the script file in ROX. The script icon turned into an image icon and ROX tries to open it with viewnior.

After some head scratching I discovered that for ROX it *sometimes* is sufficient to find a string like '<svg' in the middle of a script to change the MIME type to image/svg+xml, although
1) ROX originally created it as a script (Menu >New > Script)
2) The shebang marks it as a bash script
3) ROX's content sniffing identified it as "Bourne-Again shell script text executable"
3) The file is executable

What makes ROX suddenly think that this is an image file? And more important: Does this mean that ROX constantly scans the file content for MIME hints?

I know that I can avoid such surprises by adding a .sh extension to my scripts, but I don't like that. I don't like the whole behaviour.

Edit:
I checked with a different file manager and the result is the same: Changing the svg of below example into avg turns the MIME type back to application/x-shellscript, so it's not a ROX issue. The only difference: Clicking on the file in a different file manager runs it correctly as a script.
script_turned_image.png
 Description   
 Filesize   59.56 KB
 Viewed   346 Time(s)

script_turned_image.png


Last edited by MochiMoppel on Thu 31 Mar 2016, 10:44; edited 1 time in total
Back to top
View user's profile Send private message 
scientist

Joined: 23 May 2015
Posts: 864

PostPosted: Tue 29 Mar 2016, 19:24    Post subject:  

Running it without the extension opened Gimp when using Thunar.

Guess it uses the default image editor.

Using it with the sh extension does nothing in Thunar.

You really should use the sh extension.

By using the extension you can always know it's a script as there are many executables that don't have extensions.

_________________
Thanks,
Andy


Slacko 6.3.0 FULL INSTALL
JWM
File Manager - Thunar
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Tue 29 Mar 2016, 19:44    Post subject:  

Using the .sh extension is also useful e.g. when creating scripts that are intended to being gettext'd. The function to create the .pot file complains missing .sh and refuses to build the .pot file.

It may be different using MoManager, but when doing it manually or by a script I need to add the .sh extension.

My latest programs are basically created in a modular way using my GDAM-Builder GtkDialog application. Modular means the code is splitted into different files. E.g. definitions are separated from the main script. So I had wrote a little function for my GDAM-Builder that makes copies of all program's scripts and definitions files and adding the .sh extension to their names. These files are used to create the .pot files. After all .pot files are created, the copies are removed and the different created .pot files are combined into a single file renamed after the main script (no .sh extension then).

Today I can build a .pot file by right-clicking a script or a C code file. DevX extension SFS will load automatically (related to the Puppy in use). Same as for the .mo files.

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1921
Location: Japan

PostPosted: Wed 30 Mar 2016, 09:16    Post subject:  

@ scientist,LazY Puppy. Thanks for trying to help. Again: Pros and cons of extensions is not my topic. I'm rather interested to know how Puppy determines MIME types when no extensions are provided.

What I've learned so far is that the whole process of MIME sniffing is driven by magic files.

Contents indicate...
The information about file contents is produced by the command /usr/bin/file -b <filename>.
This command is called by ROX when opening the Properties dialog.
The contents patterns used by /usr/bin/file are stored in /usr/share/misc/magic.mgc

Contents information is not used to determine or change the MIME type, i.e it is not the cause for the type switching I described in the first post. This may also explain the mismatch with the MIME type.

MIME type
The relevant information that causes the disturbing MIME switching is stored in the file /usr/share/mime/magic
This binary file contains the string <svg+257 , which apparently means that Puppy determines an (extensionless) file to be a SVG image file if this file contains the string <svg within the first 257 characters. This also explains why using <svg> in my previous scripts didn't cause problems. The string was preceded by sufficient bash code so that it didn't fall into the 257 byte "trigger zone".

And why would the shebang, very unique and placed right at the beginning of a script file, not be sufficient to trigger the correct MIME type? Well, looking into /usr/share/mime/magic reveals that various shebangs for different shell scripts are included, but they are listed after the pattern for svg files. Apparently the first pattern that matches determines the MIME type.

My personal conclusion: /usr/share/mime/magic is poorly structured, very bloated and hardly useful, yet I will leave it as is, now that I faintly understand its inner workings.
Back to top
View user's profile Send private message 
scientist

Joined: 23 May 2015
Posts: 864

PostPosted: Wed 30 Mar 2016, 10:03    Post subject:  

Interesting file.

Deleted all svg references and it fixed the problem if run from Rox Filer.

Thunar still opens Gimp. ?

One of those mysteries we have to live with. Smile
Altered_magic.zip
Description 
zip

 Download 
Filename  Altered_magic.zip 
Filesize  6.55 KB 
Downloaded  89 Time(s) 

_________________
Thanks,
Andy


Slacko 6.3.0 FULL INSTALL
JWM
File Manager - Thunar
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 3367
Location: The Blue Marble

PostPosted: Thu 31 Mar 2016, 06:41    Post subject:  

That's because svg magic (80) is defined at higher priority that shellscript magic (50). You can two choices, either lower the shell priority, or increase the svg priority. The source file is /usr/share/mime/freedesktop.org.xml; once you have done the update just run "update-mime-database /usr/share/mime".

You can do this without restarting rox, if you do it correctly you can refresh Rox and see the icon type changes.

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0415s ][ Queries: 12 (0.0069s) ][ GZIP on ]