3 # opkg-build -- construct a .opk 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
9 sed -e "s/^[^:]*:[[:space:]]*//"
15 value=`grep "^$field:" < $CONTROL/control | opkg_extract_value`
16 if [ -z "$value" ]; then
17 echo "opkg-build: Error: $CONTROL/control is missing field $field" ;
30 if [ ! -f "$CONTROL/control" ]; then
31 echo "opkg-build: Error: Control file $pkg_dir/$CONTROL/control not found."
36 pkg=`required_field Package`
37 version=`required_field Version`
38 arch=`required_field Architecture`
39 required_field Maintainer >/dev/null
40 required_field Description >/dev/null
42 if echo $pkg | grep '[^a-z0-9.+-]'; then
43 echo "opkg-build: Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])"
47 local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
48 if [ -n "$bad_fields" ]; then
49 bad_fields=`echo $bad_fields`
50 echo "opkg-build: Error: The following fields in $CONTROL/control are missing a ':'"
52 echo "opkg-build: This may be due to a missing initial space for a multi-line field value"
56 for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do
57 if [ -f $script -a ! -x $script ]; then
58 echo "opkg-build: Error: package script $script is not executable"
63 if [ -f $CONTROL/conffiles ]; then
64 for cf in `cat $CONTROL/conffiles`; do
65 if [ ! -f ./$cf ]; then
66 echo "opkg-build: Error: $CONTROL/conffiles mentions conffile $cf which does not exist"
88 echo "Usage: opkg-build <pkg_directory> [<destination_directory>]" ;
95 if [ ! -d $pkg_dir ]; then
96 echo "opkg-build: Error: Directory $pkg_dir does not exist"
100 # CONTROL is second so that it takes precedence
102 [ -d $pkg_dir/DEBIAN ] && CONTROL=DEBIAN
103 [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL
104 if [ -z "$CONTROL" ]; then
105 echo "opkg-build: Error: Directory $pkg_dir has no CONTROL subdirectory."
109 if ! pkg_appears_sane $pkg_dir; then
110 echo "Please fix the above errors and try again."
114 tmp_dir=$dest_dir/OPKG_BUILD.$$
117 tar -C $pkg_dir -czf $tmp_dir/data.tar.gz . --exclude=$CONTROL
118 tar -C $pkg_dir/$CONTROL -czf $tmp_dir/control.tar.gz .
120 echo "2.0" > $tmp_dir/debian-binary
122 pkg_file=$dest_dir/${pkg}_${version}_${arch}.opk
123 tar -C $tmp_dir -czf $pkg_file debian-binary data.tar.gz control.tar.gz
124 rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz
127 echo "Packaged contents of $pkg_dir into $pkg_file"