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
45 # -H set hash, will be overridden for regular files unless -N is set
46 # -F set filetype, regular, symlink, directory
47 while getopts :f:vr:l:P:S:cu:g:NCm:M:T:H:F:z opt; do
50 f) pkgfile="$OPTARG" ;;
51 P) prefix="$OPTARG" ;;
52 S) strip=$(cleanpath "$OPTARG"); ;;
53 t) tags="$tags $OPTARG" ;;
55 u) cluser="$OPTARG" ;;
56 g) clgroup="$OPTARG" ;;
57 m) clmode="$OPTARG" ;;
58 M) clmtime="$OPTARG" ;;
59 T) cltarget="$OPTARG" ;;
60 F) cltype="$OPTARG" ;;
61 H) clhash="$OPTARG" ;;
62 v) verbose=$((verbose + 1)) ;;
65 *) echo 'unknown option' $OPTARG; exit 255 ;;
70 if [ $isconfig -eq 1 ]; then
71 tags="$tags configuration"
74 if [ $verbose -gt 2 ]; then
80 eval $(zpm parse -E $pkgid)
82 if [ -z "$pkgfile" ]; then
83 pkgfile=$ZPM_PACKAGE_FILE
86 if [ -z "$release" ]; then
87 if [ -z "$pkgfile" ]; then
88 die "cannot determine package file"
90 pkgstr=$(zpm findpkg -f $pkgfile $pkgid)
91 if [ -z "$pkgstr" ]; then
92 die "unable to find package id for $pkgid in $pkgfile"
95 # need to reparse the new package id
96 eval $(zpm parse -E $pkgid)
100 # look for a .zpm file here
101 if [ -z "$pkgfile" ] && [ -f "$pkgid.zpm" ]; then
105 if [ -z "$pkgfile" ]; then
106 die "cannot determine package file"
109 # check for package file
110 if [ ! -f "$pkgfile" ]; then
111 die $pkgfile does not exist
118 if [ $verbose -gt 0 ]; then
119 echo adding to $pkgfile $pkgid
122 package=$(zpm quote "$name")
123 pkgver=$(zpm quote "$version")
124 pkgrel=$(zpm quote "$release")
126 #strip=$(cleanpath "$strip")
129 if [ $verbose -gt 1 ]; then
130 printf "adding %s\n" "$path"
133 # only stat the file for items not set on the command line
134 mode=${clmode:-$(zpm stat -l -f '%a' "$path")}
135 username=${cluser:-$(zpm stat -l -f '%U' "$path")}
136 groupname=${clgroup:-$(zpm stat -l -f '%G' "$path")}
137 mtime=${clmtime:-$(zpm stat -l -f '%y' "$path")}
138 filetype=${cltype:-$(zpm stat -l -f '%t' "$path")}
142 rpath=$(cleanpath "$path")
144 # strip off leading slash
147 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
151 if [ ! -z "$strip" ]; then
152 rpath=${rpath#$strip}
156 if [ -z "$rpath" ]; then
157 die "$path resolves to nothing"
160 prefix=$(cleanpath "$prefix")
161 if [ ! -z "$prefix" ]; then
162 rpath="$prefix/$rpath"
165 # ensure all paths are absolute
173 if [ $addcontent -eq 1 ]; then
174 hash=$(zpm addfile $pkgfile "$path")
175 if [ $? -ne 0 ]; then
176 die "zpm addfile failed ($?): $pkgfile $path"
179 if [ -z "$clhash" ]; then
180 hash=$(zpm hash "$path")
192 if [ -n "$cltarget" ]; then
195 target=$(readlink $path)
196 target=$(zpm quote -q "$target")
200 die "filetype $filetype not supported"
204 # TODO check that we have such a package,version,release
206 if [ $verbose -gt 2 ]; then
209 zpm shell $pkgfile <<EOS
212 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,configuration,target)
213 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$isconfig,$target);
217 if [ $? -ne 0 ]; then
218 die zpm-add shell failed
221 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
222 if [ $verbose -gt 1 ]; then
223 printf "%s%s %s:%s %s\n" $filetype $mode $username $groupname "$path"
224 elif [ $verbose -gt 0 ]; then
225 printf "%s\n" "$path"
230 if [ $complete -eq 1 ]; then
231 zpm pkg -f $pkgfile $pkgid build_time=$(date +'%s')
232 zpm packagehash -f $pkgfile -s -q $pkgid
233 elif [ $noclear -eq 0 ]; then
234 zpm pkg -f $pkgfile $pkgid hash=
236 if [ $rv -ne 0 ]; then
237 die clearing packagehash failed