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 # TODO -l follow symlinks, -L follow symlinks, adding all, links and targets
39 while getopts :f:vr:l:P:S:cu:g: opt; do
41 f) pkgfile="$OPTARG" ;;
42 P) prefix="$OPTARG" ;;
43 S) strip=$(cleanpath "$OPTARG"); ;;
44 t) tags="$tags $OPTARG" ;;
46 u) username="$OPTARG" ;;
47 g) groupname="$OPTARG" ;;
49 *) echo 'unknown option' $OPTARG; exit 1 ;;
54 if [ $isconfig -eq 1 ]; then
55 tags="$tags configuration"
58 if [ $verbose -gt 1 ]; then
64 eval $(zpm parse -E $pkgid)
66 if [ -z "$pkgfile" ]; then
67 pkgfile=$ZPM_PACKAGE_FILE
70 if [ -z "$release" ]; then
71 if [ -z "$pkgfile" ]; then
72 die "cannot determine package file"
74 pkgstr=$(zpm findpkg -f $pkgfile $pkgid)
75 if [ -z "$pkgstr" ]; then
76 die "unable to find package id for $pkgid in $pkgfile"
79 # need to reparse the new package id
80 eval $(zpm parse -E $pkgid)
84 # look for a .zpm file here
85 if [ -z "$pkgfile" ] && [ -f "$pkgid.zpm" ]; then
89 if [ -z "$pkgfile" ]; then
90 die "cannot determine package file"
93 # check for package file
94 if [ ! -f "$pkgfile" ]; then
95 echo $pkgfile does not exist
103 if [ $verbose -gt 0 ]; then
104 echo adding to $pkgfile $pkgid
107 package=$(zpm quote "$name")
108 pkgver=$(zpm quote "$version")
109 pkgrel=$(zpm quote "$release")
111 #strip=$(cleanpath "$strip")
114 mtime=$(zpm stat -f '%y' $path)
115 uid=$(zpm stat -f '%u' $path)
116 gid=$(zpm stat -f '%g' $path)
117 : ${username:=$(zpm stat -f '%U' $path)}
118 : ${groupname:=$(zpm stat -f '%G' $path)}
119 mode=$(zpm stat -f '%a' $path)
122 rpath=$(cleanpath "$path")
124 # strip off leading slash
127 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
131 if [ ! -z "$strip" ]; then
132 echo "stripping $strip"
133 rpath=${rpath#$strip}
137 if [ -z "$rpath" ]; then
138 die "$path resolves to nothing"
141 prefix=$(cleanpath "$prefix")
142 if [ ! -z "$prefix" ]; then
143 rpath="$prefix/$rpath"
146 filetype=$(zpm stat -l -f '%t' "$path")
152 hash=$(zpm addfile $pkgfile "$path")
153 if [ $? -ne 0 ]; then
154 die "zpm addfile failed ($?): $pkgfile $path"
163 target=$(readlink $path)
168 # TODO check that we have such a package,version,release
170 zpm shell $pkgfile <<EOS
171 PRAGMA foreign_keys = ON;
173 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
174 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
178 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
179 if [ $verbose -gt 0 ]; then