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')
38 # option for "multipackage" just to let the system know that's what you meant
39 # option to take filenames from stdin
40 # parse package, version, release from file if not given
41 # TODO -l follow symlinks, -L follow symlinks, adding all, links and targets
42 while getopts :f:vr:l:P:S:cu:g:NC opt; do
45 f) pkgfile="$OPTARG" ;;
46 P) prefix="$OPTARG" ;;
47 S) strip=$(cleanpath "$OPTARG"); ;;
48 t) tags="$tags $OPTARG" ;;
50 u) username="$OPTARG" ;;
51 g) groupname="$OPTARG" ;;
53 v) verbose=$((verbose + 1)) ;;
55 *) echo 'unknown option' $OPTARG; exit 1 ;;
60 if [ $isconfig -eq 1 ]; then
61 tags="$tags configuration"
64 if [ $verbose -gt 2 ]; then
70 eval $(zpm parse -E $pkgid)
72 if [ -z "$pkgfile" ]; then
73 pkgfile=$ZPM_PACKAGE_FILE
76 if [ -z "$release" ]; then
77 if [ -z "$pkgfile" ]; then
78 die "cannot determine package file"
80 pkgstr=$(zpm findpkg -f $pkgfile $pkgid)
81 if [ -z "$pkgstr" ]; then
82 die "unable to find package id for $pkgid in $pkgfile"
85 # need to reparse the new package id
86 eval $(zpm parse -E $pkgid)
90 # look for a .zpm file here
91 if [ -z "$pkgfile" ] && [ -f "$pkgid.zpm" ]; then
95 if [ -z "$pkgfile" ]; then
96 die "cannot determine package file"
99 # check for package file
100 if [ ! -f "$pkgfile" ]; then
101 echo $pkgfile does not exist
109 if [ $verbose -gt 0 ]; then
110 echo adding to $pkgfile $pkgid
113 package=$(zpm quote "$name")
114 pkgver=$(zpm quote "$version")
115 pkgrel=$(zpm quote "$release")
117 #strip=$(cleanpath "$strip")
120 mtime=$(zpm stat -f '%y' $path)
121 uid=$(zpm stat -f '%u' $path)
122 gid=$(zpm stat -f '%g' $path)
124 if [ -z "$mode" ]; then
125 mode=$(zpm stat -f '%a' $path)
128 # only stat the file for the user and group name if not set on the
130 : ${username:=$(zpm stat -f '%U' $path)}
131 : ${groupname:=$(zpm stat -f '%G' $path)}
135 rpath=$(cleanpath "$path")
137 # strip off leading slash
140 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
144 if [ ! -z "$strip" ]; then
145 rpath=${rpath#$strip}
149 if [ -z "$rpath" ]; then
150 die "$path resolves to nothing"
153 prefix=$(cleanpath "$prefix")
154 if [ ! -z "$prefix" ]; then
155 rpath="$prefix/$rpath"
158 # ensure all paths are absolute
161 filetype=$(zpm stat -l -f '%t' "$path")
167 if [ $addcontent -eq 1 ]; then
168 hash=$(zpm addfile $pkgfile "$path")
169 if [ $? -ne 0 ]; then
170 die "zpm addfile failed ($?): $pkgfile $path"
173 hash=$(zpm hash "$path")
182 target=$(readlink $path)
187 # TODO check that we have such a package,version,release
189 zpm shell $pkgfile <<EOS
191 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,configuration,target)
192 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$isconfig,$target);
196 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
197 if [ $verbose -gt 1 ]; then
198 printf "%s%s %s:%s %s\n" $filetype $mode $username $groupname $path
199 elif [ $verbose -gt 0 ]; then
205 if [ $complete -eq 1 ]; then
206 zpm pkg -f $pkgfile $pkgid build_time=$(date +'%s')
207 zpm packagehash -f $pkgfile -s -q $pkgid
209 zpm pkg -f $pkgfile $pkgid hash=