9 # list [-v ] [ name ... ]
12 # packages [ name ... ] -- like zpm list
13 # contents [ name ... ] -- like zpm contents
14 # search [ name ] -- packages
15 # push name ckagefile ...
16 # pull name package ...
17 # extract -- extract metadata from repo
18 # json - extract metadata as json
19 # setpkgurl packageid url
20 # update - pull info from remote
21 # gc [name] - run zpm gc on repo file
26 while getopts :R:d: opt; do
28 R) pkgroot="$OPTARG" ;;
35 for cf in /etc/zpmrc ~/.zpmrc ./.zpmrc; do
41 : ${ZPMDB:=$pkgroot/var/lib/zpm/local.db}
43 repodir=/var/lib/zpm/repo
49 printf '%s:' "$0" 1>&2
56 printf '%s:' "$0" 1>&2
73 name=$(zpm quote "$1")
75 if [ -n "$name" ]; then
76 where="where name = '$name'"
78 zpm shell -separator ' ' $ZPMDB "select $cols from repository $where order by priority,name"
82 name=$(zpm quote "$1")
85 if [ -n "$name" ]; then
86 where="where name = '$name'"
88 zpm shell $ZPMDB "update repository set $col = '$val' $where"
92 zpm shell $ZPMDB "update repository set refreshed = strftime('%s', 'now') where name = '$1'"
100 url=$(select "$repo" url)
101 rf="$repodir/$repo.repo"
102 if [ -z "$url" ]; then
103 check_for_repo "$repo" || warn "no url for repo $repo"
106 if [ -f "$rf" ]; then
107 # TODO merge in so packages aren't deleted
108 zpm fetchurl -fpn -z "$rf" -o "$rf.tmp" "$url"
111 zpm fetchurl -fpn -o "$rf.tmp" "$url" && refresh "$repo"
114 if [ $rv -eq 0 ]; then
116 zpm test "$rf.tmp" &&
123 head_response_code() {
124 zpm fetchurl -S -z "$2" "$1"
130 url=$(select "$repo" url)
132 for package in "$@"; do
133 pkgid=$(zpm findpkg -f $repodir/$repo.repo $package)
134 if [ -z "$pkgid" ]; then
135 warn "no package found for $package"
137 mkdir -p "$repodir/$repo"
138 dest="$repodir/$repo/$pkgid.zpm"
139 fetch="$base/packages/$pkgid.zpm"
141 if [ -f "$dest" ]; then
142 rc=$(head_response_code $fetch $dest)
143 if [ $rc = 304 ]; then
147 echo downloading $pkgid
148 zpm fetchurl -f '-#' -z "$dest" -o "$dest.tmp" $fetch
149 mv "$dest.tmp" "$dest"
151 echo downloading $pkgid
152 zpm fetchurl -f '-#' -o "$dest.tmp" $fetch
153 mv "$dest.tmp" "$dest"
162 url=$(select "$repo" url)
164 for package in "$@"; do
165 pkgid=$(zpm findpkg -f $repodir/$repo.repo $package)
166 if [ -z "$pkgid" ]; then
167 warn "no package found for $package"
169 mkdir -p "$repodir/$repo"
170 dest="$repodir/$repo/$pkgid.zpm"
172 if [ -f "$dest" ]; then
175 zpm rmpackage -f $repodir/$repo.repo $pkgid
181 rn=$(select "$1" name)
182 if [ -z "$rn" ]; then
183 warn "no repository $1"
191 select '' priority,name,url,refreshed ;;
193 name=$(zpm quote "$1")
194 url=$(zpm quote "$2")
195 zpm shell $ZPMDB "insert into repository (name,url) values ('$name', '$url')"
198 name=$(zpm quote "$1")
199 zpm shell $ZPMDB "delete from repository where name = '$name'"
200 rm -f $repodir/$1.repo
201 test -d "$repodir/$repo" && rm -r "$repodir/$repo"
212 update "$1" priority "$2"
226 zpm list -f $repodir/$repo.repo "$@"
231 zpm contents -f $repodir/$repo.repo "$@"