]> pd.if.org Git - zpackage/blob - zpm-ipkgfile
more chatter in zpm-install
[zpackage] / zpm-ipkgfile
1 #!/bin/sh
2
3 # install a file from a package
4 # -f pkgfile
5 # -R root of pkg
6 # -P prefix to file
7 # -S strip prefix
8 # -p pkgname
9
10 pkgroot=/
11
12 while getopts :f:v:r:d:a:u:l:p:b:P:R: opt; do
13         case $opt in
14                 R) pkgroot="$OPTARG" ;;
15                 f) pkgfile="$OPTARG" ;;
16                 v) pkgver="$OPTARG" ;;
17                 r) pkgrel="$OPTARG" ;;
18                 P) prefix="$OPTARG" ;;
19         esac
20 done
21 shift $((OPTIND - 1))
22
23 die() {
24         echo $* 1>&2
25         exit 1
26 }
27
28 pkgfileinfo() {
29         zpm shell $pkgfile<<EOS
30 select $1 from packagefiles
31         where path='$2'
32         and package||'-'||version||'-'||release = '$pkg'
33         ;
34 EOS
35 }
36
37 # if not from a package file, from local db
38 if [ -z "$pkgfile" ]; then
39         die "installing from non-pkgfile not supported"
40 fi
41
42 pkg="$1"
43 shift
44
45 ZPMPKGFILE=$pkgfile
46 export ZPMPKGFILE
47
48 set -e
49 for path in $*; do
50         echo installing $path from $pkg
51         set -x
52         fhash=$(zpm pkgfileinfo hash $path)
53         mode=$(zpm pkgfileinfo mode $path)
54         ftype=$(zpm pkgfileinfo filetype $path)
55         owner=$(zpm pkgfileinfo username $path)
56         group=$(zpm pkgfileinfo groupname $path)
57
58         name=$(basename -- $path)
59         dir=$(dirname -- $path)
60
61         if [ "$pkgroot" != '/' ]; then
62                 dir=$pkgroot/$dir
63                 dir=${dir%/.}
64                 if [ "$dir" = "//" ]; then dir=/ ; fi
65         fi
66
67         tmppath=$dir/.installing.$name
68
69         # can't use install because it's not posix.
70         # probably worth writing a zpm-install, but with
71         # a different name since that wants to be a package install
72         # probably makes the most sense for extract to know how
73         # to do the extract to temp and such, then
74         # you can just add the -S option (secure)
75         #cat <<-EOC
76         set -x
77         mkdir -p $dir
78         zpm extract $pkgfile $fhash $tmppath 0
79         chown $owner:$group $tmppath
80         chmod $mode $tmppath
81         # TODO mv -n non-posix, going to need to have extract do all
82         # of this
83         mv -n $tmppath $dir/$name
84         set +x
85         #EOC
86 done