]> pd.if.org Git - zpackage/blob - zpm-ipkgfile
add directories to ipkgfile
[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:g: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                 u) owner="$OPTARG" ;;
20                 g) group="$OPTARG" ;;
21         esac
22 done
23 shift $((OPTIND - 1))
24
25 die() {
26         echo $* 1>&2
27         exit 1
28 }
29
30 pkgfileinfo() {
31         zpm shell $pkgfile<<EOS
32 select $1 from packagefiles
33         where path='$2'
34         and package||'-'||version||'-'||release = '$pkg'
35         ;
36 EOS
37 }
38
39 # if not from a package file, from local db
40 if [ -z "$pkgfile" ]; then
41         die "installing from non-pkgfile not supported"
42 fi
43
44 pkg="$1"
45 shift
46
47 ZPMPKGFILE=$pkgfile
48 export ZPMPKGFILE
49
50 set -e
51 for path in $*; do
52
53         name=$(basename -- $path)
54         dir=$(dirname -- $path)
55         dir=${dir#/}
56
57         if [ "$pkgroot" != '/' ]; then
58                 dir=$pkgroot/$dir
59                 dir=${dir%/.}
60 #               if [ "$dir" = "//" ]; then dir=/ ; fi
61         fi
62
63         # TODO generate some unique hash
64         tmppath=$dir/.installing.$name
65
66         printf '%s installing %s\n' $pkg $dir/$name
67
68         fhash=$(pkgfileinfo hash $path)
69         mode=$(pkgfileinfo mode $path)
70         ftype=$(pkgfileinfo filetype $path)
71         : ${owner:=$(pkgfileinfo username $path)}
72         : ${group:=$(pkgfileinfo groupname $path)}
73
74         # can't use install because it's not posix.
75         # probably worth writing a zpm-install, but with
76         # a different name since that wants to be a package install
77         # probably makes the most sense for extract to know how
78         # to do the extract to temp and such, then
79         # you can just add the -S option (secure)
80         #cat <<-EOC
81         mkdir -p $dir
82         umask 0700
83         case $ftype in
84                 r*) zpm extract $pkgfile $fhash $tmppath
85                         chown $owner:$group $tmppath
86                         chmod $mode $tmppath
87                         # TODO mv -n non-posix, going to need to have extract
88                         # do all of this
89                         mv $tmppath $dir/$name
90                         ;;
91                 d*)
92                         mkdir -m 000 $dir/$name
93                         chown $owner:$group $dir/$name
94                         chmod $mode $dir/name
95                         ;;
96
97                 *) echo unknown filetype ; exit 1 ;;
98         esac
99
100         #EOC
101 done