source: ipk/ipkg-utils-050831/ipkg-buildpackage@ 20249

Last change on this file since 20249 was 4890, checked in by obi, 15 years ago

[ipk] fix executable rights

  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/bin/sh
2#
3# $Id: ipkg-buildpackage,v 1.1 2001/07/26 15:36:36 oku Exp $
4#
5# Author: Oliver Kurth <oliver.kurth@innominate.com>
6#
7# Description:
8# builds an ipkg package from a source tarball using ipkg-build. Idea stolen
9# from Debian dpkg-buildpackage.
10#
11# - unpack the source tarball.
12# - cd to the source distribution, change whatever you need to make the
13# package compile and work on the ipaq.
14# - create a directory 'ipkg'
15# - put all files which go to the 'CONTROL' directory of the root of the
16# installed package into ipkg.
17# - the version (Version field in control) should match the version of the
18# source tarball, optionally with a digit (eg. -1) appended.
19# - additionally, put a file there called 'rules' which is a shell script
20# accepting arguments 'build', 'install' and 'clean'. It can be a
21# Makefile starting with the line '#!/usr/bin/make -f'
22# * the build target does things like ./configure and make.
23# * the install target installs to a temporary directory (make
24# DESTDIR=/tmp/package) and removes unnecessary items (eg. man pages)
25# * clean cleans ;-)
26#
27# You should run this with fakeroot (1) or as root.
28# If all went well, you will find a diff file and an *.ipk file in the
29# directory above.
30
31set -e
32
33#SCRIPTDIR=/usr/local/bin
34SCRIPTDIR=/other/kurth/ipaq-dev/familiar/dist/ipkg/util/
35
36SCRIPTNAME=`basename $0`
37
38ipkg_extract_value() {
39 sed -e "s/^[^:]*:[[:space:]]*//"
40}
41
42required_field() {
43 field=$1
44
45 value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value`
46 if [ -z "$value" ]; then
47 echo "ipkg-build: Error: $CONTROL/control is missing field $field" ;
48 PKG_ERROR=1
49 fi
50 echo $value
51}
52
53pkg_appears_sane_control() {
54 local pkg_dir=$1
55
56 local owd=`pwd`
57 cd $pkg_dir
58
59 if [ ! -f "$CONTROL/control" ]; then
60 echo "ipkg-build: Error: Control file $pkg_dir/$CONTROL/control not found."
61 cd $owd
62 return 1
63 fi
64
65 pkg=`required_field Package`
66 version=`required_field Version | sed 's/.*://;'`
67 arch=`required_field Architecture`
68 required_field Maintainer >/dev/null
69 required_field Description >/dev/null
70
71 if echo $pkg | grep '[^a-z0-9.+-]'; then
72 echo "ipkg-build: Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])"
73 PKG_ERROR=1;
74 fi
75
76 local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
77 if [ -n "$bad_fields" ]; then
78 bad_fields=`echo $bad_fields`
79 echo "ipkg-build: Error: The following fields in $CONTROL/control are missing a ':'"
80 echo " $bad_fields"
81 echo "ipkg-build: This may be due to a missing initial space for a multi-line field value"
82 PKG_ERROR=1
83 fi
84
85 cd $owd
86 return $PKG_ERROR
87}
88
89pkg_appears_sane_scripts() {
90 local pkg_dir=$1
91
92 local owd=`pwd`
93 cd $pkg_dir
94
95 for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do
96 if [ -f $script -a ! -x $script ]; then
97 echo "ipkg-build: Error: package script $script is not executable"
98 PKG_ERROR=1
99 fi
100 done
101
102 cd $owd
103 return $PKG_ERROR
104}
105
106pkg_dir_abs=`pwd`
107pkg_dir_base=`basename ${pkg_dir_abs}`
108
109pkg_dir=.
110
111[ -d ./CONTROL ] && CONTROL=./CONTROL
112[ -d ./ipkg ] && CONTROL=./ipkg
113if [ -z "$CONTROL" ]; then
114 echo "${SCRIPT_NAME}: Error: Directory $pkg_dir has no ipkg or CONTROL subdirectory."
115 exit 1
116fi
117
118if ! pkg_appears_sane_control $pkg_dir && pkg_appears_sane_control $pkg_dir; then
119 echo "Please fix the above errors and try again."
120 exit 1
121fi
122
123echo "Package = $pkg"
124echo "Version = $version"
125version_up=`echo ${version} | sed "s/\-[0-9]\+//"`
126echo "Upstream Version = $version_up"
127pkg_upname=${pkg}-${version_up}
128echo "Package Name = $pkg_upname"
129pkg_tarball=${pkg_upname}.tar.gz
130echo "Tarball Name = $pkg_tarball"
131
132if [ ! -x ${CONTROL}/rules ]; then
133 echo "${CONTROL}/rules not found or not executable."
134 exit 1
135fi
136
137#
138# unpack upstream tarball and make diff
139#
140if [ -e ../${pkg_tarball} ] ; then
141 (
142 set +e
143
144 cd ..
145
146 rm -rf ${pkg_upname}.tmp
147 rm -rf ${pkg_upname}.orig
148
149 mkdir ${pkg_upname}.tmp
150 cd ${pkg_upname}.tmp
151 echo "unpacking source tarball ${pkg_tarball}"
152 tar zxf ${pkg_dir_abs}/../${pkg_tarball}
153 dir=`find . -maxdepth 1 -name "*" -type d`
154 cnt=`echo $dir | wc -l`
155 if [ ${cnt} != 1 ] ; then
156 echo "Arrghh !!!!"
157 echo "upstream package contains more than one top level directory"
158 echo "giving up..."
159 exit 1
160 fi
161 mv ${dir} ${pkg_upname}.orig
162 mv ${pkg_upname}.orig ..
163 cd ..
164 echo "creating diff"
165 diff -uNr ${pkg_upname}.orig ${pkg_dir_base} > ${pkg}-${version}.diff
166 rm -f ${pkg}-${version}.diff.gz
167 echo "gzipping ${pkg}-${version}.diff"
168 gzip ${pkg}-${version}.diff
169
170 echo "Removing temporary source directorys"
171 rm -rf ${pkg_upname}.tmp
172 rm -rf ${pkg_upname}.orig
173 )
174fi
175
176# build package
177if ! ${CONTROL}/rules build; then
178 echo "Build failed"
179 exit 1
180fi
181
182# install it to tmp directory
183if ! ${CONTROL}/rules install; then
184 echo "Install failed"
185 exit 1
186fi
187
188# copy contents of control directory
189mkdir /tmp/${pkg}/CONTROL
190
191files_required="control"
192files_optional="preinst postinst prerm postrm"
193
194for i in ${files_required} ; do
195 file=${CONTROL}/$i
196
197 if [ -e ${file} ] ; then
198 cp $file /tmp/${pkg}/CONTROL
199 else
200 echo "required file ${file} missing"
201 fi
202done
203
204for i in ${files_optional} ; do
205 file=${CONTROL}/$i
206
207 if [ -e ${file} ] ; then
208 cp $file /tmp/${pkg}/CONTROL
209 fi
210done
211
212# build the ipk package
213owd=`pwd`
214cd ..
215ipkg-build /tmp/${pkg} || exit 1
216
217rm -rf /tmp/${pkg}
218
219cd $owd
220if ! ${CONTROL}/rules clean; then
221 echo "Clean failed"
222 exit 1
223fi
224
225# Yep. That's it!
226exit 0
Note: See TracBrowser for help on using the repository browser.