X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-addtopackage;h=1b7bff4d3296d34e15cb08544709f98d7646569b;hb=7cc581729bb4b242c803299f72eed987b9fee216;hp=cccd12de666d3ce2c0574207583f2120401448db;hpb=cb319777926fbee07c96a5f28aacb243f3e6353d;p=zpackage diff --git a/zpm-addtopackage b/zpm-addtopackage index cccd12d..1b7bff4 100755 --- a/zpm-addtopackage +++ b/zpm-addtopackage @@ -1,62 +1,110 @@ #!/bin/sh -package=${1:-$ZPMPACKAGE} -shift pkgver=${ZPMPKGVER:-1.0} pkgrel=${ZPMPKGREL:-1} +die() { + echo $* 1>&2 + exit 1 +} + +# basic cleanup on a path +cleanpath() { + clean="$1" + if [ -z "$clean" ]; then printf ''; fi + + # multiple slashes + clean=$(printf "%s" "$clean" | sed -e 's|/+|/|g') + # curdir + clean=$(printf "%s" "$clean" | sed -e 's|/\./|/|g') + # leading curdir + clean=${clean#./} + # trailing curdir + clean=${clean%/.} + # trailing slash + clean=${clean%/} + printf "%s" "$clean" +} + +tags= +create=0 # option for "multipackage" just to let the system know that's what you meant # option to take filenames from stdin # parse package, version, release from file if not given -while getopts :f:v:r:d:a:u:l:p:b:P: opt; do +while getopts :f:v:r:l:P:S:Ccu:g: opt; do case $opt in f) pkgfile="$OPTARG" ;; v) pkgver="$OPTARG" ;; r) pkgrel="$OPTARG" ;; - d) description="$OPTARG" ;; - a) arch="$OPTARG" ;; - u) url="$OPTARG" ;; l) licenses="$OPTARG" ;; - p) packager="$OPTARG" ;; - b) builddate="$OPTARG" ;; P) prefix="$OPTARG" ;; - t) tags="$OPTARG" ;; - c) tags="$tags +configuration" ;; + S) strip=$(cleanpath "$OPTARG"); ;; + t) tags="$tags $OPTARG" ;; + c) tags="$tags configuration" ;; + C) create=1 ;; + u) username="$OPTARG" ;; + g) groupname="$OPTARG" ;; + *) echo 'unknown option' $opt; exit 1 ;; esac done +shift $((OPTIND - 1)) + +package="$1" +shift +if [ -z "$package" ]; then + die "must specify package" +fi set -e if [ -z "$pkgfile" ]; then pkgfile="$package-$pkgver-$pkgrel.zpm" fi -if [ ! -f $pkgfile ]; then - zpm newpackage $package || exit 1 -else - zpm-test -v $pkgfile +# check for package file +if [ ! -f "$pkgfile" ]; then + if [ $create -eq 1 ]; then + echo creating $pkgfile + zpm newpackage -I -f $pkgfile -v $pkgver -r $pkgrel $package || exit 1 + else + echo $pkgfile does not exist + exit 1 + fi fi +zpm test -v $pkgfile + +#strip=$(cleanpath "$strip") for path in $*; do + #echo adding $path mtime=$(zpm stat -f '%y' $path) uid=$(zpm stat -f '%u' $path) gid=$(zpm stat -f '%g' $path) - username=$(zpm stat -f '%U' $path) - groupname=$(zpm stat -f '%G' $path) + : ${username:=$(zpm stat -f '%U' $path)} + : ${groupname:=$(zpm stat -f '%G' $path)} mode=$(zpm stat -f '%a' $path) + rpath="$path" - # strip off leading slashes - rpath=$(echo "$path" | sed -e 's|^/*||') - # and a leading ./ - rpath=${rpath#./} - rpath=$(echo "$rpath" | sed -e 's|^/*||') + rpath=$(cleanpath "$path") + + # strip off leading slash + rpath=${rpath#/} if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then continue fi + if [ ! -z "$strip" ]; then + echo "stripping $strip" + rpath=${rpath#$strip} + rpath=${rpath#/} + fi + + if [ -z "$rpath" ]; then + die "$path resolves to nothing" + fi + + prefix=$(cleanpath "$prefix") if [ ! -z "$prefix" ]; then - # trailing slashes on prefix - prefix=$(echo "$prefix" | sed -e 's|/*$||') rpath="$prefix/$rpath" fi @@ -65,10 +113,12 @@ for path in $*; do target='NULL' case "$filetype" in regular) - filetype=d + filetype=r hash=$(zpm addfile $pkgfile "$path") + if [ $? -ne 0 ]; then + die "zpm addfile failed ($?): $pkgfile $path" + fi hash="'$hash'" - filetype=r ;; directory) filetype=d @@ -80,7 +130,8 @@ for path in $*; do ;; esac - sqlite3 $pkgfile <