]> pd.if.org Git - zpackage/blob - zpm-addtopackage
large commit of C work
[zpackage] / zpm-addtopackage
1 #!/bin/sh
2
3 package=${1:-$ZPMPACKAGE}
4 shift
5 pkgver=${ZPMPACKAGEVER:-1.0}
6 pkgrel=${ZPMPACKAGEREL:-1}
7
8 # option for "multipackage" just to let the system know that's what you meant
9 # option to take filenames from stdin
10 # parse package, version, release from file if not given
11 while getopts :f:v:r:d:a:u:l:p:b:P: opt; do
12         case $opt in
13                 f) pkgfile="$OPTARG" ;;
14                 v) pkgver="$OPTARG" ;;
15                 r) pkgrel="$OPTARG" ;;
16                 d) description="$OPTARG" ;;
17                 a) arch="$OPTARG" ;;
18                 u) url="$OPTARG" ;;
19                 l) licenses="$OPTARG" ;;
20                 p) packager="$OPTARG" ;;
21                 b) builddate="$OPTARG" ;;
22                 P) prefix="$OPTARG" ;;
23         esac
24 done
25
26 set -e
27 if [ -z "$pkgfile" ]; then
28         pkgfile="$package-$pkgver-$pkgrel.zpm"
29 fi
30
31 if [ ! -f $pkgfile ]; then
32         ./zpm-newpackage $package || exit 1
33 else
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 fi
40
41 for path in $*; do
42         mtime=$(stat -c '%Y' $path)
43         uid=$(stat -c '%u' $path)
44         gid=$(stat -c '%g' $path)
45         username=$(stat -c '%U' $path)
46         groupname=$(stat -c '%G' $path)
47         mode=$(stat -c '%a' $path)
48
49         # strip off leading slashes
50         rpath=$(echo "$path" | sed -e 's|^/*||')
51         # and a leading ./
52         rpath=${rpath#./}
53         rpath=$(echo "$rpath" | sed -e 's|^/*||')
54
55         if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
56                 continue
57         fi
58
59         if [ ! -z "$prefix" ]; then
60                 # trailing slashes on prefix
61                 prefix=$(echo "$prefix" | sed -e 's|/*$||')
62                 rpath="$prefix/$rpath"
63         fi
64
65         if [ -f "$path" ]; then
66
67                 hash=$(./zpm-addfile $pkgfile $path)
68
69 #if [ -z "$hash" ]; then continue; fi
70
71 # TODO mtime, mode
72 sqlite3 $pkgfile <<EOS
73 PRAGMA foreign_keys = ON;
74 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,hash)
75 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$hash')
76 ;
77 EOS
78 elif [ -d "$path" ]; then
79 sqlite3 $pkgfile <<EOS
80 PRAGMA foreign_keys = ON;
81 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname)
82 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname')
83 ;
84 EOS
85 elif [ -l "$path" ]; then
86         target=$(readlink $path)
87 sqlite3 $pkgfile <<EOS
88 PRAGMA foreign_keys = ON;
89 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,target)
90 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$target')
91 ;
92 EOS
93 fi
94 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
95 printf "%s\n" $path
96 done