]> pd.if.org Git - zpackage/blob - zpm-install
add comments on install strategy
[zpackage] / zpm-install
1 #!/bin/sh
2
3 package=${1:-$ZPMPACKAGE}
4 shift
5 pkgver=${ZPMPACKAGEVER:-1.0}
6 pkgrel=${ZPMPACKAGEREL:-1}
7
8 pkgroot=/
9
10 # allocate an install id, perhaps hash package and timestamp
11 # extract pre-scripts and run them
12 # get list of paths to install
13 # for each path, if directory, create and set mode
14 # for each path, create leading directories
15 # extract to something like /var/tmp/.hash, with low perms
16 # only atomic if same filesystem, so use .installid.hash in the
17 # install directory
18 # set perms and such
19 # move into place
20 # after all the files, extract post scripts and run them
21
22 # option for "multipackage" just to let the system know that's what you meant
23 # option to take filenames from stdin
24 # parse package, version, release from file if not given
25 while getopts :f:v:r:d:a:u:l:p:b:P: opt; do
26         case $opt in
27                 R) pkgroot="$OPTARG" ;;
28                 f) pkgfile="$OPTARG" ;;
29                 v) pkgver="$OPTARG" ;;
30                 r) pkgrel="$OPTARG" ;;
31                 d) description="$OPTARG" ;;
32                 a) arch="$OPTARG" ;;
33                 u) url="$OPTARG" ;;
34                 l) licenses="$OPTARG" ;;
35                 p) packager="$OPTARG" ;;
36                 b) builddate="$OPTARG" ;;
37                 P) prefix="$OPTARG" ;;
38         esac
39 done
40
41 set -e
42 if [ -z "$pkgfile" ]; then
43         pkgfile="$package-$pkgver-$pkgrel.zpm"
44 fi
45
46 appid=$(sqlite3 $pkgfile 'pragma application_id;' | ( echo obase = 16; cat - ) | bc)
47 if [ "$appid" != "5A504442" ]; then
48         echo $pkgfile does not appear to be a zpm package file
49         exit 1
50 fi
51
52 # check if package exists
53 # run preinstall or preupgrade stage, in chroot
54
55 # add package info and mark installing to local package database
56 # each path: add to local db, extract, set mode/owner/mtime etc.
57 # mark install done in local database
58
59 for path in $*; do
60         mtime=$(stat -c '%Y' $path)
61         uid=$(stat -c '%u' $path)
62         gid=$(stat -c '%g' $path)
63         username=$(stat -c '%U' $path)
64         groupname=$(stat -c '%G' $path)
65         mode=$(stat -c '%a' $path)
66
67         # strip off leading slashes
68         rpath=$(echo "$path" | sed -e 's|^/*||')
69         # and a leading ./
70         rpath=${rpath#./}
71         rpath=$(echo "$rpath" | sed -e 's|^/*||')
72
73         if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
74                 continue
75         fi
76
77         if [ ! -z "$prefix" ]; then
78                 # trailing slashes on prefix
79                 prefix=$(echo "$prefix" | sed -e 's|/*$||')
80                 rpath="$prefix/$rpath"
81         fi
82
83         if [ -f "$path" ]; then
84
85                 hash=$(./zpm-addfile $pkgfile $path)
86
87 #if [ -z "$hash" ]; then continue; fi
88
89 # TODO mtime, mode
90 sqlite3 $pkgfile <<EOS
91 PRAGMA foreign_keys = ON;
92 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,hash)
93 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$hash')
94 ;
95 EOS
96 elif [ -d "$path" ]; then
97 sqlite3 $pkgfile <<EOS
98 PRAGMA foreign_keys = ON;
99 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname)
100 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname')
101 ;
102 EOS
103 elif [ -l "$path" ]; then
104         target=$(readlink $path)
105 sqlite3 $pkgfile <<EOS
106 PRAGMA foreign_keys = ON;
107 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,target)
108 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$target')
109 ;
110 EOS
111 fi
112 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
113 printf "%s\n" $path
114 done