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')
35 # option for "multipackage" just to let the system know that's what you meant
36 # option to take filenames from stdin
37 # parse package, version, release from file if not given
38 while getopts :f:vr:l:P:S:cu:g: opt; do
40 f) pkgfile="$OPTARG" ;;
41 P) prefix="$OPTARG" ;;
42 S) strip=$(cleanpath "$OPTARG"); ;;
43 t) tags="$tags $OPTARG" ;;
45 u) username="$OPTARG" ;;
46 g) groupname="$OPTARG" ;;
48 *) echo 'unknown option' $OPTARG; exit 1 ;;
53 if [ $isconfig -eq 1 ]; then
54 tags="$tags configuration"
57 if [ $verbose -gt 1 ]; then
63 eval $(zpm parse -E $pkgid)
65 if [ -z "$pkgfile" ]; then
66 pkgfile=$ZPM_PACKAGE_FILE
69 if [ -z "$release" ]; then
70 if [ -z "$pkgfile" ]; then
71 die "cannot determine package file"
73 pkgstr=$(zpm findpkg $pkgfile $pkgid)
74 if [ -z "$pkgstr" ]; then
75 die "unable to find package id for $pkgid in $pkgfile"
78 # need to reparse the new package id
79 eval $(zpm parse -E $pkgid)
83 # look for a .zpm file here
84 if [ -z "$pkgfile" ] && [ -f "$pkgid.zpm" ]; then
88 if [ -z "$pkgfile" ]; then
89 die "cannot determine package file"
92 # check for package file
93 if [ ! -f "$pkgfile" ]; then
94 echo $pkgfile does not exist
102 if [ $verbose -gt 0 ]; then
103 echo adding to $pkgfile $pkgid
106 package=$(zpm quote "$name")
107 pkgver=$(zpm quote "$version")
108 pkgrel=$(zpm quote "$release")
110 #strip=$(cleanpath "$strip")
113 mtime=$(zpm stat -f '%y' $path)
114 uid=$(zpm stat -f '%u' $path)
115 gid=$(zpm stat -f '%g' $path)
116 : ${username:=$(zpm stat -f '%U' $path)}
117 : ${groupname:=$(zpm stat -f '%G' $path)}
118 mode=$(zpm stat -f '%a' $path)
121 rpath=$(cleanpath "$path")
123 # strip off leading slash
126 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
130 if [ ! -z "$strip" ]; then
131 echo "stripping $strip"
132 rpath=${rpath#$strip}
136 if [ -z "$rpath" ]; then
137 die "$path resolves to nothing"
140 prefix=$(cleanpath "$prefix")
141 if [ ! -z "$prefix" ]; then
142 rpath="$prefix/$rpath"
145 filetype=$(zpm stat -f '%t' "$path")
151 hash=$(zpm addfile $pkgfile "$path")
152 if [ $? -ne 0 ]; then
153 die "zpm addfile failed ($?): $pkgfile $path"
162 target=$(readlink $path)
167 # TODO check that we have such a package,version,release
169 zpm shell $pkgfile <<EOS
170 PRAGMA foreign_keys = ON;
172 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
173 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
177 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}