3 # zpm add -f pkgfile pkgid [ files ]
5 # no package file? take from ZPM_PACKAGE_FILE
6 # no pkgid ? take from ZPM_PACKAGE_ID
14 # basic cleanup on a path
17 if [ -z "$clean" ]; then printf ''; fi
20 clean=$(printf "%s" "$clean" | sed -e 's|/+|/|g')
22 clean=$(printf "%s" "$clean" | sed -e 's|/\./|/|g')
34 # option for "multipackage" just to let the system know that's what you meant
35 # option to take filenames from stdin
36 # parse package, version, release from file if not given
37 while getopts :f:v:r:l:P:S:cu:g: opt; do
39 f) pkgfile="$OPTARG" ;;
40 P) prefix="$OPTARG" ;;
41 S) strip=$(cleanpath "$OPTARG"); ;;
42 t) tags="$tags $OPTARG" ;;
44 u) username="$OPTARG" ;;
45 g) groupname="$OPTARG" ;;
46 *) echo 'unknown option' $opt; exit 1 ;;
51 if [ $isconfig -eq 1 ]; then
52 tags="$tags configuration"
58 eval $(zpm parse -E $pkgid)
61 pkgfile=$ZPM_PACKAGE_FILE
64 # look for a .zpm file here
65 if [ -z "$pkgfile" ] && [ -n "$release" ] && [ -f "$pkgid.zpm" ];
69 if [ -z "$pkgfile" ]; then
70 die "cannot determine package file"
75 # check for package file
76 if [ ! -f "$pkgfile" ]; then
77 echo $pkgfile does not exist
83 if [ -z "$release" ]; then
84 pkgstr=$(zpm findpkg -f $pkgfile $pkgid)
87 if [ -z "$pkgstr" ]; then
88 die "unable to find package id for $pkgid"
92 #strip=$(cleanpath "$strip")
95 mtime=$(zpm stat -f '%y' $path)
96 uid=$(zpm stat -f '%u' $path)
97 gid=$(zpm stat -f '%g' $path)
98 : ${username:=$(zpm stat -f '%U' $path)}
99 : ${groupname:=$(zpm stat -f '%G' $path)}
100 mode=$(zpm stat -f '%a' $path)
103 rpath=$(cleanpath "$path")
105 # strip off leading slash
108 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
112 if [ ! -z "$strip" ]; then
113 echo "stripping $strip"
114 rpath=${rpath#$strip}
118 if [ -z "$rpath" ]; then
119 die "$path resolves to nothing"
122 prefix=$(cleanpath "$prefix")
123 if [ ! -z "$prefix" ]; then
124 rpath="$prefix/$rpath"
127 filetype=$(zpm stat -f '%t' "$path")
133 hash=$(zpm addfile $pkgfile "$path")
134 if [ $? -ne 0 ]; then
135 die "zpm addfile failed ($?): $pkgfile $path"
144 target=$(readlink $path)
149 # TODO check that we have such a package,version,release
150 zpm shell $pkgfile <<EOS
151 PRAGMA foreign_keys = ON;
153 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
154 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
158 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}