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" ;;
51 v) verbose=$((verbose + 1)) ;;
53 *) echo 'unknown option' $OPTARG; exit 1 ;;
58 if [ $isconfig -eq 1 ]; then
59 tags="$tags configuration"
62 if [ $verbose -gt 2 ]; 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 mode=$(zpm stat -f '%a' $path)
123 # only stat the file for the user and group name if not set on the
125 : ${username:=$(zpm stat -f '%U' $path)}
126 : ${groupname:=$(zpm stat -f '%G' $path)}
130 rpath=$(cleanpath "$path")
132 # strip off leading slash
135 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
139 if [ ! -z "$strip" ]; then
140 rpath=${rpath#$strip}
144 if [ -z "$rpath" ]; then
145 die "$path resolves to nothing"
148 prefix=$(cleanpath "$prefix")
149 if [ ! -z "$prefix" ]; then
150 rpath="$prefix/$rpath"
153 # ensure all paths are absolute
156 filetype=$(zpm stat -l -f '%t' "$path")
162 if [ $addcontent -eq 1 ]; then
163 hash=$(zpm addfile $pkgfile "$path")
164 if [ $? -ne 0 ]; then
165 die "zpm addfile failed ($?): $pkgfile $path"
168 hash=$(zpm hash "$path")
177 target=$(readlink $path)
182 # TODO check that we have such a package,version,release
184 zpm shell $pkgfile <<EOS
186 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,configuration,target)
187 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$isconfig,$target);
191 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
192 if [ $verbose -gt 1 ]; then
193 printf "%s%s %s:%s %s\n" $filetype $mode $username $groupname $path
194 elif [ $verbose -gt 0 ]; then
200 if [ $complete -eq 1 ]; then
201 zpm pkg -f $pkgfile $pkgid build_time=$(date +'%s')
202 zpm packagehash -f $pkgfile -s -q $pkgid
204 zpm pkg -f $pkgfile $pkgid hash=