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
41 while getopts :f:vr:l:P:S:cu:g:NC opt; do
44 f) pkgfile="$OPTARG" ;;
45 P) prefix="$OPTARG" ;;
46 S) strip=$(cleanpath "$OPTARG"); ;;
47 t) tags="$tags $OPTARG" ;;
49 u) username="$OPTARG" ;;
50 g) groupname="$OPTARG" ;;
53 *) echo 'unknown option' $OPTARG; exit 1 ;;
58 if [ $isconfig -eq 1 ]; then
59 tags="$tags configuration"
62 if [ $verbose -gt 1 ]; then
68 eval $(zpm parse -E $pkgid)
70 if [ -z "$pkgfile" ]; then
71 pkgfile=$ZPM_PACKAGE_FILE
74 if [ -z "$release" ]; then
75 if [ -z "$pkgfile" ]; then
76 die "cannot determine package file"
78 pkgstr=$(zpm findpkg -f $pkgfile $pkgid)
79 if [ -z "$pkgstr" ]; then
80 die "unable to find package id for $pkgid in $pkgfile"
83 # need to reparse the new package id
84 eval $(zpm parse -E $pkgid)
88 # look for a .zpm file here
89 if [ -z "$pkgfile" ] && [ -f "$pkgid.zpm" ]; then
93 if [ -z "$pkgfile" ]; then
94 die "cannot determine package file"
97 # check for package file
98 if [ ! -f "$pkgfile" ]; then
99 echo $pkgfile does not exist
107 if [ $verbose -gt 0 ]; then
108 echo adding to $pkgfile $pkgid
111 package=$(zpm quote "$name")
112 pkgver=$(zpm quote "$version")
113 pkgrel=$(zpm quote "$release")
115 #strip=$(cleanpath "$strip")
118 mtime=$(zpm stat -f '%y' $path)
119 uid=$(zpm stat -f '%u' $path)
120 gid=$(zpm stat -f '%g' $path)
121 : ${username:=$(zpm stat -f '%U' $path)}
122 : ${groupname:=$(zpm stat -f '%G' $path)}
123 mode=$(zpm stat -f '%a' $path)
126 rpath=$(cleanpath "$path")
128 # strip off leading slash
131 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
135 if [ ! -z "$strip" ]; then
136 echo "stripping $strip"
137 rpath=${rpath#$strip}
141 if [ -z "$rpath" ]; then
142 die "$path resolves to nothing"
145 prefix=$(cleanpath "$prefix")
146 if [ ! -z "$prefix" ]; then
147 rpath="$prefix/$rpath"
150 filetype=$(zpm stat -l -f '%t' "$path")
156 if [ $addcontent -eq 1 ]; then
157 hash=$(zpm addfile $pkgfile "$path")
158 if [ $? -ne 0 ]; then
159 die "zpm addfile failed ($?): $pkgfile $path"
162 hash=$(zpm hash "$path")
171 target=$(readlink $path)
176 # TODO check that we have such a package,version,release
178 zpm shell $pkgfile <<EOS
180 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
181 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
185 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
186 if [ $verbose -gt 0 ]; then
192 if [ $complete -eq 1 ]; then
193 zpm pkg -f $pkgfile $pkgid build_time=$(date +'%s')
194 zpm packagehash -f $pkgfile -s -q $pkgid
196 zpm pkg -f $pkgfile $pkgid hash=