Writing Shell Scripts that use a FARGOS/VISTA Object Management Environment

From the beginning, it has been possible to invoke a startup script for a FARGOS/VISTA Object Management Environment daemon as a user command. To achieve this effect, the boot scripts are normally written with the first line appearing as:

#!/usr/bin/env vista

In certain hardened environments, the env utility would not be used to resolve the location of the vista daemon and instead an absolute path to the vista daemon would be specified, but this does not change the ultimate effect. Arguments passed on the command line to the script can be referenced within the boot script using $1, $2, etc. While this can be convenient for many applications, the approach does assume any needed classes are already available, either embedded within the vista core itself or obtainable by dynamically loading either an OIL2 ANF or shared object file suitable for the local execution environment.

Using OIL2 as a First-Tier Scripting Language

The oil2script utility can be used to enable OIL2 source to be used as a scripting language. Similar to how a vista startup script can be enabled for direct invocation, an OIL2 source file can be prefixed with the following usage of oil2script:

#!/usr/bin/env oil2script
By default, the oil2script command will compile the OIL2 source in the file, prepare a custom boot script for the vista daemon that will load the generated object code and invoke it, while passing any additional command line arguments. This convenience mechanism works for many applications, but others require additional setup to initialize services of interest. An optional RC file can be embedded in the OIL2 file that will be recognized by oil2script. The beginning of the script portion is marked with a comment line containing RC and the comment block is closed with an ENDRC line. This is demonstrated below:
/* RC
ScriptTestClass $*

ENDRC */

Note that since the RC content was embedded within a comment block, it is invisible to the oil2 compiler. The remaining content in the file after the optional RC script is expected to be an OIL2 source file. This will be compiled and the resulting object code automatically loaded by the internally generated RC script before the contents of the embedded RC script are processed.

%include <OMEcore.o2h>

class ScriptTestClass {
} inherits from Object;

ScriptTestClass:create(any arg)
{
	int i;
	display("Ran TestScript with argc=", argc, "\n");
	for(i=0;i<argc;i+=1) {
		display("argv[",i,"]=", argv[i], "\n");
		display("type argv[",i,"]=", typeOf(argv[i]), "\n");
		display("exact type argv[",i,"]=", exactTypeOf(argv[i]), "\n");
		display("type name argv[",i,"]=", typeAsText(argv[i]), "\n");
	}
}

The OIL2 compiler will also ignore the initial #! line, which will permit the script to be compiled manually without requiring modification. This is definitely useful for handling initial syntax errors.

It is also possible to provide oil2script with only the code fragment of a single method body, which would not be legal OIL2 source. When provided only a method body, oil2script will automatically generate an affiliated class-and-method for the trivial script body and have it automatically loaded. This approach reduces the contents of the script above to simply:

#!/usr/bin/env oil2script
// OIL2
	int i;
	display("Ran TestScript with argc=", argc, "\n");
	for(i=0;i<argc;i+=1) {
		display("argv[",i,"]=", argv[i], "\n");
		display("type argv[",i,"]=", typeOf(argv[i]), "\n");
		display("exact type argv[",i,"]=", exactTypeOf(argv[i]), "\n");
		display("type name argv[",i,"]=", typeAsText(argv[i]), "\n");
	}

Exploitation of this feature is really suitable for only single trivial methods; in general, it is best to construct a proper class definition and corresponding method implementations.

A more complicated example is illustrated by the VISTAcheckCurrentVersion command.