X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-addtopackage;h=9c66169547a7d31a4a6812cd789473ebc59a304e;hb=d3b90e6aa8ab580c77ead76ff5c6c6dca7991cc6;hp=a3b045b04c8f9330751a89a778c301dfe451bff5;hpb=c4b62e2fc6674d790be58f841221de49bdb4d00a;p=zpackage diff --git a/zpm-addtopackage b/zpm-addtopackage index a3b045b..9c66169 100755 --- a/zpm-addtopackage +++ b/zpm-addtopackage @@ -3,10 +3,33 @@ 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" +} + # 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:d:a:u:l:p:b:P:S: opt; do case $opt in f) pkgfile="$OPTARG" ;; v) pkgver="$OPTARG" ;; @@ -18,17 +41,13 @@ while getopts :f:v:r:d:a:u:l:p:b:P: opt; do p) packager="$OPTARG" ;; b) builddate="$OPTARG" ;; P) prefix="$OPTARG" ;; + S) strip=$(cleanpath "$OPTARG"); ;; t) tags="$OPTARG" ;; c) tags="$tags +configuration" ;; esac done shift $((OPTIND - 1)) -die() { - echo $* 1&>2 - exit 1 -} - package="$1" shift if [ -z "$package" ]; then @@ -45,6 +64,7 @@ zpm newpackage -I -f $pkgfile -v $pkgver -r $pkgrel $package || exit 1 zpm test -v $pkgfile +#strip=$(cleanpath "$strip") for path in $*; do mtime=$(zpm stat -f '%y' $path) uid=$(zpm stat -f '%u' $path) @@ -52,20 +72,29 @@ for path in $*; do username=$(zpm stat -f '%U' $path) groupname=$(zpm stat -f '%G' $path) mode=$(zpm stat -f '%a' $path) + rpath="$path" + + rpath=$(cleanpath "$path") - # strip off leading slashes - rpath=$(echo "$path" | sed -e 's|^/*||') - # and a leading ./ - rpath=${rpath#./} - rpath=$(echo "$rpath" | sed -e 's|^/*||') + # 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