X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-script.c;h=ba057ef72303d2e02d358fc2d6a10d785d62aafd;hb=49ff42bdf62fe00f15ec217171649f0ce8848c14;hp=359970abd567d7934d641864c8e4e034e7c8d706;hpb=636836fc0d1e5126ad94a73be80a7eea7d984d09;p=zpackage diff --git a/zpm-script.c b/zpm-script.c index 359970a..ba057ef 100644 --- a/zpm-script.c +++ b/zpm-script.c @@ -26,7 +26,7 @@ */ void usage(void) { - fprintf(stderr, "usage: db hash file\n"); + fprintf(stderr, "usage: zpm script ...\n"); } int setdir(char *rootdir) { @@ -119,6 +119,12 @@ int run(char *program, char **args, char *output, int *status) { #define SOFT 1 #define HARD 2 +static int list_scripts(void *ud, const char *pkg, const char *stage, + const char *hash) { + printf("%s %s %.8s\n", pkg, stage, hash); + return 0; +} + int main(int ac, char **av){ struct zpm zpm; int rv; @@ -137,10 +143,10 @@ int main(int ac, char **av){ char *script = "/var/tmp/zpm-script"; char *output = "/var/tmp/zpm-script.out"; char *phase = 0; + char *envvar = 0; int quiet = 0; int scriptishash = 0; int mode = RUN; - int all = 0; if (getenv("ZPMDB")) { db = getenv("ZPMDB"); @@ -149,6 +155,16 @@ int main(int ac, char **av){ rootdir = getenv("ZPM_ROOT_DIR"); + envvar = getenv("ZPM_SCRIPT_FILE"); + if (envvar) { + script = envvar; + } + + envvar = getenv("ZPM_SCRIPT_OUTPUT"); + if (envvar) { + output = envvar; + } + /* run, set, show, hash */ /* set -S, if -H set the hash, output hash, unless quiet * show: -o, or stdout, @@ -172,12 +188,11 @@ int main(int ac, char **av){ case 'l': mode = LIST; break; case 'R': rootdir = optarg; break; case 'F': required = 1; break; - case 'a': all = 1; break; case 'h': scriptishash = 1; break; case 'o': output = optarg; break; case 'S': script = optarg; break; - case 'q': quiet = 1; + case 'q': quiet = 1; break; default: usage(); @@ -248,10 +263,14 @@ int main(int ac, char **av){ fail = HARD; } } else if (mode == LIST) { - if (!zpm_script_hash(&zpm, pkgid, phase, hash)) { + if (!phase) { + zpm_foreach_script(&zpm, pkgid, phase, 0, list_scripts); + } else if (!zpm_script_hash(&zpm, pkgid, phase, hash)) { fail = SOFT; } else if (scriptishash) { - printf("%s\n", hash); + if (!quiet) { + printf("%s\n", hash); + } } else { if (!output) { output = "-"; @@ -300,6 +319,7 @@ int main(int ac, char **av){ if (!zpm_extract(&zpm, hash, script, 0700)) { fprintf(stderr, "unable to extract script"); fail = HARD; + zpm_note_add(&zpm, pkgid, NULL, hash, "unable to extract %s script", phase); goto cleanup; } @@ -307,6 +327,10 @@ int main(int ac, char **av){ if (rv) { fprintf(stderr, "package %s script failed with code %d\n", pkgid, rv); + + zpm_import(&zpm, output, 0, hash); + zpm_note_add(&zpm, pkgid, NULL, hash, "package %s script failed with code %d", phase, rv); + fail = HARD; } @@ -324,5 +348,4 @@ cleanup: zpm_close(&zpm); return (fail == HARD || (required && fail)) ? EXIT_FAILURE : 0; - }