What happened to this site? And what's that frog about?

How to set up starkits as CGI

From the old Equi4 Software site wiki 

(Prompted by a Q from "Pauli Soininen" on comp.lang.tcl)

Here's what I do to get CGI going:

    • Create a file called "try.cgi", containing:
        #! /path/to/tclkit
        puts "Content-Type: text/plain\n"
        parray env
    • Get the right tclkit for the platform from /pub/tk/builds.html
    • Get paths and permissions right so the above works.

Once this is in place, I always use starkits - either wrapped (e.g. "try.kit") or unwrapped. The latter is convenient for development, it can be wrapped up later on, once you decide to freeze things.


Let me describe the process, with lots of small steps to resolve everything:

    • start with a file "try.tcl", containing (again):
        puts "Content-Type: text/plain\n"
        parray env
    • to create the starkit, use SDX which has a handy quick-wrap function:
        sdx qwrap try.tcl
    • the result is a starkit called "try.kit", it can be verified to work using:
        ./try.kit
    • a copy of "try.tcl" is stored inside, so the original can now be deleted:
        rm try.tcl
    • now to hook it up as CGI, change that first try.cgi file to:
        #!/bin/sh
        exec /path/to/tclkit /path/to/try.kit
    • you now have a three-file combo (try.cgi, tclkit, and try.kit)
    • if all is well, it will produce output similar to the first test.

Ok, everything is ready to handle real apps as CGI.


One quick way to get going is to unpack the "try.kit" produced above, and modify/extend it as needed, so here goes:

    • to unwrap, use SDX again:
        sdx unwrap try.kit
    • the result is an unwrapped directory area, named "try.vfs/"
    • for convenience, let's modify the "try.cgi" wrapper to run in unpacked mode:
        #!/bin/sh
        exec /path/to/tclkit /path/to/try.vfs/main.tcl
    • this should continue to work as CGI, running scripts directly off the disk

Now CGI works, wrapped starkits work, and unwrapped mode has been set up. It's time to make changes and extend things with real application logic:

    • put the cgi package, or whatever packages are needed, inside try.vfs/lib/
    • modify the main application code, in the package called "app-try"
        edit try.vfs/lib/app-try/try.tcl

That leads to a setup with files which can be edited and tested in unwrapped mode.


When everything is working, you can quickly seal it all as a starkit:

    • run SDX again to wrap things up:
        sdx wrap try.kit     (this will take try.vfs/ as input)
    • change the try.cgi file back to:
        #!/bin/sh
        exec /path/to/tclkit /path/to/try.kit
    • you now have a three-file combo (try.cgi, tclkit, and try.kit) as your application

You can delete the try.vfs area (it can be reconstructed at any time by doing "sdx unwrap try.kit").

If you want a single-file version, i.e. a self-contained executable CGI application which can be shipped to run out of the box (for a specific platform):

    • pick the tclkit platform build you need (let's use FreeBSD as example):
        wget /pub/tk/tclkit-freebsd-x86.gz
        gzip -d tclkit-freebsd-x86.gz
    • build a starpack with it:
        sdx wrap try.cgi -runtime tclkit-freebsd-x86   (this uses try.vfs/ again)
    • that's it, you now have a single file "try.cgi" executable which runs on freebsd

Small point of attention: if you create a starpack for the same platform you're on, you need to specify a temp *copy* of tclkit, otherwise sdx won't be able to merge it into the starpack.


See also:

    • Safekit - a way to run tclkit in a "chroot jail" for maximum security




Powered by Mavrig