2 # ipkg-build -- construct a .ipk from a directory
3 # Waldemar Brodkorb <wbx@openadk.org>
4 # use cpio instead of tar for uid/gid handling
5 # Carl Worth <cworth@east.isi.edu>
6 # based on a script by Steve Redler IV <steve@sr-tech.com>
11 ipkg_extract_value
() {
12 sed -e "s/^[^:]*:[[:space:]]*//"
18 value
=`grep "^$field:" < $CONTROL/control | ipkg_extract_value`
19 if [ -z "$value" ]; then
20 echo "*** Error: $CONTROL/control is missing field $field" >&2
30 value
=`grep "^$field:" < $CONTROL/control | ipkg_extract_value`
31 if [ -n "$value" ]; then
32 echo "*** Error: $CONTROL/control contains disallowed field $field" >&2
47 tilde_files
=`find . -name '*~'`
48 if [ -n "$tilde_files" ]; then
49 if [ "$noclean" = "1" ]; then
50 echo "*** Warning: The following files have names ending in '~'.
51 You probably want to remove them: " >&2
55 echo "*** Removing the following files: $tilde_files"
60 if [ ! -f "$CONTROL/control" ]; then
61 echo "*** Error: Control file $pkg_dir/$CONTROL/control not found." >&2
66 pkg
=`required_field Package`
67 [ "$?" -ne 0 ] && PKG_ERROR
=1
69 version
=`required_field Version | sed 's/Version://; s/^.://g;'`
70 [ "$?" -ne 0 ] && PKG_ERROR
=1
72 arch
=`required_field Architecture`
73 [ "$?" -ne 0 ] && PKG_ERROR
=1
75 required_field Maintainer
>/dev
/null
76 [ "$?" -ne 0 ] && PKG_ERROR
=1
78 required_field Description
>/dev
/null
79 [ "$?" -ne 0 ] && PKG_ERROR
=1
81 section
=`required_field Section`
82 [ "$?" -ne 0 ] && PKG_ERROR
=1
83 if [ -z "$section" ]; then
84 echo "The Section field should have one of the following values:" >&2
85 echo "admin, base, comm, editors, extras, games, graphics, kernel, lang, libs, misc, net, scm, text, web, x11" >&2
88 priority
=`required_field Priority`
89 [ "$?" -ne 0 ] && PKG_ERROR
=1
90 if [ -z "$priority" ]; then
91 echo "The Priority field should have one of the following values:" >&2
92 echo "required, important, standard, optional, extra." >&2
93 echo "If you don't know which priority value you should be using, then use \`optional'" >&2
96 source=`required_field Source`
97 [ "$?" -ne 0 ] && PKG_ERROR
=1
98 if [ -z "$source" ]; then
99 echo "The Source field contain the URL's or filenames of the source code and any patches"
100 echo "used to build this package. Either gnu-style tarballs or Debian source packages "
101 echo "are acceptable. Relative filenames may be used if they are distributed in the same"
102 echo "directory as the .ipk file."
105 disallowed_filename
=`disallowed_field Filename`
106 [ "$?" -ne 0 ] && PKG_ERROR
=1
108 if echo $pkg |
grep '[^a-z0-9.+-]'; then
109 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
113 local bad_fields
=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
114 if [ -n "$bad_fields" ]; then
115 bad_fields
=`echo $bad_fields`
116 echo "*** Error: The following fields in $CONTROL/control are missing a ':'" >&2
117 echo " $bad_fields" >&2
118 echo "ipkg-build: This may be due to a missing initial space for a multi-line field value" >&2
122 for script in $CONTROL/preinst
$CONTROL/postinst
$CONTROL/prerm
$CONTROL/postrm
; do
123 if [ -f $script -a ! -x $script ]; then
124 if [ "$noclean" = "1" ]; then
125 echo "*** Error: package script $script is not executable" >&2
133 if [ -f $CONTROL/conffiles
]; then
134 for cf
in `cat $CONTROL/conffiles`; do
135 if [ ! -f .
/$cf ]; then
136 echo "*** Error: $CONTROL/conffiles mentions conffile $cf which does not exist" >&2
150 usage
="Usage: $0 [-C] <pkg_directory> [<destination_directory>]"
151 while getopts ":h:v" opt
; do
158 h
) echo $usage >&2 ;;
163 shift $
(($OPTIND - 1))
165 # continue on to process additional arguments
173 if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
185 if [ ! -d $pkg_dir ]; then
186 echo "*** Error: Directory $pkg_dir does not exist" >&2
190 # CONTROL is second so that it takes precedence
192 [ -d $pkg_dir/DEBIAN
] && CONTROL
=DEBIAN
193 [ -d $pkg_dir/CONTROL
] && CONTROL
=CONTROL
194 if [ -z "$CONTROL" ]; then
195 echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
199 if ! pkg_appears_sane
$pkg_dir; then
201 echo "ipkg-build: Please fix the above errors and try again." >&2
205 tmp_dir
=$dest_dir/IPKG_BUILD.$$
208 ( cd $pkg_dir && find . |
grep -v $CONTROL | \
209 sed "s#\(.*\)#:0:0::::::\1#" | \
210 sort |
cpio -o -Hustar -P |
gzip -n9 > $tmp_dir/data.
tar.gz
)
212 ( cd $pkg_dir/$CONTROL && find . | \
213 sed "s#\(.*\)#:0:0::::::\1#" | \
214 sort |
cpio -o -Hustar -P |
gzip -n9 > $tmp_dir/control.
tar.gz
)
216 echo "2.0" > $tmp_dir/debian-binary
217 pkg_file
=$dest_dir/${pkg}_${version}_${arch}.ipk
219 ( cd $tmp_dir && tar -zcf $pkg_file .
/debian-binary .
/data.
tar.gz .
/control.
tar.gz
)
220 rm $tmp_dir/debian-binary
$tmp_dir/data.
tar.gz
$tmp_dir/control.
tar.gz
222 echo "Packaged contents of $pkg_dir into $pkg_file"