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')
37 # option for "multipackage" just to let the system know that's what you meant
38 # option to take filenames from stdin
39 # parse package, version, release from file if not given
40 # TODO -l follow symlinks, -L follow symlinks, adding all, links and targets
44 # -H set hash, will be overridden for regular files unless -N is set
45 # -F set filetype, regular, symlink, directory
46 while getopts :f:vr:l:P:S:cu:g:NCm:M:T:H:F: opt; do
49 f) pkgfile="$OPTARG" ;;
50 P) prefix="$OPTARG" ;;
51 S) strip=$(cleanpath "$OPTARG"); ;;
52 t) tags="$tags $OPTARG" ;;
54 u) cluser="$OPTARG" ;;
55 g) clgroup="$OPTARG" ;;
56 m) clmode="$OPTARG" ;;
57 M) clmtime="$OPTARG" ;;
58 T) cltarget="$OPTARG" ;;
59 F) cltype="$OPTARG" ;;
60 H) clhash="$OPTARG" ;;
61 v) verbose=$((verbose + 1)) ;;
63 *) echo 'unknown option' $OPTARG; exit 1 ;;
68 if [ $isconfig -eq 1 ]; then
69 tags="$tags configuration"
72 if [ $verbose -gt 2 ]; then
78 eval $(zpm parse -E $pkgid)
80 if [ -z "$pkgfile" ]; then
81 pkgfile=$ZPM_PACKAGE_FILE
84 if [ -z "$release" ]; then
85 if [ -z "$pkgfile" ]; then
86 die "cannot determine package file"
88 pkgstr=$(zpm findpkg -f $pkgfile $pkgid)
89 if [ -z "$pkgstr" ]; then
90 die "unable to find package id for $pkgid in $pkgfile"
93 # need to reparse the new package id
94 eval $(zpm parse -E $pkgid)
98 # look for a .zpm file here
99 if [ -z "$pkgfile" ] && [ -f "$pkgid.zpm" ]; then
103 if [ -z "$pkgfile" ]; then
104 die "cannot determine package file"
107 # check for package file
108 if [ ! -f "$pkgfile" ]; then
109 echo $pkgfile does not exist
117 if [ $verbose -gt 0 ]; then
118 echo adding to $pkgfile $pkgid
121 package=$(zpm quote "$name")
122 pkgver=$(zpm quote "$version")
123 pkgrel=$(zpm quote "$release")
125 #strip=$(cleanpath "$strip")
128 if [ $verbose -gt 1 ]; then
129 printf "adding %s\n" $path
132 # only stat the file for items not set on the command line
133 mode=${clmode:-$(zpm stat -l -f '%a' $path)}
134 username=${cluser:-$(zpm stat -l -f '%U' $path)}
135 groupname=${clgroup:-$(zpm stat -l -f '%G' $path)}
136 mtime=${clmtime:-$(zpm stat -l -f '%y' $path)}
137 filetype=${cltype:-$(zpm stat -l -f '%t' "$path")}
141 rpath=$(cleanpath "$path")
143 # strip off leading slash
146 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
150 if [ ! -z "$strip" ]; then
151 rpath=${rpath#$strip}
155 if [ -z "$rpath" ]; then
156 die "$path resolves to nothing"
159 prefix=$(cleanpath "$prefix")
160 if [ ! -z "$prefix" ]; then
161 rpath="$prefix/$rpath"
164 # ensure all paths are absolute
172 if [ $addcontent -eq 1 ]; then
173 hash=$(zpm addfile $pkgfile "$path")
174 if [ $? -ne 0 ]; then
175 die "zpm addfile failed ($?): $pkgfile $path"
178 if [ -z "$clhash" ]; then
179 hash=$(zpm hash "$path")
191 if [ -n "$cltarget" ]; then
194 target=$(readlink $path)
195 target=$(zpm quote -q "$target")
199 die "filetype $filetype not supported"
203 # TODO check that we have such a package,version,release
205 if [ $verbose -gt 2 ]; then
208 zpm shell $pkgfile <<EOS
211 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,configuration,target)
212 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$isconfig,$target);
216 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
217 if [ $verbose -gt 1 ]; then
218 printf "%s%s %s:%s %s\n" $filetype $mode $username $groupname $path
219 elif [ $verbose -gt 0 ]; then
225 if [ $complete -eq 1 ]; then
226 zpm pkg -f $pkgfile $pkgid build_time=$(date +'%s')
227 zpm packagehash -f $pkgfile -s -q $pkgid
229 zpm pkg -f $pkgfile $pkgid hash=