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"
57 eval $(zpm parse -E $pkgid)
59 if [ -z "$pkgfile" ]; then
60 pkgfile=$ZPM_PACKAGE_FILE
63 if [ -z "$release" ]; then
64 if [ -z "$pkgfile" ]; then
65 die "cannot determine package file"
67 pkgstr=$(zpm findpkg $pkgfile $pkgid)
68 if [ -z "$pkgstr" ]; then
69 die "unable to find package id for $pkgid in $pkgfile"
72 # need to reparse the new package id
73 eval $(zpm parse -E $pkgid)
77 # look for a .zpm file here
78 if [ -z "$pkgfile" ] && [ -f "$pkgid.zpm" ]; then
82 if [ -z "$pkgfile" ]; then
83 die "cannot determine package file"
88 # check for package file
89 if [ ! -f "$pkgfile" ]; then
90 echo $pkgfile does not exist
96 package=$(zpm quote "$name")
97 pkgver=$(zpm quote "$version")
98 pkgrel=$(zpm quote "$release")
100 #strip=$(cleanpath "$strip")
103 mtime=$(zpm stat -f '%y' $path)
104 uid=$(zpm stat -f '%u' $path)
105 gid=$(zpm stat -f '%g' $path)
106 : ${username:=$(zpm stat -f '%U' $path)}
107 : ${groupname:=$(zpm stat -f '%G' $path)}
108 mode=$(zpm stat -f '%a' $path)
111 rpath=$(cleanpath "$path")
113 # strip off leading slash
116 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
120 if [ ! -z "$strip" ]; then
121 echo "stripping $strip"
122 rpath=${rpath#$strip}
126 if [ -z "$rpath" ]; then
127 die "$path resolves to nothing"
130 prefix=$(cleanpath "$prefix")
131 if [ ! -z "$prefix" ]; then
132 rpath="$prefix/$rpath"
135 filetype=$(zpm stat -f '%t' "$path")
141 hash=$(zpm addfile $pkgfile "$path")
142 if [ $? -ne 0 ]; then
143 die "zpm addfile failed ($?): $pkgfile $path"
152 target=$(readlink $path)
157 # TODO check that we have such a package,version,release
159 zpm shell $pkgfile <<EOS
160 PRAGMA foreign_keys = ON;
162 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
163 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
167 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}