
void install(string request, string dest)
{
    string target;
    int components = 0;
    list pathsplit;
    string base;
    base = "tmp/install/";

    md(base);

    if (request == "x")
        components = 63;
    else 
    {
        if (strfind(request, "a") != -1)
            components |= 1;
        if (strfind(request, "b") != -1)
            components |= 2;
        if (strfind(request, "d") != -1)
            components |= 4;
        if (strfind(request, "m") != -1)
            components |= 8;                
        if (strfind(request, "u") != -1)
            components |= 32;
    }

    chdir(g_cwd);                       // determine the destination path
    if (dest == "")
        dest = "/";
    else
        md(dest);

    dest = cutEoln(backtick("readlink -f " + dest)[0]);

    if (g_logPath != "")
        backtick("icmake/log " + dest + " " + g_logPath);


    if (components & 1)
    {
        target = base + "a/" ADD "/";

        printf("\n  installing additional documentation\n");

        printf("  installing README files and ACKNOWLEDGEMENTS at `", 
                                                            target, "\n");
        logZip("", "README", target);
        logZip("", "README.3.00.00", target);
        logZip("", "ACKNOWLEDGEMENTS", target);

        printf("  installing cross-reference at `", target, "'\n");
        logZip("", "stealth.xref", target);
 

        target += "examples/";
        printf("  installing examples at `", target, "'\n");
        logZip("documentation/example-policies/", "demo.pol", target);
        logZip("documentation/example-policies/", "localhost.pol", target);
        logZip("documentation/example-policies/", "simple.pol", target);

        destInstall(dest, base + "a");
    }

    if (components & 2)
    {
        target = base + "b/" BINARY;
        pathsplit = path_file(target);

        printf("  installing the executable `", target, "'\n");
        logFile("tmp/bin", "binary", pathsplit[0], pathsplit[1]);

        destInstall(dest, base + "b");
    }


    if (components & (4 | 8))
    {
        target = base + "d/" DOC "/";

        if (components & 4)
        {
            printf("  installing the changelog at `", target, "\n");
            logZip("", "changelog", target );

            printf("  installing the logrotate mold  as `", 
                    target, "/scripts/etc/logrotate.d/target.gz'\n");
            logZip("share/etc/logrotate.d/", "target", 
                            target + "scripts/etc/logrotate.d/");

            printf("  installing the cleanup script as `", 
                            target, "/scripts/etc/stealth/cleanup.rc.gz'\n");
            logZip("share/etc/stealth/", "cleanup.rc", 
                                        target + "scripts/etc/stealth/");

            printf("  installing additional scripts at `", 
                            target, "/scripts/usr/bin'\n");

            logZip("share/usr/bin/", "", target + "scripts/usr/bin/");

            destInstall(dest, base + "d");
        }

        if (components & 8)
        {
            printf("  installing the html-manual pages at `", target, "\n");
            logInstall("tmp/manhtml", "", target);

            destInstall(dest, base + "d");
        }
    }


    if (components & 8)
    {
        target = base + "m/" MAN "/";
        printf("  installing the manual pages below `", target, "'\n");
    
        logZip("tmp/man", "stealth.1", target);

        destInstall(dest, base + "m");
    }

    if (components & 32)
    {
        target = base + "u/" UGUIDE "/";
        printf("  installing the user-guide at `", target, "'\n");
        logZip("tmp/manual/LaTeX", "", target + "LaTeX/");
        logZip("tmp/manual/pdf", "", target + "pdf/");
        logInstall("tmp/manual/html", "", target + "html/");

        destInstall(dest, base + "u");
    }

    printf("\n  Installation completed\n");

    exit(0);
}
