]> pd.if.org Git - zpackage/blob - zpm-install
integrate previous work
[zpackage] / zpm-install
1 #!/bin/sh
2
3 #package=${1:-$ZPMPACKAGE}
4 pkgver=${ZPMPACKAGEVER:-1.0}
5 pkgrel=${ZPMPACKAGEREL:-1}
6
7 pkgroot=/
8
9 # allocate an install id, perhaps hash package and timestamp
10 # installid=$(echo $(date) $pkglist | zpm hash)
11
12 # extract pre-scripts and run them
13 # get list of paths to install
14 # for each path, if directory, create and set mode
15 # for each path, create leading directories
16 # extract to something like /var/tmp/.hash, with low perms
17 # only atomic if same filesystem, so use .installid.hash in the
18 # install directory
19 # set perms and such
20 # move into place
21 # after all the files, extract post scripts and run them
22
23 # also need to mark package as installing so if it fails part way
24 # through, it can be finished later
25 # probably also want an option to "backup" any packages being upgraded
26 # so it's trivial to downgrade or to revert if the install fails
27
28 # option for "multipackage" just to let the system know that's what you meant
29 # option to take filenames from stdin
30 # parse package, version, release from file if not given
31 # TODO what's the difference between prefix and pkgroot
32 # need an option to not chown the files
33 # option to install but not merge/track
34 while getopts :f:v:r:d:a:u:l:p:b:P:R: opt; do
35         case $opt in
36                 R) pkgroot="$OPTARG" ;;
37                 f) pkgfile="$OPTARG" ;;
38                 v) pkgver="$OPTARG" ;;
39                 r) pkgrel="$OPTARG" ;;
40                 d) description="$OPTARG" ;;
41                 a) arch="$OPTARG" ;;
42                 u) url="$OPTARG" ;;
43                 l) licenses="$OPTARG" ;;
44                 p) packager="$OPTARG" ;;
45                 b) builddate="$OPTARG" ;;
46                 P) prefix="$OPTARG" ;;
47         esac
48 done
49 shift $((OPTIND - 1))
50
51 die() {
52         echo $* 1>&2
53         exit 1
54 }
55
56 if [ -z "$pkgfile" ]; then
57         # actually, if no pkgfile, get pkgfile from repo
58         # but need to loop over finding package files then
59         # so this program probably needs to be "install from pkgfile"
60         # and a separate one that will loop over a package
61         # spec list and find from repos
62         die "must specify package file" 
63         pkgfile="$package-$pkgver-$pkgrel.zpm"
64 fi
65
66 set -e
67 zpm test -v $pkgfile
68
69 if [ $# -gt 0 ]; then
70         pkglist="$@"
71 else
72         pkglist=$(zpm findpkg $pkgfile)
73 fi
74
75 pathlist() {
76         sqlite3 $pkgfile<<EOS
77 select path from packagefiles
78         where package||'-'||version||'-'||release = '$pkg'
79         ;
80 EOS
81 }
82
83 for pkg in $pkglist; do
84         # TODO find scripts marked as pre-install
85         # TODO if this is an upgrade, run pre-upgrade
86
87         # TODO get total size of install so we can do a progress bar
88
89         # add package info to local package db
90         # zpm merge -L -f $pkgfile $pkg
91         # check for conflicts
92         # mark package in localdb as installing
93         # zpm setmark installing $pkg
94         # install all the files for a package
95         # TODO install directories first in order of path length
96         pathlist | xargs zpm ipkgfile -R "$pkgroot" -f $pkgfile -- $pkg 
97
98         # TODO find scripts marked as post-install
99         # TODO if this is an upgrade, run post-upgrade
100
101         # mark as ready for install
102         #zpm setmark ready $pkg
103 done
104
105 #zpm setmark installed $pkglist