]> pd.if.org Git - zpackage/blob - zpm-install
large commit of C work
[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 # option for "multipackage" just to let the system know that's what you meant
11 # option to take filenames from stdin
12 # parse package, version, release from file if not given
13 while getopts :f:v:r:d:a:u:l:p:b:P: opt; do
14         case $opt in
15                 R) pkgroot="$OPTARG" ;;
16                 f) pkgfile="$OPTARG" ;;
17                 v) pkgver="$OPTARG" ;;
18                 r) pkgrel="$OPTARG" ;;
19                 d) description="$OPTARG" ;;
20                 a) arch="$OPTARG" ;;
21                 u) url="$OPTARG" ;;
22                 l) licenses="$OPTARG" ;;
23                 p) packager="$OPTARG" ;;
24                 b) builddate="$OPTARG" ;;
25                 P) prefix="$OPTARG" ;;
26         esac
27 done
28
29 set -e
30 if [ -z "$pkgfile" ]; then
31         pkgfile="$package-$pkgver-$pkgrel.zpm"
32 fi
33
34 appid=$(sqlite3 $pkgfile 'pragma application_id;' | ( echo obase = 16; cat - ) | bc)
35 if [ "$appid" != "5A504442" ]; then
36         echo $pkgfile does not appear to be a zpm package file
37         exit 1
38 fi
39
40 # check if package exists
41 # run preinstall or preupgrade stage, in chroot
42
43 # add package info and mark installing to local package database
44 # each path: add to local db, extract, set mode/owner/mtime etc.
45 # mark install done in local database
46
47 for path in $*; do
48         mtime=$(stat -c '%Y' $path)
49         uid=$(stat -c '%u' $path)
50         gid=$(stat -c '%g' $path)
51         username=$(stat -c '%U' $path)
52         groupname=$(stat -c '%G' $path)
53         mode=$(stat -c '%a' $path)
54
55         # strip off leading slashes
56         rpath=$(echo "$path" | sed -e 's|^/*||')
57         # and a leading ./
58         rpath=${rpath#./}
59         rpath=$(echo "$rpath" | sed -e 's|^/*||')
60
61         if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
62                 continue
63         fi
64
65         if [ ! -z "$prefix" ]; then
66                 # trailing slashes on prefix
67                 prefix=$(echo "$prefix" | sed -e 's|/*$||')
68                 rpath="$prefix/$rpath"
69         fi
70
71         if [ -f "$path" ]; then
72
73                 hash=$(./zpm-addfile $pkgfile $path)
74
75 #if [ -z "$hash" ]; then continue; fi
76
77 # TODO mtime, mode
78 sqlite3 $pkgfile <<EOS
79 PRAGMA foreign_keys = ON;
80 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,hash)
81 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$hash')
82 ;
83 EOS
84 elif [ -d "$path" ]; then
85 sqlite3 $pkgfile <<EOS
86 PRAGMA foreign_keys = ON;
87 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname)
88 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname')
89 ;
90 EOS
91 elif [ -l "$path" ]; then
92         target=$(readlink $path)
93 sqlite3 $pkgfile <<EOS
94 PRAGMA foreign_keys = ON;
95 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,target)
96 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$target')
97 ;
98 EOS
99 fi
100 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
101 printf "%s\n" $path
102 done