X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-add;h=c910a1cfd30025ae8b82af825f0f0bc43525c4b0;hb=090abacfef5458a521c154ba735f5b84cea3724d;hp=68c986dbfc05a365a3dadce4c2804296efd683fe;hpb=fc0e2fbaf7051e42be1a6449a5a004fb3e665d45;p=zpackage diff --git a/zpm-add b/zpm-add index 68c986d..c910a1c 100755 --- a/zpm-add +++ b/zpm-add @@ -7,8 +7,8 @@ # no id impossible die() { - echo $* 1>&2 - exit 1 + echo "$@" 1>&2 + exit 255 } # basic cleanup on a path @@ -34,12 +34,17 @@ tags= isconfig=0 addcontent=1 complete=0 -mode= +noclear=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 # TODO -l follow symlinks, -L follow symlinks, adding all, links and targets -while getopts :f:vr:l:P:S:cu:g:NC opt; do +# -T set link target +# -M set mtime +# -m set mode +# -H set hash, will be overridden for regular files unless -N is set +# -F set filetype, regular, symlink, directory +while getopts :f:vr:l:P:S:cu:g:NCm:M:T:H:F:z opt; do case $opt in N) addcontent=0 ;; f) pkgfile="$OPTARG" ;; @@ -47,12 +52,17 @@ while getopts :f:vr:l:P:S:cu:g:NC opt; do S) strip=$(cleanpath "$OPTARG"); ;; t) tags="$tags $OPTARG" ;; c) isconfig=1 ;; - u) username="$OPTARG" ;; - g) groupname="$OPTARG" ;; - m) mode="$OPTARG" ;; + u) cluser="$OPTARG" ;; + g) clgroup="$OPTARG" ;; + m) clmode="$OPTARG" ;; + M) clmtime="$OPTARG" ;; + T) cltarget="$OPTARG" ;; + F) cltype="$OPTARG" ;; + H) clhash="$OPTARG" ;; v) verbose=$((verbose + 1)) ;; C) complete=1 ;; - *) echo 'unknown option' $OPTARG; exit 1 ;; + z) noclear=1 ;; + *) echo 'unknown option' $OPTARG; exit 255 ;; esac done shift $((OPTIND - 1)) @@ -98,8 +108,7 @@ fi # check for package file if [ ! -f "$pkgfile" ]; then - echo $pkgfile does not exist - exit 1 + die $pkgfile does not exist fi set -e @@ -115,20 +124,18 @@ pkgver=$(zpm quote "$version") pkgrel=$(zpm quote "$release") #strip=$(cleanpath "$strip") -for path in $*; do +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) - - if [ -z "$mode" ]; then - mode=$(zpm stat -f '%a' $path) - fi +if [ $verbose -gt 1 ]; then + printf "adding %s\n" "$path" +fi - # only stat the file for the user and group name if not set on the - # command line - : ${username:=$(zpm stat -f '%U' $path)} - : ${groupname:=$(zpm stat -f '%G' $path)} + # only stat the file for items not set on the command line + mode=${clmode:-$(zpm stat -l -f '%a' "$path")} + username=${cluser:-$(zpm stat -l -f '%U' "$path")} + groupname=${clgroup:-$(zpm stat -l -f '%G' "$path")} + mtime=${clmtime:-$(zpm stat -l -f '%y' "$path")} + filetype=${cltype:-$(zpm stat -l -f '%t' "$path")} rpath="$path" @@ -158,7 +165,6 @@ for path in $*; do # ensure all paths are absolute rpath=/${rpath#/} - filetype=$(zpm stat -l -f '%t' "$path") hash='NULL' target='NULL' case "$filetype" in @@ -170,7 +176,11 @@ for path in $*; do die "zpm addfile failed ($?): $pkgfile $path" fi else - hash=$(zpm hash "$path") + if [ -z "$clhash" ]; then + hash=$(zpm hash "$path") + else + hash=$clhash + fi fi hash="'$hash'" ;; @@ -179,25 +189,40 @@ for path in $*; do ;; symlink) filetype=l - target=$(readlink $path) - target="'$target'" + if [ -n "$cltarget" ]; then + target=$cltarget + else + target=$(readlink $path) + target=$(zpm quote -q "$target") + fi + ;; + *) + die "filetype $filetype not supported" ;; esac # TODO check that we have such a package,version,release #cat < $target"} if [ $verbose -gt 1 ]; then - printf "%s%s %s:%s %s\n" $filetype $mode $username $groupname $path + printf "%s%s %s:%s %s\n" $filetype $mode $username $groupname "$path" elif [ $verbose -gt 0 ]; then - printf "%s\n" $path + printf "%s\n" "$path" fi done @@ -205,6 +230,11 @@ done if [ $complete -eq 1 ]; then zpm pkg -f $pkgfile $pkgid build_time=$(date +'%s') zpm packagehash -f $pkgfile -s -q $pkgid -else +elif [ $noclear -eq 0 ]; then zpm pkg -f $pkgfile $pkgid hash= + rv=$? + if [ $rv -ne 0 ]; then + die clearing packagehash failed + fi fi +exit 0