]> pd.if.org Git - zpackage/blob - zpm-addtopackage
1964b77589e29f6cf58778cb3b8e24fdc4a57cc0
[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 package="$1"
28 shift
29
30 set -e
31 if [ -z "$pkgfile" ]; then
32         pkgfile="$package-$pkgver-$pkgrel.zpm"
33 fi
34
35 if [ ! -f $pkgfile ]; then
36         zpm newpackage $package || exit 1
37 else
38         zpm test -v $pkgfile
39 fi
40
41 for path in $*; do
42         mtime=$(zpm stat -f '%y' $path)
43         uid=$(zpm stat -f '%u' $path)
44         gid=$(zpm stat -f '%g' $path)
45         username=$(zpm stat -f '%U' $path)
46         groupname=$(zpm stat -f '%G' $path)
47         mode=$(zpm stat -f '%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         filetype=$(zpm stat -f '%t' "$path")
66         hash='NULL'
67         target='NULL'
68         case "$filetype" in
69                 regular)
70                         filetype=d
71                         hash=$(zpm addfile $pkgfile "$path")
72                         hash="'$hash'"
73                         filetype=r
74                         ;;
75                 directory)
76                         filetype=d
77                         ;;
78                 symlink)
79                         filetype=l
80                         target=$(readlink $path)
81                         target="'$target'"
82                         ;;
83         esac
84
85         sqlite3 $pkgfile <<EOS
86 PRAGMA foreign_keys = ON;
87 begin;
88 insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
89 values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
90 commit;
91 EOS
92
93 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
94 printf "%s\n" $path
95 done