summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/mkipkg104
1 files changed, 58 insertions, 46 deletions
diff --git a/scripts/mkipkg b/scripts/mkipkg
index 54651af..7877078 100755
--- a/scripts/mkipkg
+++ b/scripts/mkipkg
@@ -1,371 +1,383 @@
1#!/bin/sh 1#!/bin/sh
2# vim: et sw=4 2# vim: et sw=4
3 3
4# TODO: srcdir!=builddir 4# TODO: srcdir!=builddir
5 5
6usage() 6usage()
7{ 7{
8 echo "usage: $self --destdir=[destination installation directory]" 8 echo "usage: $self --destdir=[destination installation directory]"
9 echo "usage: $self [destination installation directory]" 9 echo "usage: $self [destination installation directory]"
10 exit 1 10 exit 1
11} 11}
12 12
13self=mkipkg 13self=mkipkg
14destdir= 14destdir=
15strip=strip 15strip=strip
16control= 16control=
17builddir= 17builddir=
18srcdir= 18srcdir=
19prefix= 19prefix=
20preinst= 20preinst=
21postinst= 21postinst=
22prerm= 22prerm=
23postrm= 23postrm=
24mkfsjffs2= 24mkfsjffs2=
25ipkgbuild=ipkg-build 25ipkgbuild=ipkg-build
26buildversion= 26buildversion=
27subst= 27subst=
28user=root 28user=root
29group=root 29group=root
30filesubst= 30filesubst=
31 31
32oldpwd= 32oldpwd=
33 33
34for option 34for option
35do 35do
36 case "$option" in 36 case "$option" in
37 -*=*) 37 -*=*)
38 arg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` 38 arg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'`
39 ;; 39 ;;
40 esac 40 esac
41 41
42 case "$option" in 42 case "$option" in
43 --destdir=*) 43 --destdir=*)
44 destdir=$arg 44 destdir=$arg
45 ;; 45 ;;
46 --strip=*) 46 --strip=*)
47 strip=$arg 47 strip=$arg
48 ;; 48 ;;
49 --control=*) 49 --control=*)
50 control=$arg 50 control=$arg
51 ;; 51 ;;
52 --preinst=*) 52 --preinst=*)
53 preinst=$arg 53 preinst=$arg
54 ;; 54 ;;
55 --postinst=*) 55 --postinst=*)
56 postinst=$arg 56 postinst=$arg
57 ;; 57 ;;
58 --prerm=*) 58 --prerm=*)
59 prerm=$arg 59 prerm=$arg
60 ;; 60 ;;
61 --postrm=*) 61 --postrm=*)
62 postrm=$arg 62 postrm=$arg
63 ;; 63 ;;
64 --builddir=*) 64 --builddir=*)
65 builddir=$arg 65 builddir=$arg
66 ;; 66 ;;
67 --srcdir=*) 67 --srcdir=*)
68 srcdir=$arg 68 srcdir=$arg
69 ;; 69 ;;
70 --prefix=*) 70 --prefix=*)
71 prefix=$arg 71 prefix=$arg
72 ;; 72 ;;
73 --mkfsjffs2=*) 73 --mkfsjffs2=*)
74 mkfsjffs2=$arg 74 mkfsjffs2=$arg
75 ;; 75 ;;
76 --ipkgbuild=*) 76 --ipkgbuild=*)
77 ipkgbuild=$arg 77 ipkgbuild=$arg
78 ;; 78 ;;
79 --buildversion=*) 79 --buildversion=*)
80 buildversion=$arg 80 buildversion=$arg
81 ;; 81 ;;
82 --subst=*) 82 --subst=*)
83 subst=$arg 83 subst=$arg
84 ;; 84 ;;
85 --user=*) 85 --user=*)
86 user=$arg 86 user=$arg
87 ;; 87 ;;
88 --group=*) 88 --group=*)
89 group=$arg 89 group=$arg
90 ;; 90 ;;
91 --filesubst=*) 91 --filesubst=*)
92 filesubst=$arg 92 filesubst=$arg
93 ;; 93 ;;
94 --classic) 94 --classic)
95 classic=-c 95 classic=-c
96 ;; 96 ;;
97 -*) 97 -*)
98 usage 98 usage
99 ;; 99 ;;
100 *) 100 *)
101 destdir=$option 101 destdir=$option
102 ;; 102 ;;
103 esac 103 esac
104done 104done
105 105
106if [ -z "$control" ]; then 106if [ -z "$control" ]; then
107 control=$destdir/CONTROL/control 107 control=$destdir/CONTROL/control
108fi 108fi
109if [ -z "$prerm" ]; then 109if [ -z "$prerm" ]; then
110 prerm=$destdir/CONTROL/prerm 110 prerm=$destdir/CONTROL/prerm
111fi 111fi
112if [ -z "$postrm" ]; then 112if [ -z "$postrm" ]; then
113 postrm=$destdir/CONTROL/postrm 113 postrm=$destdir/CONTROL/postrm
114fi 114fi
115if [ -z "$preinst" ]; then 115if [ -z "$preinst" ]; then
116 preinst=$destdir/CONTROL/preinst 116 preinst=$destdir/CONTROL/preinst
117fi 117fi
118if [ -z "$postinst" ]; then 118if [ -z "$postinst" ]; then
119 postinst=$destdir/CONTROL/postinst 119 postinst=$destdir/CONTROL/postinst
120fi 120fi
121 121
122# remove leading slash from prefix (to fix globbing) 122# remove leading slash from prefix (to fix globbing)
123if [ -n "$prefix" ]; then 123if [ -n "$prefix" ]; then
124 prefix=`echo $prefix | sed -e "s,/\(.*\),\\1,"` 124 prefix=`echo $prefix | sed -e "s,/\(.*\),\\1,"`
125fi 125fi
126 126
127if [ -z "$destdir" ]; then 127if [ -z "$destdir" ]; then
128 usage 128 usage
129fi 129fi
130 130
131if [ ! -r $control ]; then 131if [ ! -r $control ]; then
132 echo "$self: cannot find $control, exiting..." 132 echo "$self: cannot find $control, exiting..."
133 exit 1 133 exit 1
134fi 134fi
135 135
136if [ -z "`which $ipkgbuild 2>/dev/null`" ]; then 136if [ -z "`which $ipkgbuild 2>/dev/null`" ]; then
137 echo "$self: cannot find ipkg-build, exiting..." 137 echo "$self: cannot find ipkg-build, exiting..."
138 exit 1 138 exit 1
139fi 139fi
140 140
141findFile() 141findFile()
142{ 142{
143 local path= 143 local path=
144 if [ $# = 1 ]; then 144 if [ $# = 1 ]; then
145 find $1 -type f -o -type b -o -type c -o -type l -o -type d 145 find $1 -type f -o -type b -o -type c -o -type l
146 find $1 -type d -a -empty
146 else 147 else
147 find . -type f -o -type b -o -type c -o -type l -o -type d | \ 148 find . -type f -o -type b -o -type c -o -type l | \
148 sed -e "s,\./\(.*\),\\1,g" 149 sed -e "s,\./\(.*\),\\1,g"
150 find . -type d -a -empty
149 fi 151 fi
150
151} 152}
152 153
153_pushd() { oldpwd=`pwd`; cd $1; } 154_pushd() { oldpwd=`pwd`; cd $1; }
154_popd() { cd $oldpwd; } 155_popd() { cd $oldpwd; }
155 156
156setVar() 157setVar()
157{ 158{
158 eval "$1='$2'" 159 eval "$1='$2'"
159} 160}
160 161
161expandMaskToList() 162expandMaskToList()
162{ 163{
163 local _list=`echo $1` 164 local _list=`echo $1`
164 local _tmpFileList= 165 local _tmpFileList=
165 for f in $_list; do 166 for f in $_list; do
166 if [ -d $f ]; then 167 if [ -d $f ]; then
167 find="`findFile $f`" 168 f="`findFile $f`"
168 if [ -z "$find" ]; then
169 find="$f"
170 fi
171 f="$f `findFile $f`"
172 fi 169 fi
173 _tmpFileList=$f" $_tmpFileList" 170 _tmpFileList="`eval echo $f` $_tmpFileList"
174 done 171 done
175 setVar $2 "$_tmpFileList" 172 setVar $2 "$_tmpFileList"
176} 173}
177 174
178createFileList() 175createFileList()
179{ 176{
180 local excludeMask 177 local excludeMask
181 local includeMask 178 local includeMask
179 local includemaskpresent=0
180 local excludemaskpresent=0
181
182 if (cat $1|grep -q ^FileExcludeMask); then 182 if (cat $1|grep -q ^FileExcludeMask); then
183 excludemaskpresent=1 183 excludemaskpresent=1
184 excludeMask=$(eval echo '"'$(sed -n -e "s,^FileExcludeMask: *,,p" $1)'"') 184 excludeMask=$(eval echo '"'$(sed -n -e "s,^FileExcludeMask: *,,p" $1)'"')
185 fi 185 fi
186 if (cat $1|grep -q ^FileIncludeMask); then 186 if (cat $1|grep -q ^FileIncludeMask); then
187 includemaskpresent=1 187 includemaskpresent=1
188 includeMask=$(eval echo '"'$(sed -n -e "s,^FileIncludeMask: *,,p" $1)'"') 188 includeMask=$(eval echo '"'$(sed -n -e "s,^FileIncludeMask: *,,p" $1)'"')
189 else 189 else
190 if (cat $1|grep -q ^Files:); then 190 if (cat $1|grep -q ^Files:); then
191 includemaskpresent=1 191 includemaskpresent=1
192 includeMask=$(eval echo '"'$(sed -n -e "s,^Files: *,,p" $1)'"') 192 includeMask=$(eval echo '"'$(sed -n -e "s,^Files: *,,p" $1)'"')
193 fi 193 fi
194 fi 194 fi
195 195
196 excludeMask="$excludeMask CONTROL/* usr/share/* CVS/* SCCS/*" 196 _pushd $destdir
197
198 excludeMask="$excludeMask CONTROL/* usr/share/*"
197 199
198 if [ $includemaskpresent == 1 ]; then 200 if [ $includemaskpresent != 1 ]; then
199 if [ -z "$includeMask" ]; then 201 includeMask="."
200 setVar $2 "" 202 fi
201 return 0 203
202 fi 204 if [ -z "$includeMask" ]; then
203 _pushd $destdir 205 setVar $2 ""
204 expandMaskToList "$includeMask" _fileList 206 _popd
205 _popd 207 return 0
206 else
207 _fileList=`cd $destdir && findFile`
208 fi 208 fi
209 209
210 expandMaskToList "$includeMask" _fileList
211
210 _excludeList= 212 _excludeList=
211 if [ -n "$excludeMask" ]; then 213 if [ -n "$excludeMask" ]; then
212 _pushd $destdir
213 expandMaskToList "$excludeMask" _excludeList 214 expandMaskToList "$excludeMask" _excludeList
214 _popd 215 _excludeList="$_excludeList `find -name \*CVS\* -o -name \*SCCS\*`"
215 fi 216 fi
216 217
217 local realFileList= 218 local realFileList=
218 local missing=0 219 local missing=0
219 for file in $_fileList; do 220 for file in $_fileList; do
220 local containedInList=0 221 local containedInList=0
221 for i in $_excludeList; do 222 for i in $_excludeList; do
222 if [ $file = $i ]; then 223 if [ $file = $i ]; then
223 containedInList=1 224 containedInList=1
224 fi 225 fi
225 done 226 done
226 if [ $containedInList = 0 ]; then 227 if [ $containedInList = 0 ]; then
227 if [ ! -e $file ]; then 228 if ! [ -e $file -o -L $file ]; then
228# echo "$self: $file not found" 229 echo "$self: $file not found"
229 missing=1 230 missing=1
230 fi 231 fi
231 realFileList=$file" $realFileList" 232 realFileList=$file" $realFileList"
232 fi 233 fi
233 done 234 done
234 235
236 _popd
237
235 if [ $missing = 1 ]; then 238 if [ $missing = 1 ]; then
236 return 1 239 return 1
237 fi 240 fi
238 241
239 setVar $2 "$realFileList" 242 setVar $2 "$realFileList"
240} 243}
241 244
242stripFile() 245stripFile()
243{ 246{
244 if [ -f $1 -a -x $1 ]; then 247 if [ -f $1 -a -x $1 ]; then
245 $strip --strip-all $1 248 $strip --strip-all $1
246 fi 249 fi
247} 250}
248 251
249substFile() 252substFile()
250{ 253{
251 local oldfile=$1 254 local oldfile=$1
252 255
253 if [ ! -e $2 ]; then return 1; fi 256 if [ ! -e $2 ]; then return 1; fi
254 257
255 if [ -e $oldfile ]; then 258 if [ -e $oldfile -o -L $oldfile ]; then
256 newfile=./`echo $1|sed -f $2|sed -e's,^/,,g'` 259 newfile=`echo $oldfile|sed -f $2|sed -e's,^/,,g'`
257 olddir=./`dirname $1` 260 olddir=`dirname $oldfile`
261 base=`basename $oldfile`
258 newdir=`dirname $newfile` 262 newdir=`dirname $newfile`
259 263
264# echo >&2 moving $oldfile to $newfile
265
260 if [ "$newdir" = "$olddir" ]; then 266 if [ "$newdir" = "$olddir" ]; then
261 return 0 267 return 0
262 fi 268 fi
263 269
264 mkdir -p $newdir 270 mkdir -p $newdir
265 mv $1 $newfile 271 mv $olddir/$base $newfile
266 rmdir -p $olddir 2>/dev/null 272 rmdir -p $olddir 2>/dev/null
267 fi 273 fi
268} 274}
269 275
270stripFiles() 276stripFiles()
271{ 277{
272 for f in $1; do 278 for f in $1; do
273 stripFile $f 279 stripFile ./$f
274 done 280 done
275} 281}
276 282
277substFiles() 283substFiles()
278{ 284{
279 for f in $1; do 285 for f in $1; do
280 substFile $f 286 substFile ./$f
281 done 287 done
282} 288}
283 289
284substAndStripFiles() 290substAndStripFiles()
285{ 291{
286 for f in $1; do 292 for f in $1; do
287 stripFile $f 293 stripFile ./$f
288 substFile $f $2 294 substFile ./$f $2
289 done 295 done
290} 296}
291 297
292installScript() 298installScript()
293{ 299{
294 if [ -n "$1" -a -f "$1" ]; then 300 if [ -n "$1" -a -f "$1" ]; then
295 destfile=`basename $1` 301 destfile=`basename $1`
302 filetype=`echo $destfile|cut -d. -f2`
303 if [ -n "$filetype" ]; then destfile=$filetype; fi
296 if [ -n "$subst" ]; then 304 if [ -n "$subst" ]; then
297 sed -f $subst < $1 > $ctrldir/$destfile 305 sed -f $subst < $1 > $ctrldir/$destfile
298 else 306 else
299 cat $1 > $ctrldir/$destfile 307 cat $1 > $ctrldir/$destfile
300 fi 308 fi
301 chmod +x $ctrldir/$destfile 309 chmod +x $ctrldir/$destfile
302 fi 310 fi
303} 311}
304 312
305tempDir=/tmp/`basename $self`.$$ 313tempDir=/tmp/`basename $self`.$$
306mkdir -p $tempDir 314mkdir -p $tempDir
307if [ $? != 0 ]; then 315if [ $? != 0 ]; then
308 echo "$self: cannot create $tempDir, exiting..." 316 echo "$self: cannot create $tempDir, exiting..."
309 exit 1 317 exit 1
310fi 318fi
311 319
312cd $destdir; createFileList $control ipkgFileList 320ctrldir=$tempDir/CONTROL
321
322mkdir -p $ctrldir
323
324if [ ! -e $subst ] || [ -z "$subst" ]; then
325 cat $control > $ctrldir/control.new
326else
327 sed -f $subst < $control > $ctrldir/control.new
328fi
329
330createFileList $ctrldir/control.new ipkgFileList
331
313if [ "$?" != "0" ]; then 332if [ "$?" != "0" ]; then
314 echo "$self: ERROR: missing files, not building $control" 333 echo "$self: ERROR: missing files, not building $control"
315 exit 1 334 exit 1
316fi 335fi
317 336
318( cd $destdir && tar cf - $ipkgFileList 2>/dev/null ) | \ 337
319( cd $tempDir && tar xf - 2>/dev/null ) 338cat $ctrldir/control.new | egrep -v '^(Files|FileExcludeMask|FileIncludeMask):' > $ctrldir/control
339rm -f $ctrldir/control.new
340
341( cd $destdir && tar -cf - $ipkgFileList 2>/dev/null ) | ( cd $tempDir && tar -xf - 2>/dev/null )
320 342
321if [ -z "$filesubst" ]; then 343if [ -z "$filesubst" ]; then
322 ( cd $tempDir && stripFiles "$ipkgFileList" ) 344 ( cd $tempDir && stripFiles "$ipkgFileList" )
323else 345else
324 if ! (echo $filesubst|grep -q '^/'); then 346 if ! (echo $filesubst|grep -q '^/'); then
325 filesubst="$oldpwd/$filesubst" 347 filesubst="$oldpwd/$filesubst"
326 fi 348 fi
327 ( cd $tempDir && substAndStripFiles "$ipkgFileList" $filesubst ) 349 ( cd $tempDir && substAndStripFiles "$ipkgFileList" $filesubst )
328fi 350fi
329 351
330path="`echo "$PATH" | sed -e "s/\:/ /g"`" 352path="`echo "$PATH" | sed -e "s/\:/ /g"`"
331if [ -z "$mkfsjffs2" ]; then 353if [ -z "$mkfsjffs2" ]; then
332 for i in $path; do 354 for i in $path; do
333 if [ -x "$i/mkfs.jffs2" ]; then 355 if [ -x "$i/mkfs.jffs2" ]; then
334 mkfsjffs2="$i/mkfs.jffs2" 356 mkfsjffs2="$i/mkfs.jffs2"
335 break 357 break
336 fi 358 fi
337 done 359 done
338fi 360fi
339 361
340if [ -z "$mkfsjffs2" ]; then 362if [ -z "$mkfsjffs2" ]; then
341 echo "$self: WARNING: no mkjfs.jffs2 found in path. Falling back to using du" 363 echo "$self: WARNING: no mkjfs.jffs2 found in path. Falling back to using du"
342 echo "for size calculation. mkfs.jffs2 is recommended for size calculation" 364 echo "for size calculation. mkfs.jffs2 is recommended for size calculation"
343 echo "as it calculates the real package size on the compressed file system," 365 echo "as it calculates the real package size on the compressed file system,"
344 echo "in contrast to du calculating the uncompressed size!" 366 echo "in contrast to du calculating the uncompressed size!"
345 buildsize=`du -h -s $tempDir | awk '{print $1}'` 367 buildsize=`du -h -s $tempDir | awk '{print $1}'`
346else 368else
347 buildsize=`$mkfsjffs2 -r $tempDir | wc -c` 369 buildsize=`$mkfsjffs2 -r $tempDir | wc -c`
348fi 370fi
349 371
350ctrldir=$tempDir/CONTROL
351
352mkdir -p $ctrldir
353
354if [ ! -e $subst ] || [ -z "$subst" ]; then
355 cat $control | egrep -v '^(FileIncludeMask|FileExcludeMask|Files):' > $ctrldir/control
356else
357 sed -f $subst < $control | egrep -v '^(FileIncludeMask|FileExcludeMask|Files):' > $ctrldir/control
358fi
359
360if [ "$buildsize" != "0" ]; then 372if [ "$buildsize" != "0" ]; then
361 echo "Installed-Size: $buildsize" >> $ctrldir/control 373 echo "Installed-Size: $buildsize" >> $ctrldir/control
362fi 374fi
363 375
364installScript $preinst 376installScript $preinst
365installScript $postinst 377installScript $postinst
366installScript $prerm 378installScript $prerm
367installScript $posrm 379installScript $posrm
368 380
369$ipkgbuild $classic -o $user -g $group $tempDir 381$ipkgbuild $classic -o $user -g $group $tempDir
370 382
371rm -rf $tempDir 383rm -rf $tempDir