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