void rungzip9(string src, string dest)
{
    int idx;
    string file;
    list man;

    chdir(src);
    man = makelist("*");
    chdir(g_cwd);
    for (idx = sizeof(man); idx--; )
    {
        file = element(idx, man);
        run("gzip -9 < " + src + file + " > " + dest + file + ".gz");
    }
}

void reqzip(string dest, string srcPath, string src)
{
    list files;
    int idx;
    string file;

    files = strtok(src, " ");
    for (idx = sizeof(files); idx--; )
    {
        file = element(idx, files);
        run("gzip -9 < " + srcPath + file + " > " + dest + file + ".gz");
    }
}

void install(string what, string where)
{
    string docdoc;
    docdoc = DOC + "-doc";

    if (what == "program")
    {
        printf("  installing the executable\n");
        md(where + BIN);
        run("cp tmp/bin/* " + where + BIN);

        printf("  installing the information directly in and under $DOC\n");
        md(where + DOC);
        reqzip(where + DOC + "/", "./", "changelog");
        run("cp README ACKNOWLEDGEMENTS " + where + DOC);
    }

    if (what == "man")
    {
        printf("  installing the manual page stealth.1\n");
        md(where + MAN);
        reqzip(where + MAN + "/", "tmp/man/", "stealth.1");
    
        printf("  installing the manual page stealthman.html\n");
        md(where + DOC + "/man");
        reqzip(where + DOC + "/man/", "tmp/manhtml/", "stealthman.html");

        printf("  installing scripts\n");
        md(where + DOC + "/scripts/etc/logrotate.d");
        reqzip(where + DOC + "/scripts/etc/logrotate.d/", 
                                        "share/etc/logrotate.d/", "target");

        md(where + DOC + "/scripts/etc/stealth");
        reqzip(where + DOC + "/scripts/etc/stealth/", "share/etc/stealth/", 
                                                                "cleanup.rc");
        md(where + DOC + "/scripts/usr/bin");
        rungzip9("share/usr/bin/", where + DOC + "/scripts/usr/bin/");
    }

    if (what == "manual")
    {
        printf("  installing examples\n");
        md(where + docdoc + "/examples");
        rungzip9("example-policies/", where + docdoc + "/examples/");

        printf("  installing manual\n");
        run("cp -r tmp/manual " + where + docdoc);
    }

    printf("  " + what + " installation completed\n");

    exit(0);
}


