root/trunk/freewrt/scripts/ipkg-build

Revision 2295, 6.3 kB (checked in by tg, 2 years ago)

more from the “coolz” departement:
• get rid of dependency on external ipkg and python stuff
• one distfile less too ;)
• while here, remove executable bits on more shell scripts

tested with a defaultconfig full bootstrap (cleandir+v)

Line 
1 #!/bin/sh
2
3 # ipkg-build -- construct a .ipk from a directory
4 # Carl Worth <cworth@east.isi.edu>
5 # based on a script by Steve Redler IV, steve@sr-tech.com 5-21-2001
6 # 2003-04-25 rea@sr.unh.edu
7 #   Updated to work on Familiar Pre0.7rc1, with busybox tar.
8 #   Note it Requires: binutils-ar (since the busybox ar can't create)
9 #   For UID debugging it needs a better "find".
10 set -e
11
12 version=1.0
13
14 ipkg_extract_value() {
15         sed -e "s/^[^:]*:[[:space:]]*//"
16 }
17
18 required_field() {
19         field=$1
20
21         value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value`
22         if [ -z "$value" ]; then
23                 echo "*** Error: $CONTROL/control is missing field $field" >&2
24                 return 1
25         fi
26         echo $value
27         return 0
28 }
29
30 disallowed_field() {
31         field=$1
32
33         value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value`
34         if [ -n "$value" ]; then
35                 echo "*** Error: $CONTROL/control contains disallowed field $field" >&2
36                 return 1
37         fi
38         echo $value
39         return 0
40 }
41
42 pkg_appears_sane() {
43         local pkg_dir=$1
44
45         local owd=$PWD
46         cd $pkg_dir
47
48         PKG_ERROR=0
49
50         cvs_dirs=`find . -name 'CVS'`
51         if [ -n "$cvs_dirs" ]; then
52             if [ "$noclean" = "1" ]; then
53                 echo "*** Warning: The following CVS directories where found.
54 You probably want to remove them: " >&2
55                 ls -ld $cvs_dirs
56                 echo >&2
57             else
58                 echo "*** Removing the following files: $cvs_dirs"
59                 rm -rf "$cvs_dirs"
60             fi
61         fi
62
63         tilde_files=`find . -name '*~'`
64         if [ -n "$tilde_files" ]; then
65             if [ "$noclean" = "1" ]; then
66                 echo "*** Warning: The following files have names ending in '~'.
67 You probably want to remove them: " >&2
68                 ls -ld $tilde_files
69                 echo >&2
70             else
71                 echo "*** Removing the following files: $tilde_files"
72                 rm -f "$tilde_files"
73             fi
74         fi
75
76         if [ ! -f "$CONTROL/control" ]; then
77                 echo "*** Error: Control file $pkg_dir/$CONTROL/control not found." >&2
78                 cd $owd
79                 return 1
80         fi
81
82         pkg=`required_field Package`
83         [ "$?" -ne 0 ] && PKG_ERROR=1
84
85         version=`required_field Version | sed 's/Version://; s/^.://g;'`
86         [ "$?" -ne 0 ] && PKG_ERROR=1
87
88         arch=`required_field Architecture`
89         [ "$?" -ne 0 ] && PKG_ERROR=1
90
91         required_field Maintainer >/dev/null
92         [ "$?" -ne 0 ] && PKG_ERROR=1
93
94         required_field Description >/dev/null
95         [ "$?" -ne 0 ] && PKG_ERROR=1
96
97         section=`required_field Section`
98         [ "$?" -ne 0 ] && PKG_ERROR=1
99         if [ -z "$section" ]; then
100             echo "The Section field should have one of the following values:" >&2
101             echo "admin, base, comm, editors, extras, games, graphics, kernel, libs, misc, net, text, web, x11" >&2
102         fi
103
104         priority=`required_field Priority`
105         [ "$?" -ne 0 ] && PKG_ERROR=1
106         if [ -z "$priority" ]; then
107             echo "The Priority field should have one of the following values:" >&2
108             echo "required, important, standard, optional, extra." >&2
109             echo "If you don't know which priority value you should be using, then use \`optional'" >&2
110         fi
111
112         source=`required_field Source`
113         [ "$?" -ne 0 ] && PKG_ERROR=1
114         if [ -z "$source" ]; then
115             echo "The Source field contain the URL's or filenames of the source code and any patches"
116             echo "used to build this package.  Either gnu-style tarballs or Debian source packages "
117             echo "are acceptable.  Relative filenames may be used if they are distributed in the same"
118             echo "directory as the .ipk file."
119         fi
120
121         disallowed_filename=`disallowed_field Filename`
122         [ "$?" -ne 0 ] && PKG_ERROR=1
123
124         if echo $pkg | grep '[^a-z0-9.+-]'; then
125                 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
126                 PKG_ERROR=1;
127         fi
128
129         local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
130         if [ -n "$bad_fields" ]; then
131                 bad_fields=`echo $bad_fields`
132                 echo "*** Error: The following fields in $CONTROL/control are missing a ':'" >&2
133                 echo "  $bad_fields" >&2
134                 echo "ipkg-build: This may be due to a missing initial space for a multi-line field value" >&2
135                 PKG_ERROR=1
136         fi
137
138         for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do
139                 if [ -f $script -a ! -x $script ]; then
140                     if [ "$noclean" = "1" ]; then
141                         echo "*** Error: package script $script is not executable" >&2
142                         PKG_ERROR=1
143                     else
144                         chmod a+x $script
145                     fi
146                 fi
147         done
148
149         if [ -f $CONTROL/conffiles ]; then
150                 for cf in `cat $CONTROL/conffiles`; do
151                         if [ ! -f ./$cf ]; then
152                                 echo "*** Error: $CONTROL/conffiles mentions conffile $cf which does not exist" >&2
153                                 PKG_ERROR=1
154                         fi
155                 done
156         fi
157
158         cd $owd
159         return $PKG_ERROR
160 }
161
162 ###
163 # ipkg-build "main"
164 ###
165 ogargs=""
166 outer=ar
167 noclean=0
168 usage="Usage: $0 [-c] [-C] [-o owner] [-g group] <pkg_directory> [<destination_directory>]"
169 while getopts "cg:ho:v" opt; do
170     case $opt in
171         o ) owner=$OPTARG
172 #           ogargs="--owner=$owner"
173             ogargs="-M uidgid"
174             ;;
175         g ) group=$OPTARG
176 #           ogargs="$ogargs --group=$group"
177             ogargs="-M uidgid"
178             ;;
179         c ) outer=tar
180             ;;
181         C ) noclean=1
182             ;;
183         v ) echo $version
184             exit 0
185             ;;
186         h )     echo $usage  >&2 ;;
187         \? )    echo $usage  >&2
188         esac
189 done
190
191
192 shift $(($OPTIND - 1))
193
194 # continue on to process additional arguments
195
196 case $# in
197 1)
198         dest_dir=$PWD
199         ;;
200 2)
201         dest_dir=$2
202         if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
203             dest_dir=$PWD
204         fi
205         ;;
206 *)
207         echo $usage >&2
208         exit 1
209         ;;
210 esac
211
212 pkg_dir=$1
213
214 if [ ! -d $pkg_dir ]; then
215         echo "*** Error: Directory $pkg_dir does not exist" >&2
216         exit 1
217 fi
218
219 # CONTROL is second so that it takes precedence
220 CONTROL=
221 [ -d $pkg_dir/DEBIAN ] && CONTROL=DEBIAN
222 [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL
223 if [ -z "$CONTROL" ]; then
224         echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
225         exit 1
226 fi
227
228 if ! pkg_appears_sane $pkg_dir; then
229         echo >&2
230         echo "ipkg-build: Please fix the above errors and try again." >&2
231         exit 1
232 fi
233
234 tmp_dir=$dest_dir/IPKG_BUILD.$$
235 mkdir $tmp_dir
236
237 ( cd $pkg_dir && pax -rw -pe $CONTROL $tmp_dir/ )
238 rm -rf $pkg_dir/$CONTROL
239 ( cd $pkg_dir && tar $ogargs -czf $tmp_dir/data.tar.gz . )
240 ( cd $tmp_dir && pax -rw -pe $CONTROL $pkg_dir/ )
241 ( cd $pkg_dir/$CONTROL && tar $ogargs -czf $tmp_dir/control.tar.gz . )
242 rm -rf $tmp_dir/$CONTROL
243
244 echo "2.0" > $tmp_dir/debian-binary
245
246 pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk
247 rm -f $pkg_file
248 if [ "$outer" = "ar" ] ; then
249   ( cd $tmp_dir && ar -crf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz )
250 else
251   ( cd $tmp_dir && tar -zcf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz )
252 fi
253
254 rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz
255 rmdir $tmp_dir
256
257 echo "Packaged contents of $pkg_dir into $pkg_file"
Note: See TracBrowser for help on using the browser.