3 package=${1:-$ZPMPACKAGE}
5 pkgver=${ZPMPACKAGEVER:-1.0}
6 pkgrel=${ZPMPACKAGEREL:-1}
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
20 # after all the files, extract post scripts and run them
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
27 R) pkgroot="$OPTARG" ;;
28 f) pkgfile="$OPTARG" ;;
29 v) pkgver="$OPTARG" ;;
30 r) pkgrel="$OPTARG" ;;
31 d) description="$OPTARG" ;;
34 l) licenses="$OPTARG" ;;
35 p) packager="$OPTARG" ;;
36 b) builddate="$OPTARG" ;;
37 P) prefix="$OPTARG" ;;
42 if [ -z "$pkgfile" ]; then
43 pkgfile="$package-$pkgver-$pkgrel.zpm"
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
52 # check if package exists
53 # run preinstall or preupgrade stage, in chroot
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
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)
67 # strip off leading slashes
68 rpath=$(echo "$path" | sed -e 's|^/*||')
71 rpath=$(echo "$rpath" | sed -e 's|^/*||')
73 if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
77 if [ ! -z "$prefix" ]; then
78 # trailing slashes on prefix
79 prefix=$(echo "$prefix" | sed -e 's|/*$||')
80 rpath="$prefix/$rpath"
83 if [ -f "$path" ]; then
85 hash=$(./zpm-addfile $pkgfile $path)
87 #if [ -z "$hash" ]; then continue; fi
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')
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')
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')
112 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}