]> pd.if.org Git - zpackage/blob - zpm-addtopackage
cccd12de666d3ce2c0574207583f2120401448db
[zpackage] / zpm-addtopackage
1 #!/bin/sh
2
3 package=${1:-$ZPMPACKAGE}
4 shift
5 pkgver=${ZPMPKGVER:-1.0}
6 pkgrel=${ZPMPKGREL:-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                 t) tags="$OPTARG" ;;
24                 c) tags="$tags +configuration" ;;
25         esac
26 done
27
28 set -e
29 if [ -z "$pkgfile" ]; then
30         pkgfile="$package-$pkgver-$pkgrel.zpm"
31 fi
32
33 if [ ! -f $pkgfile ]; then
34         zpm newpackage $package || exit 1
35 else
36         zpm-test -v $pkgfile
37 fi
38
39 for path in $*; do
40         mtime=$(zpm stat -f '%y' $path)
41         uid=$(zpm stat -f '%u' $path)
42         gid=$(zpm stat -f '%g' $path)
43         username=$(zpm stat -f '%U' $path)
44         groupname=$(zpm stat -f '%G' $path)
45         mode=$(zpm stat -f '%a' $path)
46
47         # strip off leading slashes
48         rpath=$(echo "$path" | sed -e 's|^/*||')
49         # and a leading ./
50         rpath=${rpath#./}
51         rpath=$(echo "$rpath" | sed -e 's|^/*||')
52
53         if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
54                 continue
55         fi
56
57         if [ ! -z "$prefix" ]; then
58                 # trailing slashes on prefix
59                 prefix=$(echo "$prefix" | sed -e 's|/*$||')
60                 rpath="$prefix/$rpath"
61         fi
62
63         filetype=$(zpm stat -f '%t' "$path")
64         hash='NULL'
65         target='NULL'
66         case "$filetype" in
67                 regular)
68                         filetype=d
69                         hash=$(zpm addfile $pkgfile "$path")
70                         hash="'$hash'"
71                         filetype=r
72                         ;;
73                 directory)
74                         filetype=d
75                         ;;
76                 symlink)
77                         filetype=l
78                         target=$(readlink $path)
79                         target="'$target'"
80                         ;;
81         esac
82
83         sqlite3 $pkgfile <<EOS
84 PRAGMA foreign_keys = ON;
85 begin;
86 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
87 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
88 commit;
89 EOS
90
91 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
92 printf "%s\n" $path
93 done