{"id":11,"date":"2007-10-05T06:24:23","date_gmt":"2007-10-05T11:24:23","guid":{"rendered":"http:\/\/littlesvr.ca\/grumble\/2007\/10\/05\/execute-a-download\/"},"modified":"2012-12-05T00:59:30","modified_gmt":"2012-12-05T05:59:30","slug":"execute-a-download","status":"publish","type":"post","link":"http:\/\/littlesvr.ca\/grumble\/2007\/10\/05\/execute-a-download\/","title":{"rendered":"Execute a download"},"content":{"rendered":"<p>Some Windows and Mac users will be surprised at this, some will laugh &#8211; and well they should. On Linux it&#8217;s not possible to just download a program and run it, not even if it&#8217;s a program for the right platform. How stupid is that?<\/p>\n<p>The problem is that (probably for no-longer-relevant security reasons) any file you download using a web browser (over HTTP or FTP) will have read and write permissions for the user, and read (or nothing) for group and others &#8211; in other words -rw-r&#8211;r&#8211;, or 644. A double-click on the file in a file manager (or on the desktop) will get the system to think that it&#8217;s a data file that needs to be opened in another program, and usually a dialog will come up asking you what program you want to open this file (program) in. Arrrgh!<\/p>\n<p>I&#8217;m asking around for a solution, but I suspect there is none. If that&#8217;s the case maybe I&#8217;ll try to fix it myself &#8211; the solution is a couple of lines in C.<\/p>\n<p>Some background: it is possible to have a shell script (let&#8217;s call it program.sh) that has more than just shell commands. For example the Loki games installer is a shell script but it has a GUI and a few hundred binary files (possibly in an archive), all this in program.sh. There are other examples of this.<\/p>\n<p>So let&#8217;s say we make a new file extension &#8211; .esh, for executable .sh, and these will actually be shell scripts, following all the rules of sh\/bash. When one double-clicks on such a file in a file manager, the file manager will either:<\/p>\n<ul>\n<li>Execute the file if it has +x permissions, in which case it will act like a shell script, or<\/li>\n<li>Treat the file as a data file and will open it in the associated program &#8211; this will be my program which I will call esh<\/li>\n<\/ul>\n<p>The program will be something like this:<br \/>\n<code><br \/>\n\/* esh.c *\/<br \/>\nint main(int argc,char** argv)<br \/>\n{<br \/>\nif(argc != 2) return -1;<br \/>\nexec(\"\/bin\/bash\", \"bash\", argv[1], NULL);<br \/>\n}<br \/>\n\/* thank you WordPress for deleting spaces at the beginning of a line. grrr *\/<br \/>\n<\/code><\/p>\n<p>So if the file manager runs &#8216;esh program.esh&#8217; it will just execute \/bin\/bash program.esh, which is exactly what I want &#8211; it will give the illusion of a file being executed even if it doesn&#8217;t have execute permissions.<\/p>\n<p>Of course then there is the matter of getting distributions to ship with esh installed by default &#8211; but maybe I&#8217;m not the only one who thinks this is a major misfeature in Linux, and it will get done quickly.<\/p>\n<p>If I don&#8217;t find a different solution in a couple of weeks, I will probably go ahead and start pimping this one.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some Windows and Mac users will be surprised at this, some will laugh &#8211; and well they should. On Linux it&#8217;s not possible to just download a program and run it, not even if it&#8217;s a program for the right platform. How stupid is that? The problem is that (probably for no-longer-relevant security reasons) any &hellip; <\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-andrew","4":"post-11","6":"format-standard","7":"category-opensource","8":"category-safeforseneca"},"_links":{"self":[{"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":1,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":687,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/posts\/11\/revisions\/687"}],"wp:attachment":[{"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}