Reply to topic

Can shell-script execution on double-clicks be disabled?

Farry
Registered Member
Posts
10
Karma
1
In konqueror and/or dolphin, I'm so used to double-clicking on text files that I also occasionally double-click by mistake on a shell-script with the executable-flag set when I actually want to edit the script. This can be a problem. Is there a way to disable the file-manager's execution of shell-scripts?
User avatar bcooksley
Administrator
Posts
19765
Karma
87
OS
You could try changing the file association. Konqueror > Settings > Configure Konqueror > File Manager > File Associations. Look for an association containing "sh" under Applications.


KDE Sysadmin
[img]http://forum.kde.org/content/bcooksley_sig.png[/img]
Farry
Registered Member
Posts
10
Karma
1
bcooksley wrote:You could try changing the file association. Konqueror > Settings > Configure Konqueror > File Manager > File Associations. Look for an association containing "sh" under Applications.


Thanks, but no luck so far.

I tried that in both KDE 3.5.9 (Mandriva 8.1) and KDE 4.2.2 (Mandriva 9.1) and for "sh", there is the association "x-shellscript". (My scripts are listed as type "shell script" in the file-view, whether they have the "sh" extension or not). In x-shellscript's embedding-tab there are options: "use settings for application group" (the default), "show file in embedded viewer", and "show file in separate viewer". I tried both of the latter options for both versions of KDE, and although the option changes were retained even after restarting KDE, the shell-scripts continued to execute on a double-click.

Am I misunderstanding the intent of those options or are the options broken?
User avatar anda_skoa
KDE Developer
Posts
783
Karma
4
OS
You could check whether one of the Kiosk restrictions work
http://websvn.kde.org:80/trunk/KDE/kdel ... rev=444344

Or make sure the scripts don't have the execution bit set, e.g. by mounting the respective paritions with noexec

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
Farry
Registered Member
Posts
10
Karma
1
anda_skoa wrote:You could check whether one of the Kiosk restrictions work
http://websvn.kde.org:80/trunk/KDE/kdel ... rev=444344
Or make sure the scripts don't have the execution bit set, e.g. by mounting the respective paritions with noexec


Thanks. No luck so far.

I tried adding some of the suggested KDE Action Restrictions in that document to kdeglobals:

shell_access=false -- but that stopped konsole from starting and disabled Autostart scripts, which was too restrictive.

action/executeshellcommand=false -- that just removed an item from the tools menu, but the scripts still executed on double clicks.

The problem is that I occasionally double-click by mistake on shell-scripts with the executable-flag set, and I want to guard against that. I can't mount the partitions with noexec because they are scripts that need to be executable on the same machine.
Farry
Registered Member
Posts
10
Karma
1
Is there a way to manipulate the magic file recognition so that shellscripts simply aren't recognized as such? Is there a database file that can be hacked to accomplish this?
User avatar bcooksley
Administrator
Posts
19765
Karma
87
OS
Try running the following command aganist the shell scripts:
Code: Select all
file -i


Then search for the mimetype it returns in file associations.


KDE Sysadmin
[img]http://forum.kde.org/content/bcooksley_sig.png[/img]
Farry
Registered Member
Posts
10
Karma
1
bcooksley wrote:Try running the following command aganist the shell scripts:
file -i
Then search for the mimetype it returns in file associations.


Thanks. That identified the files a bit differently, but it led me to find kfile, which seems to identify the mimetypes in the same way as konqueror. When identifying shellscripts, it warns:

Code: Select all
$ kfile  test1.sh
test1.sh: Shell Script (application/x-shellscript)
KFileMetaInfo: WARNING: KTxtPlugin was created for application/x-shellscript but doesn't call addMimeTypeInfo for it!
test1.sh: Cannot determine metadata


What does that warning mean? Is it possible to hack some file to alter the recognitions?
User avatar bcooksley
Administrator
Posts
19765
Karma
87
OS
It is probably possible, but I wouldn't know how to, modify a files mimetype. It might be determined on the fly, in which case it is impossible.


KDE Sysadmin
[img]http://forum.kde.org/content/bcooksley_sig.png[/img]
Farry
Registered Member
Posts
10
Karma
1
I've cracked the original problem for KDE3, but not KDE4.

KDE3: In the file: /usr/share/mimelnk/application/x-shellscript.desktop
comment out the line: X-KDE-IsAlso=application/x-executable-script

And shellscripts stop executing on double-clicks in the file-manager.

The only untoward effect I've noticed was that a script in .kde/Autostart stopped executing, but I fixed that by creating a .desktop link to it. That's fine. The only time I want to execute shellscripts is from konsole or from icons that I've added to a quick-browser menu.

In KDE4, I found the apparent equivalent, and
in the file: /usr/share/mime/application/x-shellscript.xml
I deleted the line:
But that didn't make any difference, even after rebooting.
User avatar bcooksley
Administrator
Posts
19765
Karma
87
OS
You may need to force a rebuild of the Sycoca.
Code: Select all
kbuildsycoca4 --noincremental


KDE Sysadmin
[img]http://forum.kde.org/content/bcooksley_sig.png[/img]
Farry
Registered Member
Posts
10
Karma
1
Thanks. I've now cracked the problem for KDE4 too.

I realized that something needed to be rebuilt when I saw a note in the top of the file that I changed, saying that it was auto-generated and should not be edited. I followed the info in the note and found:
/usr/share/mime/packages/freedesktop.org.xml

To stop shellscripts executing on double-clicks in the file-manager, I needed to edit that file. It contains all the mime definitions (including all the "magic" tags for recognizing the files by content inspection). The section for shellscripts began with:


and there I commented out a line like so:


then rebuilt the mime database:
[root]# update-mime-database /usr/share/mime

Sorted. :-)
Farry
Registered Member
Posts
10
Karma
1
Hmmm... Just stumbled across this again because it's got a high Google search rating, but it seems that the passage of time has graunched my last post. Something to do with updated forum software not liking the XML syntax, I guess. So here it is in a code box:

Code: Select all
edit /usr/share/mime/packages/freedesktop.org.xml
and find the line that starts the shellscript section:
  <mime-type type="application/x-shellscript">
then scroll down to find this line within that section:
    <sub-class-of type="application/x-executable"/>
then comment it out like so:
    <!-- <sub-class-of type="application/x-executable"/> -->
save that, then compile it with this command:
  sudo update-mime-database /usr/share/mime

Re-start KDE -- and shellscripts no longer execute on double-clicks in Dolphin.
RedUbi
Registered Member
Posts
1
Karma
0
Thank you Farry !!!
You are a hero for me!

That was exactly the solution!

When I click on my scripts from Konqueror is only because I want to read/modify them - the choice to execute them upon click just don't make any sense for me!

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], claydoh, Google [Bot], Yahoo [Bot]