4 # collects info from package file and copies it into another package file
6 # merge [ -d ZPMDB ] [-f $pkgfile] pkg
7 # -F include file content
8 # -S don't include script content
11 printf 'zpm-merge:' 1>&2
12 printf ' %s' "$@" 1>&2
20 target=/var/lib/zpm/local.db
22 target=${ZPMDB:=/var/lib/zpm/local.db}
24 # TODO option to merge all packages found in pkgfile
25 while getopts :f:vd:FSs: opt; do
27 f) pkgfile="$OPTARG" ;;
29 d) target="$OPTARG" ;;
32 s) newstatus="$OPTARG" ;;
33 *) echo 'zpm-merge unknown option' $OPTARG; exit 1 ;;
39 if [ ! -e "$target" ]; then
40 die "target file $target does not exist"
43 zpm test -v "$target" || exit 1
45 # TODO if pkgfile is specified, allow multiple packages as args
49 if [ -z "$pkgid" ]; then
50 die "must specify pkgid"
53 eval "$(zpm parse -E $pkgid)"
55 if [ -z "$pkgfile" ]; then
56 pkgfile=$ZPM_PACKAGE_FILE
59 # calculate package id, pkgfile, etc
60 # cases R = full package id, F = specified package file
63 # --- 000 error, must specify something
64 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
65 die must specify package file or complete package id
68 # try to get from package file
69 if [ -z "$release" ]; then
70 pkgid=$(zpm findpkg -f $pkgfile $pkgid)
71 if [ -z "$pkgid" ]; then
72 die cannot find package id
74 eval "$(zpm parse -E $pkgid)"
77 # --F 001 error, wouldn't know which pkgid to create, could derive from file?
78 if [ -z "$release" ]; then
79 die must specify complete package id
83 # -R- 010 set file from pkgid, create in file, error if no file
84 if [ -z "$pkgfile" ]; then
88 if [ $verbose -gt 0 ]; then
89 echo merging $pkgfile $pkgid into $target
92 zpm test -v "$pkgfile" || exit 1
94 merged=$(zpm shell "$target" "select 1 from packages_pkgid where pkgid = '$pkgid'")
95 if [ -n "$merged" ]; then
96 die "$pkgid already exists in $target";
99 # TODO file tags and package tags
103 attach '$pkgfile' as remote;
107 insert or rollback into packages
108 select * from remote.packages P
110 printf('%s-%s-%s', P.package, P.version, P.release) = '$pkgid'
113 insert or rollback into packagefiles
114 select * from remote.packagefiles PF
116 printf('%s-%s-%s', PF.package, PF.version, PF.release) = '$pkgid'
119 insert or rollback into scripts
120 select * from remote.scripts PF
122 printf('%s-%s-%s', PF.package, PF.version, PF.release) = '$pkgid'
127 if [ $mergefiles -eq 1 ]; then
130 select F.* from remote.files F
131 inner join remote.packagefiles_pkgid PF
135 on conflict (hash) do nothing
142 if [ $mergescripts -eq 1 ]; then
145 select F.* from remote.files F
146 inner join remote.scripts_pkgid PF
150 on conflict (hash) do nothing
155 if [ -n "$newstatus" ]; then
156 newstatus=$(zpm quote "$newstatus")
157 package=$(zpm quote "$name")
158 version=$(zpm quote "$version")
160 update packages set status = '$newstatus'
161 where package = '$package' and version = '$version' and release = '$release'
168 # TODO check for adding file contents
170 } | zpm shell $target