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