3 # zpm add -f pkgfile pkgid [ files ]
5 # no package file? take from ZPM_PACKAGE_FILE
6 # no pkgid ? take from ZPM_PACKAGE_ID
14 while getopts :f: opt; do
16 f) pkgfile="$OPTARG" ;;
17 *) echo 'zpm-setscript unknown option' $opt; exit 1 ;;
25 if [ -z "$pkgid" ]; then
26 die "must specify pkgid"
29 eval "$(zpm parse -E $pkgid)"
31 if [ -z "$pkgfile" ]; then
32 pkgfile=$ZPM_PACKAGE_FILE
35 # cases R = full package id, F = specified package file
38 # --- 000 error, must specify something
39 if [ -z "$release" ] && [ -z "$pkgfile" ]; then
40 die must specify package file or complete package id
43 # try to get from package file
44 if [ -z "$release" ]; then
45 pkgid=$(zpm findpkg -f $pkgfile $pkgid)
46 if [ -z "$pkgid" ]; then
47 die cannot find package id
49 eval "$(zpm parse -E $pkgid)"
52 # --F 001 error, wouldn't know which pkgid to create, could derive from file?
53 if [ -z "$release" ]; then
54 die must specify complete package id
57 #echo "have '$pkgid' '$pkgfile'"
60 # -R- 010 set file from pkgid, create in file, error if no file
61 if [ -z "$pkgfile" ]; then
65 # will now be one of these
66 # -RF 011 create package in file, error if file doesn't exist
67 if [ ! -f "$pkgfile" ]; then
68 die $pkgfile does not exist
73 if [ "$idempotent" = 1 ]; then
74 idempotent='or ignore'
77 package=$(zpm quote "$name")
78 pkgver=$(zpm quote "$version")
79 pkgrel=$(zpm quote "$release")
81 # args are stage and script
88 if [ ! -f "$script" ]; then
89 die "$script is not a regular file"
91 hash=$(zpm addfile $pkgfile "$path")
93 die "zpm addfile failed ($?): $pkgfile $path"
95 #echo adding script $hash $path
96 hash=$(zpm quote "$hash")
98 stage=$(zpm quote "$stage")
101 zpm shell $pkgfile <<EOS
102 PRAGMA foreign_keys = ON;
104 insert or replace into scripts (package,version,release,stage,hash)
105 values ('$package', '$pkgver', $pkgrel, '$stage', '$hash');
109 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
115 stage=$(zpm quote "$stage")
118 zpm shell $pkgfile <<EOS
119 PRAGMA foreign_keys = ON;
122 where package = '$package' and version = '$pkgver' and release = $pkgrel
128 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
132 # TODO better syntax for showing the script
133 # TODO a way to set the script hash directly
134 while [ $# -gt 1 ]; do
139 if [ "$script" = '-' ]; then
140 removescript "$stage"
141 elif [ -z "$script" ]; then
144 addscript "$stage" "$script"