package

simple and robust package manager
Log | Files | Refs | README

commit 138f73da6d29fefb2f814e308fed8ca9137b6aee
parent f14761bb129f6889f9453a65b1b9becd210a656d
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 13 Jan 2019 13:48:37 +0100

more homogene pack-* download scripts

Diffstat:
Mbin/pack-cvs | 18+++++-------------
Mbin/pack-extract | 1+
Mbin/pack-ftp | 9+++------
Dbin/pack-get | 15---------------
Mbin/pack-git | 9+++++----
Mbin/pack-http | 8++------
Mbin/pack-install | 17++++++++---------
Mbin/pack-tar | 11++++-------
Mfs.c | 8++++----
Mpack-add.c | 37+++++++++++++++++++------------------
Mpack-get.c | 15++++++++++-----
Mpack.c | 39+++++++++++++++++++++++++++++++++++----
Mpack.h | 3++-
13 files changed, 98 insertions(+), 92 deletions(-)

diff --git a/bin/pack-cvs b/bin/pack-cvs @@ -1,15 +1,7 @@ #!/bin/sh -e -PACK=${PACK:-/var/pack} -IFS=/; set -- $1; IFS= -pack=${1%/*} -version=${1#*/} -url=$2 +PACK_TAR=${PACK_TAR:-/var/pack/tar} +PACK_CVS=${PACK_CVS:-/var/pack/cvs} -trap "rm -rf '$PACK/cvs/$pack/$version' '$PACK/tar/$pack/$version.tar'" INT TERM EXIT - -mkdir -p "$PACK/src/$pack/$version" -cd "$PACK/cvs/$pack/$version" -cvs -qd "$url" checkout -P "$path" -tar -cf "$PACK/tar/$pack/$version.tar" . - -trap - INT TERM EXIT +cd "$PACK/cvs/$1" +cvs -qd "$2" checkout -P "$path" +tar -cf "$PACK_TAR/$1.tar" . diff --git a/bin/pack-extract b/bin/pack-extract @@ -5,4 +5,5 @@ case $1 in (*.tbz|*.tar.bz2) bzip2 -d - ;; (*.txz|*.tar.xz) xz -d - ;; (*.tlz|*.tar.lz) lzip -d - ;; +(*) exit 1 ;; esac diff --git a/bin/pack-ftp b/bin/pack-ftp @@ -1,8 +1,5 @@ #!/bin/sh -e -PACK=${PACK:-/var/pack} -pack=${1%/*} -version=${1#*/} -url=$2 +PACK_TAR=${PACK_TAR:-/var/pack/tar} -mkdir -p "$PACK/tar/$pack" -[ -f "$PACK/tar/$1.tar" ] || wget --no-check-certificate -O- "$url" | pack-extract "$url" >$PACK/tar/$1.tar +sleep 10 +wget --no-check-certificate -O- "$2" | pack-extract "$2" >$PACK_TAR/$1/tar diff --git a/bin/pack-get b/bin/pack-get @@ -1,15 +0,0 @@ -#!/bin/sh -e -PACK_TAR=${PACK_TAR:-/var/pack/tar} -PACK_DEF=${PACK_TAR:-/etc/pack} -pack=${1%/*} -version=${1#*/} - -test -f "$PACK_TAR/$version/$pack.tar" || -while IFS= read -r url; do - case $url in - (http://*|https://*) pack-http "$pack/$version" "$url" ;; - (git://*) pack-git "$pack/$version" "$url" ;; - (ftp://*|ftps://*) pack-ftp "$pack/$version" "$url" ;; - (cvs://*) pack-cvs "$pack/$version" "$url" ;; - esac -done <$PACK_DEF/$pack/$version/uri diff --git a/bin/pack-git b/bin/pack-git @@ -1,8 +1,9 @@ #!/bin/sh -e -PACK=${PACK:-/var/pack} +PACK_GIT=${PACK_GIT:-/var/pack/git} +PACK_TAR=${PACK_TAR:-/var/pack/tar} pack=${1%/*} url=$2 -mkdir -p "$PACK/git/$pack" "$PACK/tar/$pack" -! git clone --bare "$url" "$PACK/git/$1" -git -C "$PACK/git/$1" archive --format=tar master >$PACK/tar/$1.tar +mkdir -p "$PACK_GIT/${1%/*}" +! git clone --bare "$url" "$PACK_GIT/$1" +git -C "$PACK_GIT/$1" archive --format=tar master >$PACK_TAR/$1/tar diff --git a/bin/pack-http b/bin/pack-http @@ -1,8 +1,4 @@ #!/bin/sh -e -PACK=${PACK:-/var/pack} -pack=${1%/*} -version=${1#*/} -url=$2 +PACK_TAR=${PACK_TAR:-/var/pack/tar} -mkdir -p "$PACK/tar/$pack" -[ -f "$PACK/tar/$1.tar" ] || wget --no-check-certificate -O- "$url" | pack-extract "$url" >$PACK/tar/$1.tar +wget --no-check-certificate -O- "$2" | pack-extract "$2" >$PACK_TAR/$1/tar diff --git a/bin/pack-install b/bin/pack-install @@ -1,12 +1,11 @@ #!/bin/sh -e -PACK=${PACK:-/var/pack} -pack=${1%/*} -version=${1#*/} +PACK_OUT=${PACK_OUT:-/var/pack/pkg} +PACK_BIN=${PACK_BIN:-/var/pack/bin} +PACK_MAN=${PACK_MAN:-/var/pack/man} -mkdir -p "$PACK/bin" -mkdir -p "$PACK/man" -cd "$PACK/pkg/$pack/$version" +mkdir -p "$PACK_BIN" "$PACK_MAN" +cd "$PACK_OUT/$1" -if [ -d bin ]; then cp -RLfp bin "$PACK"; fi -if [ -d man ]; then cp -RLfp man "$PACK"; fi -if [ -d share/man ]; then cp -RLfp share/man "$PACK"; fi +if [ -d bin ]; then cp -RLfp bin/* "$PACK_BIN"; fi +if [ -d man ]; then cp -RLfp man/* "$PACK_MAN"; fi +if [ -d share/man ]; then cp -RLfp share/man/* "$PACK_MAN"; fi diff --git a/bin/pack-tar b/bin/pack-tar @@ -1,12 +1,9 @@ #!/bin/sh -e PACK_SRC=${PACK_SRC:-/var/pack/src} PACK_TAR=${PACK_TAR:-/var/pack/tar} -IFS=/; set -- $1; IFS= -pack=${1:?} version=${2:?} -mkdir -p "$PACK/src/$pack/$version" -tar -xv -f "$PACK/tar/$pack/$version.tar" -C "$PACK/src/$pack/$version" -if [ "$(ls "$PACK/src/$pack/$version" | wc -l | tr -cd 0-9)" = 1 ]; then - ! mv "$PACK/src/$pack/$version/"*/* "$PACK/src/$pack/$version" - ! rmdir "$PACK/src/$pack/$version"/* 2>/dev/null +tar -xv -f "$PACK_TAR/$1/tar" -C "$PACK_SRC/$1" +if [ "$(ls "$PACK_SRC/$1" | wc -l | tr -cd 0-9)" = 1 ]; then + ! mv "$PACK_SRC/$1/"*/* "$PACK_SRC/$1" + ! rmdir "$PACK_SRC/$1"/* 2>/dev/null fi diff --git a/fs.c b/fs.c @@ -136,14 +136,14 @@ fs_remove_r_recurse(stralloc *sa) if (S_ISDIR(st.st_mode)) { if (!fs_remove_r_recurse(sa)) break; - if (rmdir(sa->x) == -1) break; } else { if (unlink(sa->x) == -1) break; } } closedir(dp); - return errno == 0; + rmdir(sa->x); + return (errno == 0); } int @@ -154,8 +154,8 @@ fs_remove_r(char const *dir) if (!stralloc_cats(&path, dir)) goto err; ret = fs_remove_r_recurse(&path); - -err: stralloc_free(&path); +err: + stralloc_free(&path); return ret; } diff --git a/pack-add.c b/pack-add.c @@ -4,7 +4,6 @@ #include "buffer.h" #include "env.h" -#include "forkexec.h" #include "fs.h" #include "genalloc.h" #include "log.h" @@ -23,28 +22,23 @@ void step(pack const *p, char const *cmd, char const *log, char const *dir) { int x; + char fmt[4]; buffer_puts(buffer_2, " "); buffer_puts(buffer_2, cmd + (str_start(cmd, "pack-") ? 5 : 0)); buffer_puts(buffer_2, " "); buffer_flush(buffer_2); - switch ((x = pack_step(p, cmd, log))) { - char fmt[4]; - case -1: - log_diesys1(100, cmd); - case 0: - break; - default: - fmt_long(fmt, x); - buffer_puts(buffer_2, "< exit "); - buffer_puts(buffer_2, fmt); - buffer_puts(buffer_2, "\n"); - buffer_flush(buffer_2); - if (!pack_remove(p, dir)) - log_errsys6("deleting ", dir, "/", p->name, "/", p->ver); - log_die5(100, cmd, " ", p->name, "/", p->ver); - } + if ((x = pack_step(p, cmd, log, dir)) == 0) return; + + fmt_long(fmt, x); + buffer_puts(buffer_2, "< exit "); + buffer_puts(buffer_2, fmt); + buffer_puts(buffer_2, "\n"); + buffer_flush(buffer_2); + if (dir && !pack_remove(p, dir)) + log_errsys6("deleting ", dir, "/", p->name, "/", p->ver); + exit(100); } int @@ -96,9 +90,16 @@ main(int argc, char **argv) buffer_puts(buffer_2, " "); buffer_flush(buffer_2); - step(p, "pack-get", log, src); + if (pack_isdone(p, out)) goto step_install; + if (pack_isdone(p, src)) goto step_build; + if (pack_isdone(p, tar)) goto step_tar; + + step(p, "pack-get", log, tar); +step_tar: step(p, "pack-tar", log, src); +step_build: step(p, "pack-build", log, out); +step_install: step(p, "pack-install", log, NULL); buffer_puts(buffer_2, "\n"); buffer_flush(buffer_2); diff --git a/pack-get.c b/pack-get.c @@ -86,14 +86,19 @@ main(int argc, char **argv) buffer_init(&b, &read, fd, buf, sizeof buf); while (stralloc_zero(&sa), (r = buffer_getline(&b, &sa)) > 0) { + char *cmd = NULL; + if (sa.x[sa.n - 1] == '\n') --sa.n; if (!stralloc_cat0(&sa)) die_nomem(); - if (str_start(sa.x, "http://")) if (get(&p, "pack-http", sa.x)) break; - if (str_start(sa.x, "https://")) if (get(&p, "pack-http", sa.x)) break; - if (str_start(sa.x, "git://")) if (get(&p, "pack-git", sa.x)) break; - if (str_start(sa.x, "cvs://")) if (get(&p, "pack-cvs", sa.x)) break; + if (str_start(sa.x, "http://")) cmd = "pack-http"; + if (str_start(sa.x, "https://")) cmd = "pack-http"; + if (str_start(sa.x, "ftp://")) cmd = "pack-ftp"; + if (str_start(sa.x, "ftps://")) cmd = "pack-ftps"; + if (str_start(sa.x, "git://")) cmd = "pack-git"; + if (str_start(sa.x, "cvs://")) cmd = "pack-cvs"; + if (cmd && get(&p, cmd, sa.x)) break; } - if (r < 0) log_errsys1("buffering"); + if (r < 0 || !cmd) log_errsys1("buffering"); stralloc_free(&sa); close(fd); diff --git a/pack.c b/pack.c @@ -169,14 +169,26 @@ pack_hasdep(pack const *p, genalloc *packs) } int -pack_step(pack const *p, char const *cmd, char const *log) +pack_step(pack const *p, char const *cmd, char const *log, char const *dir) { char fmt[PACK_FMT]; char const *argv[] = { NULL, NULL, NULL }; stralloc sa; int ret = -1; - stralloc_init(&sa); + if (dir) + { + stralloc_init(&sa); + if (!stralloc_cats(&sa, dir)) goto err; + if (!stralloc_cats(&sa, "/")) goto err; + if (!stralloc_cats(&sa, p->name)) goto err; + if (!stralloc_cats(&sa, "/")) goto err; + if (!stralloc_cats(&sa, p->ver)) goto err; + if (!stralloc_cat0(&sa)) goto err; + if (!fs_mkdir_r(sa.x, 0640)) goto err; + } + + stralloc_zero(&sa); if (!stralloc_cats(&sa, log)) goto err; if (!stralloc_cats(&sa, "/")) goto err; if (!stralloc_cats(&sa, p->name)) goto err; @@ -186,14 +198,13 @@ pack_step(pack const *p, char const *cmd, char const *log) sa.n--; if (!fs_mkdir_r(sa.x, 0640)) goto err; if (!stralloc_cats(&sa, "/")) goto err; - if (!stralloc_cats(&sa, cmd)) goto err; + if (!stralloc_cats(&sa, cmd + (str_start(cmd, "pack-") ? 5 : 0))) goto err; if (!stralloc_cat0(&sa)) goto err; argv[0] = cmd; pack_fmt(p, fmt); argv[1] = fmt; ret = forkexec_wait_redir(argv, sa.x); - err: stralloc_free(&sa); return ret; @@ -450,3 +461,23 @@ err: stralloc_free(&path); if (fd >= 0) close(fd); return ret; } + +int +pack_isdone(pack const *p, char *dir) +{ + stralloc sa; + int ret = 0; + + stralloc_init(&sa); + if (!stralloc_cats(&sa, dir)) goto err; + if (!stralloc_cats(&sa, "/")) goto err; + if (!stralloc_cats(&sa, p->name)) goto err; + if (!stralloc_cats(&sa, "/")) goto err; + if (!stralloc_cats(&sa, p->ver)) goto err; + if (!stralloc_cat0(&sa)) goto err; + + ret = fs_isdir(sa.x); +err: + stralloc_free(&sa); + return ret; +} diff --git a/pack.h b/pack.h @@ -24,10 +24,11 @@ int pack_dep(pack const *, genalloc *, char const *); int pack_env(pack *, const char *, const char *); int pack_envset(char const *, char const *); int pack_hasdep(pack const *, genalloc *); +int pack_isdone(pack const *, char *); int pack_opendepfile(pack const *, char const *); int pack_patch(pack const *, char *); int pack_remove(pack const *, char const *); -int pack_step(pack const *, char const *, char const *); +int pack_step(pack const *, char const *, char const *, char const *); int pack_version(pack *, char const *); size_t pack_fmt(pack const *, char *); size_t pack_scan(pack *, char const *);