]> pd.if.org Git - zpackage/blob - zpm-ipkgfile
get zpm-ipkgfile working
[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         cat <<-EOC
64         mkdir -p $dir
65         zpm extract $pkgfile $fhash $tmppath 0
66         chown $owner:$group $tmppath
67         chmod $mode $tmppath
68         mv $tmppath $dir/$name
69         EOC
70 done