#!/bin/sh 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:S: 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" ;; S) strip=$(cleanpath "$OPTARG"); ;; t) tags="$OPTARG" ;; c) tags="$tags +configuration" ;; 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 # make sure package exists 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) gid=$(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" 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 rpath="$prefix/$rpath" fi filetype=$(zpm stat -f '%t' "$path") hash='NULL' target='NULL' case "$filetype" in regular) filetype=r hash=$(zpm addfile $pkgfile "$path") if [ $? -ne 0 ]; then die "zpm addfile failed ($?): $pkgfile $path" fi hash="'$hash'" ;; directory) filetype=d ;; symlink) filetype=l target=$(readlink $path) target="'$target'" ;; esac zpm shell $pkgfile < $target"} printf "%s\n" $path done