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')
36 # option for "multipackage" just to let the system know that's what you meant
37 # option to take filenames from stdin
38 # parse package, version, release from file if not given
39 # TODO -l follow symlinks, -L follow symlinks, adding all, links and targets
40 while getopts :f:vr:l:P:S:cu:g:N opt; do
43 f) pkgfile="$OPTARG" ;;
44 P) prefix="$OPTARG" ;;
45 S) strip=$(cleanpath "$OPTARG"); ;;
46 t) tags="$tags $OPTARG" ;;
48 u) username="$OPTARG" ;;
49 g) groupname="$OPTARG" ;;
51 *) echo 'unknown option' $OPTARG; exit 1 ;;
56 if [ $isconfig -eq 1 ]; then
57 tags="$tags configuration"
60 if [ $verbose -gt 1 ]; then
66 eval $(zpm parse -E $pkgid)
68 if [ -z "$pkgfile" ]; then
69 pkgfile=$ZPM_PACKAGE_FILE
72 if [ -z "$release" ]; then
73 if [ -z "$pkgfile" ]; then
74 die "cannot determine package file"
76 pkgstr=$(zpm findpkg -f $pkgfile $pkgid)
77 if [ -z "$pkgstr" ]; then
78 die "unable to find package id for $pkgid in $pkgfile"
81 # need to reparse the new package id
82 eval $(zpm parse -E $pkgid)
86 # look for a .zpm file here
87 if [ -z "$pkgfile" ] && [ -f "$pkgid.zpm" ]; then
91 if [ -z "$pkgfile" ]; then
92 die "cannot determine package file"
95 # check for package file
96 if [ ! -f "$pkgfile" ]; then
97 echo $pkgfile does not exist
105 if [ $verbose -gt 0 ]; then
106 echo adding to $pkgfile $pkgid
109 package=$(zpm quote "$name")
110 pkgver=$(zpm quote "$version")
111 pkgrel=$(zpm quote "$release")
113 #strip=$(cleanpath "$strip")
116 mtime=$(zpm stat -f '%y' $path)
117 uid=$(zpm stat -f '%u' $path)
118 gid=$(zpm stat -f '%g' $path)
119 : ${username:=$(zpm stat -f '%U' $path)}
120 : ${groupname:=$(zpm stat -f '%G' $path)}
121 mode=$(zpm stat -f '%a' $path)
124 rpath=$(cleanpath "$path")
126 # strip off leading slash
129 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
133 if [ ! -z "$strip" ]; then
134 echo "stripping $strip"
135 rpath=${rpath#$strip}
139 if [ -z "$rpath" ]; then
140 die "$path resolves to nothing"
143 prefix=$(cleanpath "$prefix")
144 if [ ! -z "$prefix" ]; then
145 rpath="$prefix/$rpath"
148 filetype=$(zpm stat -l -f '%t' "$path")
154 if [ $addcontent -eq 1 ]; then
155 hash=$(zpm addfile $pkgfile "$path")
156 if [ $? -ne 0 ]; then
157 die "zpm addfile failed ($?): $pkgfile $path"
160 hash=$(zpm hash "$path")
169 target=$(readlink $path)
174 # TODO check that we have such a package,version,release
176 zpm shell $pkgfile <<EOS
177 PRAGMA foreign_keys = ON;
179 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
180 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
184 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
185 if [ $verbose -gt 0 ]; then