#!/bin/sh # edit package metadata #zpm pkg -s packager=foo zpm # zpm pkg -f zpm packager=xyz # zpm pkg zpm packager warn() { printf '%s:' "$0" 1>&2 printf ' %s' $* 1>&2 printf '\n' 1>&2 rv=1 } die() { printf '%s:' "$0" 1>&2 printf ' %s' $* 1>&2 printf '\n' 1>&2 exit 1 } pkgfile=${ZPMDB:-/var/lib/zpm/local.db} while getopts f: opt; do case $opt in f) pkgfile="$OPTARG" ;; esac done shift $((OPTIND - 1)) set -e if [ ! -f $pkgfile ]; then echo cannot find $pkgfile exit 1 fi item=$1 shift #printf "pkg: %s\n" $pkg pkgid=$(zpm findpkg -f $pkgfile "$item") if [ -z "$pkgid" ]; then die "can't find pkgid for $item in $pkgfile" fi ( rv=0 { printf "begin;\n" while [ $# -gt 0 ]; do item=$1 shift show=0 case "$item" in :*) pkgid=$(zpm findpkg -f $pkgfile "${item#:}") continue ;; *=*) field=${item%%=*} value=${item#*=} ;; *=) field=${item%%=*} value= ;; *) field=$item show=1 ;; esac if [ -z "$pkgid" ]; then warn "can't find pkgid for $item in $pkgfile" break; fi vfield=$(zpm quote "$field") hasfield=$(zpm shell $pkgfile "select name from pragma_table_info('packages') where name = '$vfield';") if [ -z "$hasfield" ]; then warn "$field is not a valid package field" break fi field=$(zpm quote -i "$field") if [ $show -eq 1 ]; then printf "select %s from packages_pkgid where pkgid = '%s';\n" "$field" "$pkgid" continue fi if [ -z "$value" ]; then value=NULL else value=$(zpm quote -q "$value") fi printf "update packages_pkgid set %s = %s where pkgid = '$pkgid';\n" $field "$value" done if [ $rv -eq 0 ]; then printf "commit;\n" else printf "rollback;\n" fi } | zpm shell $pkgfile exit $rv )