package

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

commit 09e9642f2040cd5fc9fae68d147625d1fd7be456
parent b1feacc60da23576363d8a3d2211a8282fc56ee7
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon,  7 Jan 2019 01:38:48 +0100

version 0.0

Diffstat:
MMakefile | 12+++++++++---
Abin/pack-add | 28++++++++++++++++++++++++++++
Abin/pack-cvs | 15+++++++++++++++
Abin/pack-extract | 8++++++++
Abin/pack-ftp | 12++++++++++++
Abin/pack-get | 19+++++++++++++++++++
Abin/pack-git | 14++++++++++++++
Abin/pack-http | 12++++++++++++
Abin/pack-install | 12++++++++++++
Abin/pack-tar | 14++++++++++++++
Mfs.c | 27++++++++++++---------------
Mfs.h | 2+-
12 files changed, 156 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile @@ -5,6 +5,12 @@ all: pack-build pack-dep clean: rm -f *.o leapsecs leapsecs.dat +.PHONY: install +install: all + mkdir -p ${PREFIX} + cp -r bin ${PREFIX} + cp pack-build pack-dep ${PREFIX}/bin + pack-build-o = pack-build.o pack.o buffer.o fmt.o fs.o log.o mem.o str.o stralloc.o pack-build: ${pack-build-o} ./make-bin $@ ${pack-build-o} @@ -21,8 +27,8 @@ fmt.o: fmt.c fmt.h str.h fs.o: fs.c fs.h mem.h open.h str.h stralloc.h log.o: log.c buffer.h log.h mem.o: mem.c mem.h -pack-build.o: pack-build.c env.h log.h pack.h str.h -pack-dep.o: pack-dep.c env.h log.h pack.h str.h -pack.o: pack.c buffer.h fs.h mem.h open.h pack.h stralloc.h +pack-build.o: pack-build.c buffer.h env.h fs.h log.h pack.h str.h +pack-dep.o: pack-dep.c genalloc.h env.h log.h pack.h str.h buffer.h +pack.o: pack.c buffer.h env.h fs.h genalloc.h mem.h open.h pack.h stralloc.h str.o: str.c str.h stralloc.o: stralloc.c mem.h fmt.h str.h stralloc.h diff --git a/bin/pack-add b/bin/pack-add @@ -0,0 +1,28 @@ +#!/bin/sh -e +PACK_LOG=${PACK_LOG:-/var/log/pack} + +test $# -gt 0 + +trap echo INT TERM EXIT + +pack-dep "$@" | while IFS=/ read -r pack version; do + printf ' %-30s %-15s' "$pack" "$version" + + mkdir -p "$PACK_LOG/$pack/$version" + + printf ' get ' + pack-get "$pack" "$version" >$PACK_LOG/$pack/$version/get 2>&1 + + printf ' tar ' + pack-tar "$pack" "$version" >$PACK_LOG/$pack/$version/tar 2>&1 + + printf ' build ' + pack-build "$pack/$version" >$PACK_LOG/$pack/$version/build 2>&1 + + printf ' install ' + pack-install "$pack" "$version" >$PACK_LOG/$pack/$version/install 2>&1 + + echo +done + +trap - INT TERM EXIT diff --git a/bin/pack-cvs b/bin/pack-cvs @@ -0,0 +1,15 @@ +#!/bin/sh -e +PACK=${PACK:-/var/pack} +IFS=/; set -- $1; IFS= +pack=$1 +version=${2:-$(sed q "/etc/pack/$1/default/version")} +url=$3 + +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 diff --git a/bin/pack-extract b/bin/pack-extract @@ -0,0 +1,8 @@ +#!/bin/sh -e + +case $1 in +(*.tgz|*.tar.gz) gzip -d - ;; +(*.tbz|*.tar.bz2) bzip2 -d - ;; +(*.txz|*.tar.xz) xz -d - ;; +(*.tlz|*.tar.lz) lzip -d - ;; +esac diff --git a/bin/pack-ftp b/bin/pack-ftp @@ -0,0 +1,12 @@ +#!/bin/sh -e +PACK=${PACK:-/var/pack} +pack=$1 +version=${2:-$(sed q "/etc/pack/$1/version")} +url=$3 + +trap "rm -f '$PACK/tar/$pack/$version.tar'" INT TERM EXIT + +mkdir -p "$PACK/src/$pack/$version" "$PACK/tar/$pack" +wget -O- "$url" | pack-extract "$url" >$PACK/tar/$pack/$version.tar + +trap - INT TERM EXIT diff --git a/bin/pack-get b/bin/pack-get @@ -0,0 +1,19 @@ +#!/bin/sh -e +PACK=${PACK:-/var/pack} +IFS=/; set -- $1; IFS= +pack=$1 +version=${2:-$(sed q "/etc/pack/$1/default/version")} + +if [ -d "$PACK/src/$pack/$version" ]; then exit 0; fi +mkdir -p "$PACK/log/$pack/$version" +exec >$PACK/log/$pack/$version/get 2>&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 </etc/pack/$pack/$version/uri diff --git a/bin/pack-git b/bin/pack-git @@ -0,0 +1,14 @@ +#!/bin/sh -e +PACK=${PACK:-/var/pack} +pack=$1 +version=$2 +uri=$3 + +if [ -d "$PACK/git/$pack/$version" ]; then exit 0; fi +trap "rm -rf '$PACK/git/$pack/$version' '$PACK/tar/$pack/$version.tar'" INT TERM EXIT + +mkdir -p "$PACK/git/$pack" "$PACK/tar/$pack" +git clone --bare "$url" "$PACK/git/$pack/$version" +git -C "$PACK/git/$pack/$version" archive master >$PACK/tar/$pack/$version.tar + +trap - INT TERM EXIT diff --git a/bin/pack-http b/bin/pack-http @@ -0,0 +1,12 @@ +#!/bin/sh -e +PACK=${PACK:-/var/pack} +pack=$1 version=${2:-$(sed q "/etc/pack/$1/version")} url=$3 + +trap "rm -f '/etc/pack/tar/$pack/$version.tar'" INT TERM EXIT + +mkdir -p "$PACK/src/$pack/$version" "$PACK/tar/$pack" +if [ ! -f "$PACK/tar/$pack/$version.tar" ]; then + wget --no-check-certificate -O- "$url" | pack-extract "$url" >/var/pack/tar/$pack/$version.tar +fi + +trap - INT TERM EXIT diff --git a/bin/pack-install b/bin/pack-install @@ -0,0 +1,12 @@ +#!/bin/sh -e +PACK=${PACK:-/var/pack} +pack=$1 +version=$2 + +mkdir -p "$PACK/bin" +mkdir -p "$PACK/man" +cd "$PACK/pkg/$pack/$version" + +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 diff --git a/bin/pack-tar b/bin/pack-tar @@ -0,0 +1,14 @@ +#!/bin/sh -e +PACK=${PACK:-/var/pack} +pack=$1 version=${2:-$(sed q "/etc/pack/$1/version")} + +trap "rm -rf '$PACK/src/$pack/$version'" EXIT TERM INT + +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 +fi + +trap - EXIT TERM INT diff --git a/fs.c b/fs.c @@ -10,17 +10,16 @@ #include "stralloc.h" int -fs_mkdirr(char *dir) +fs_mkdirr(char *dir, unsigned int mode) { char *d = dir + (*dir == '/'); - int end = 0; + size_t n = 0; - while (!end) { - d += str_chr(d, '/'); - if (*d == '\0') end = 1; + while (d[n] != '\0') { + d += n = str_chr(d, '/'); *d = '\0'; - if (mkdir(dir, 0600) == -1 && errno != EEXIST) return 0; + if (mkdir(dir, mode) == -1 && errno != EEXIST) return 0; *d = '/'; } @@ -45,6 +44,7 @@ fs_rmdirr_recurse(stralloc *path) if (str_equal(de->d_name, ".")) continue; if (str_equal(de->d_name, "..")) continue; + path->n = n; if (!stralloc_cats(path, de->d_name)) break; if (!stralloc_append(path, '\0')) break; @@ -56,8 +56,6 @@ fs_rmdirr_recurse(stralloc *path) } else { if (unlink(path->x) == -1) break; } - - path->n = n; } closedir(dp); @@ -124,28 +122,27 @@ fs_copyr_recurse(stralloc *from, stralloc *to) if (str_equal(de->d_name, ".")) continue; if (str_equal(de->d_name, "..")) continue; + from->n = from_n; if (!stralloc_cats(from, de->d_name)) break; if (!stralloc_append(from, '\0')) break; + to->n = to_n; if (!stralloc_cats(to, de->d_name)) break; if (!stralloc_append(to, '\0')) break; if (lstat(from->x, &st) == -1) break; + if (lstat(to->x, &st) == -1) break; if (S_ISDIR(st.st_mode)) { + if (lstat(to->x, &st) == 0) continue; if (mkdir(to->x, st.st_mode) == -1) break; if (!fs_copyr_recurse(from, to)) break; - } - if (S_ISREG(st.st_mode)) { + } else if (S_ISREG(st.st_mode)) { if (!fs_copy(from->x, to->x, st.st_mode)) break; - } - if (S_ISLNK(st.st_mode)) { + } else if (S_ISLNK(st.st_mode)) { if (readlink(from->x, ln, sizeof ln) == -1) break; if (symlink(ln, to->x) == -1) break; } else break; - - from->n = from_n; - to->n = to_n; } closedir(dp); diff --git a/fs.h b/fs.h @@ -3,7 +3,7 @@ int fs_copy(char const *, char const *, unsigned int); int fs_copyr(char const *, char const *); -int fs_mkdirr(char *); +int fs_mkdirr(char *, unsigned int); int fs_rmdirr(char const *); #endif