]> pd.if.org Git - zpackage/blob - zpm-install
add user and group to zpm-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 for cf in /etc/zpmrc ~/.zpmrc ./.zpmrc; do
57         test -r $cf && . $cf
58 done
59
60 while getopts :R:CNXf:d:Dt:T:u:g: opt; do
61         case $opt in
62                 R) pkgroot="$OPTARG" ;;
63                 C) chroot=0 ;;
64                 f) pkgfile="$OPTARG" ;;
65                 u) user="$OPTARG" ;;
66                 g) group="$OPTARG" ;;
67                 d) ZPMDB="$OPTARG" ;;
68         esac
69 done
70
71 shift $((OPTIND - 1))
72
73 : ${ZPMDB:=/var/lib/zpm/db.zpm}
74
75 export ZPMDB
76
77 die() {
78         printf 'zpm-install:' 1>&2
79         printf ' %s' $* 1>&2
80         printf '\n' 1>&2
81         exit 1
82 }
83
84 if [ -z "$pkgfile" ]; then
85         # actually, if no pkgfile, get pkgfile from repo
86         # but need to loop over finding package files then
87         # so this program probably needs to be "install from pkgfile"
88         # and a separate one that will loop over a package
89         # spec list and find from repos
90         die "must specify package file" 
91         pkgfile="$package-$pkgver-$pkgrel.zpm"
92 fi
93
94 set -e
95 zpm test -v $pkgfile
96
97 if [ $# -gt 0 ]; then
98         pkglist="$@"
99 else
100         pkglist=$(zpm findpkg $pkgfile)
101 fi
102
103 pathlist() {
104         zpm shell $pkgfile<<EOS
105 select path from packagefiles
106         where package||'-'||version||'-'||release = '$pkg'
107         ;
108 EOS
109 }
110
111 # find a repo file for a given package
112 findrepofor() {
113         false
114 }
115
116 installpkg() (
117         package="$1"
118 )
119
120 zpm merge $pkgfile
121
122 for pkg in $pkglist; do
123         # TODO find scripts marked as pre-install
124         # TODO if this is an upgrade, run pre-upgrade
125
126         # TODO get total size of install so we can do a progress bar
127
128         # add package info to local package db
129         # check for conflicts
130         # mark package in localdb as installing
131         # zpm setmark installing $pkg
132         # install all the files for a package
133         # TODO install directories first in order of path length
134         echo installing $pkglist
135         filecount=$(pathlist | wc -l)
136         echo $filecount files
137         #pathlist
138         pathlist | xargs zpm ipkgfile ${user+-u $user} ${group+-g $group} -R "$pkgroot" -f $pkgfile -- $pkg
139
140         # TODO find scripts marked as post-install
141         # TODO if this is an upgrade, run post-upgrade
142
143         # mark as ready for install
144         #zpm setmark ready $pkg
145 done
146
147 #zpm setmark installed $pkglist