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 curl -f '-#' -z "$rf" -o "$rf.tmp" "$url"
111 curl -f '-#' -o "$rf.tmp" "$url" && refresh "$repo"
114 if [ $rv -eq 0 ]; then
116 zpm test "$rf.tmp" &&
123 # response=$(curl --write-out %{http_code} --silent --output /dev/null servername)
126 head_response_code() {
127 curl --write-out '%{http_code}' --silent --output /dev/null -z $2 $1
133 url=$(select "$repo" url)
135 for package in "$@"; do
136 pkgid=$(zpm findpkg -f $repodir/$repo.repo $package)
137 if [ -z "$pkgid" ]; then
138 warn "no package found for $package"
140 mkdir -p "$repodir/$repo"
141 dest="$repodir/$repo/$pkgid.zpm"
142 fetch="$base/packages/$pkgid.zpm"
144 if [ -f "$dest" ]; then
145 rc=$(head_response_code $fetch $dest)
146 if [ $rc = 304 ]; then
150 echo downloading $pkgid
151 curl -f '-#' -z "$dest" -o "$dest.tmp" $fetch
152 mv "$dest.tmp" "$dest"
154 echo downloading $pkgid
155 curl -f '-#' -o "$dest.tmp" $fetch
156 mv "$dest.tmp" "$dest"
165 url=$(select "$repo" url)
167 for package in "$@"; do
168 pkgid=$(zpm findpkg -f $repodir/$repo.repo $package)
169 if [ -z "$pkgid" ]; then
170 warn "no package found for $package"
172 mkdir -p "$repodir/$repo"
173 dest="$repodir/$repo/$pkgid.zpm"
175 if [ -f "$dest" ]; then
178 zpm rmpackage -f $repodir/$repo.repo $pkgid
184 rn=$(select "$1" name)
185 if [ -z "$rn" ]; then
186 warn "no repository $1"
194 select '' priority,name,url,refreshed ;;
196 name=$(zpm quote "$1")
197 url=$(zpm quote "$2")
198 zpm shell $ZPMDB "insert into repository (name,url) values ('$name', '$url')"
201 name=$(zpm quote "$1")
202 zpm shell $ZPMDB "delete from repository where name = '$name'"
203 rm -f $repodir/$1.repo
204 test -d "$repodir/$repo" && rm -r "$repodir/$repo"
215 update "$1" priority "$2"
229 zpm list -f $repodir/$repo.repo "$@"
234 zpm contents -f $repodir/$repo.repo "$@"