X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-merge;h=dc6f51c45f13340ddb5e25ef1e9cc45f99a5f10d;hb=3e81f5aec6dbb79f13ecfd50d506767fc6b5da7f;hp=ada48aacfefcc6a0859908a38ae632a41f6d25bb;hpb=51a6d79f8a532376a9f27dbb5133bf13a5474703;p=zpackage diff --git a/zpm-merge b/zpm-merge index ada48aa..dc6f51c 100755 --- a/zpm-merge +++ b/zpm-merge @@ -17,12 +17,17 @@ die() { verbose=0 mergefiles=0 mergescripts=1 -target=/var/lib/zpm/local.db +mergeall=1 +update=0 +remove_older=0 +only_if_newer=0 target=${ZPMDB:=/var/lib/zpm/local.db} +# TODO option to only update if new +# new is hash is different or build time is later # TODO option to merge all packages found in pkgfile -while getopts :f:vd:FSs: opt; do +while getopts :f:vd:FSs:auon opt; do case $opt in f) pkgfile="$OPTARG" ;; v) verbose=1 ;; @@ -30,6 +35,10 @@ while getopts :f:vd:FSs: opt; do F) mergefiles=1 ;; S) mergescripts=0 ;; s) newstatus="$OPTARG" ;; + a) mergeall=1 ;; + u) update=1 ;; + o) remove_older=1 ;; + n) only_if_newer=1 ;; *) echo 'zpm-merge unknown option' $OPTARG; exit 1 ;; esac done @@ -42,129 +51,155 @@ fi zpm test -v "$target" || exit 1 +if [ $# -eq 0 ]; then + mergeall=1 +else + mergeall=0 +fi + # TODO if pkgfile is specified, allow multiple packages as args -pkgid=$1 -shift +if [ $mergeall -eq 0 ]; then + pkgid=$1 + shift -if [ -z "$pkgid" ]; then - die "must specify pkgid" -fi + if [ -z "$pkgid" ]; then + die "must specify pkgid" + fi -eval "$(zpm parse -E $pkgid)" + eval "$(zpm parse -E $pkgid)" -if [ -z "$pkgfile" ]; then - pkgfile=$ZPM_PACKAGE_FILE -fi + if [ -z "$pkgfile" ]; then + pkgfile=$ZPM_PACKAGE_FILE + fi -# calculate package id, pkgfile, etc -# cases R = full package id, F = specified package file + # calculate package id, pkgfile, etc + # cases R = full package id, F = specified package file -# immediate error -# --- 000 error, must specify something -if [ -z "$release" ] && [ -z "$pkgfile" ]; then - die must specify package file or complete package id -fi + # immediate error + # --- 000 error, must specify something + if [ -z "$release" ] && [ -z "$pkgfile" ]; then + die must specify package file or complete package id + fi -# try to get from package file -if [ -z "$release" ]; then - pkgid=$(zpm findpkg -f $pkgfile $pkgid) - if [ -z "$pkgid" ]; then - die cannot find package id + # try to get from package file + if [ -z "$release" ]; then + pkgid=$(zpm findpkg -f $pkgfile $pkgid) + if [ -z "$pkgid" ]; then + die cannot find package id + fi + eval "$(zpm parse -E $pkgid)" fi - eval "$(zpm parse -E $pkgid)" -fi -# --F 001 error, wouldn't know which pkgid to create, could derive from file? -if [ -z "$release" ]; then - die must specify complete package id -fi + # --F 001 error, wouldn't know which pkgid to create, could derive from file? + if [ -z "$release" ]; then + die must specify complete package id + fi -# set file from pkgid -# -R- 010 set file from pkgid, create in file, error if no file -if [ -z "$pkgfile" ]; then - pkgfile="$pkgid.zpm" -fi + # set file from pkgid + # -R- 010 set file from pkgid, create in file, error if no file + if [ -z "$pkgfile" ]; then + pkgfile="$pkgid.zpm" + fi -if [ $verbose -gt 0 ]; then - echo merging $pkgfile $pkgid into $target + if [ $verbose -gt 0 ]; then + echo merging $pkgfile $pkgid into $target + fi + pkglist=$pkgid +else + pkglist=$(zpm list -f "$pkgfile") fi zpm test -v "$pkgfile" || exit 1 -merged=$(zpm shell "$target" "select 1 from packages_pkgid where pkgid = '$pkgid'") -if [ -n "$merged" ]; then - die "$pkgid already exists in $target"; +if [ -n "$newstatus" ]; then + newstatus=$(zpm quote "$newstatus") fi -# TODO file tags and package tags -{ -cat < (select max(pkgid) collate vercmp from packages_pkgid where package = '$package') from packages_pkgid where package = '$package'") + if [ "$newer" = '1' ] || [ -z "$newer" ]; then + return 0; + fi + return 1 +} + +mlist="$pkglist" +if [ $only_if_newer -eq 1 ]; then + mlist= + for pkgid in $pkglist; do + if check_newer "$pkgid" ; then + mlist="$mlist $pkgid" + fi + done + if [ -z "$mlist" ]; then + exit 0 + fi fi -# elf info +# TODO file tags and package tags +{ + printf ".bail on\n" + printf "attach '%s' as remote;\n" "$pkgfile" + printf "begin;\n" + + for pkgid in $pkglist; do + mergeone "$pkgid" + done + + printf "insert or ignore into elfneeded select * from remote.elfneeded;\n" + printf "insert or ignore into elflibraries select * from remote.elflibraries;\n" -# TODO check for adding file contents -echo 'commit;' + printf "commit;\n" } | zpm shell $target + +if [ $verbose -ne 0 ]; then + printf "%s\n" $pkglist +fi