]> pd.if.org Git - zpackage/blob - zpm-addtopackage
05c35963713f4b310f213f2861489cdb61fa039d
[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         appid=$(sqlite3 $pkgfile 'pragma application_id;' | ( echo obase = 16; cat - ) | bc)
37         if [ "$appid" != "5A504442" ]; then
38                 echo $pkgfile does not appear to be a zpm package file
39                 exit 1
40         fi
41 fi
42
43 for path in $*; do
44         mtime=$(zpm stat -f '%y' $path)
45         uid=$(zpm stat -f '%u' $path)
46         gid=$(zpm stat -f '%g' $path)
47         username=$(zpm stat -f '%U' $path)
48         groupname=$(zpm stat -f '%G' $path)
49         mode=$(zpm stat -f '%a' $path)
50
51         # strip off leading slashes
52         rpath=$(echo "$path" | sed -e 's|^/*||')
53         # and a leading ./
54         rpath=${rpath#./}
55         rpath=$(echo "$rpath" | sed -e 's|^/*||')
56
57         if [ -z "$rpath" ] || [ "$rpath" = '.' ]; then
58                 continue
59         fi
60
61         if [ ! -z "$prefix" ]; then
62                 # trailing slashes on prefix
63                 prefix=$(echo "$prefix" | sed -e 's|/*$||')
64                 rpath="$prefix/$rpath"
65         fi
66
67         filetype=$(zpm stat -f '%t' "$path")
68         hash='NULL'
69         target='NULL'
70         case "$filetype" in
71                 regular)
72                         filetype=d
73                         hash=$(zpm addfile $pkgfile "$path")
74                         hash="'$hash'"
75                         filetype=r
76                         ;;
77                 directory)
78                         filetype=d
79                         ;;
80                 symlink)
81                         filetype=l
82                         target=$(readlink $path)
83                         target="'$target'"
84                         ;;
85         esac
86
87         sqlite3 $pkgfile <<EOS
88 PRAGMA foreign_keys = ON;
89 begin;
90 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
91 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
92 commit;
93 EOS
94
95 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
96 printf "%s\n" $path
97 done