]> pd.if.org Git - zpackage/blob - zpm-addtopackage
exit with failure status if soname not found
[zpackage] / zpm-addtopackage
1 #!/bin/sh
2
3 pkgver=${ZPMPKGVER:-1.0}
4 pkgrel=${ZPMPKGREL:-1}
5
6 # option for "multipackage" just to let the system know that's what you meant
7 # option to take filenames from stdin
8 # parse package, version, release from file if not given
9 while getopts :f:v:r:d:a:u:l:p:b:P: opt; do
10         case $opt in
11                 f) pkgfile="$OPTARG" ;;
12                 v) pkgver="$OPTARG" ;;
13                 r) pkgrel="$OPTARG" ;;
14                 d) description="$OPTARG" ;;
15                 a) arch="$OPTARG" ;;
16                 u) url="$OPTARG" ;;
17                 l) licenses="$OPTARG" ;;
18                 p) packager="$OPTARG" ;;
19                 b) builddate="$OPTARG" ;;
20                 P) prefix="$OPTARG" ;;
21                 t) tags="$OPTARG" ;;
22                 c) tags="$tags +configuration" ;;
23         esac
24 done
25 shift $((OPTIND - 1))
26
27 die() {
28         echo $* 1&>2
29         exit 1
30 }
31
32 package="$1"
33 shift
34 if [ -z "$package" ]; then
35         die "must specify package"
36 fi
37
38 set -e
39 if [ -z "$pkgfile" ]; then
40         pkgfile="$package-$pkgver-$pkgrel.zpm"
41 fi
42
43 # make sure package exists
44 zpm newpackage -I -f $pkgfile -v $pkgver -r $pkgrel $package || exit 1
45
46 zpm test -v $pkgfile
47
48 for path in $*; do
49         mtime=$(zpm stat -f '%y' $path)
50         uid=$(zpm stat -f '%u' $path)
51         gid=$(zpm stat -f '%g' $path)
52         username=$(zpm stat -f '%U' $path)
53         groupname=$(zpm stat -f '%G' $path)
54         mode=$(zpm stat -f '%a' $path)
55
56         # strip off leading slashes
57         rpath=$(echo "$path" | sed -e 's|^/*||')
58         # and a leading ./
59         rpath=${rpath#./}
60         rpath=$(echo "$rpath" | sed -e 's|^/*||')
61
62         if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
63                 continue
64         fi
65
66         if [ ! -z "$prefix" ]; then
67                 # trailing slashes on prefix
68                 prefix=$(echo "$prefix" | sed -e 's|/*$||')
69                 rpath="$prefix/$rpath"
70         fi
71
72         filetype=$(zpm stat -f '%t' "$path")
73         hash='NULL'
74         target='NULL'
75         case "$filetype" in
76                 regular)
77                         filetype=r
78                         hash=$(zpm addfile $pkgfile "$path")
79                         if [ $? -ne 0 ]; then
80                                 die "zpm addfile failed ($?): $pkgfile $path" 
81                         fi
82                         hash="'$hash'"
83                         ;;
84                 directory)
85                         filetype=d
86                         ;;
87                 symlink)
88                         filetype=l
89                         target=$(readlink $path)
90                         target="'$target'"
91                         ;;
92         esac
93
94         sqlite3 $pkgfile <<EOS
95 PRAGMA foreign_keys = ON;
96 begin;
97 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
98 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
99 commit;
100 EOS
101
102 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
103 printf "%s\n" $path
104 done