Fossil Forum

Can I invoke 'fossil' in a CGI set up as a bash script?
Login

Can I invoke 'fossil' in a CGI set up as a bash script?

Can I invoke 'fossil' in a CGI set up as a bash script?

(1) By Robert Hairgrove (bobhairgrove) on 2023-04-24 09:25:00 [link] [source]

My shared hosting server will let me run CGI scripts written in Perl, Python, SSI or shell scripts. However, it won't invoke the fossil binary when I set up the CGI script according to the docs (statically-compiled in a Docker container and extracted as a stand-alone binary, according to the instructions in Fossil docs).

Everything works fine on my localhost server, there are no problems with the path, and the fossil binary I am using on my shared hosting server has permissions 0755 set.

So I attempted to write a short bash script -- the server will run this correctly, for example:

#!/bin/bash
echo -e "Content-type: text/html\n\nHello World!\nMy first CGI script."

Now I have written this shell script to try to run fossil from the script, not as the executable itself. If I understand correctly, instead of setting the "repository: xyz" on a separate line, I can set the environment variable FOSSIL_REPOSITORY. I am assuming that all of the other environment variables already set by the server will also be seen by fossil when invoked this way. But I probably need to do this differently.

When I add "--repository" as a command-line option instead of setting the environment variable, and run the script in a terminal, fossil gives me an error: "Unknown option".

Here is what I have so far (invoked on 'localhost' for the moment, but not working):

#!/bin/bash
v_fossil_bin="/usr/local/bin/fossil"
v_fossil_repo="/home/bob/code/TEST_REPOS/SBBL_DEV/FOSSIL/SBBL_README.fossil"
v_cmd="${v_fossil_bin}"
export FOSSIL_REPOSITORY="${v_fossil_repo}"
echo -e "$(${v_cmd} $@)"

This will invoke fossil, but it appears that it does not return what it is supposed to return. It returns about 100 bvtes of gzip'ed text which my browser does not understand.

There must be a way ... I looked at the source of the Flint project over on chiselapp.com, and they call fossil through a PHP script using exec(). However, I am fairly sure that my shared hosting server has locked that function out as well if I am still having problems of the sort described above.

And I'd rather not use Chisel anyway ... they are still on an older Fossil version, and there are just too many projects out there which were obviously set up as tests and never deleted (click on "Public repositories"...)

(2) By Richard Hipp (drh) on 2023-04-24 10:24:52 in reply to 1 [link] [source]

Two step process:

  1. Set up a normal Fossil CGI script as described in the documentation, using "repository:" and similar. Call this normal CGI script "norm".

  2. Set up a separate CGI script that uses /bin/sh to invoke the first:

#!/bin/sh
fossil norm

(3) By Robert Hairgrove (bobhairgrove) on 2023-04-24 11:13:09 in reply to 2 [link] [source]

Thanks very much, Richard. This now works fine if I run it on localhost.

However, when uploaded to my shared hosting provider, with paths properly adjusted and 0777 file and directory permissions set, I am now getting the error "Permission denied" in my CGI error log.

Not sure why, but it looks like the server puts everything in a chroot jail that doesn't have access to any of my local executable files.

It would be really great if I could somehow get this to work, because Fossil is so amazing! :)

(4.3) By S. Ross Gohlke (rossgohlke) on 2023-04-28 18:04:25 edited from 4.2 in reply to 3 [source]

Try absolute paths.

#!/bin/bash
/path/to/fossil /path/to/norm

The host might not be setting or passing $PATH.

For general troubleshooting of paths and chroot, modify your original CGI script to run arbitrary commands.

#!/bin/bash
echo -e "Content-type: text/html\n\n`ls -l /`."

#!/bin/bash
echo -e "Content-type: text/html\n\n`echo $PATH`."