| 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 |
|
|---|
| 31 | set -e
|
|---|
| 32 |
|
|---|
| 33 | #SCRIPTDIR=/usr/local/bin
|
|---|
| 34 | SCRIPTDIR=/other/kurth/ipaq-dev/familiar/dist/ipkg/util/
|
|---|
| 35 |
|
|---|
| 36 | SCRIPTNAME=`basename $0`
|
|---|
| 37 |
|
|---|
| 38 | ipkg_extract_value() {
|
|---|
| 39 | sed -e "s/^[^:]*:[[:space:]]*//"
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | required_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 |
|
|---|
| 53 | pkg_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 |
|
|---|
| 89 | pkg_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 |
|
|---|
| 106 | pkg_dir_abs=`pwd`
|
|---|
| 107 | pkg_dir_base=`basename ${pkg_dir_abs}`
|
|---|
| 108 |
|
|---|
| 109 | pkg_dir=.
|
|---|
| 110 |
|
|---|
| 111 | [ -d ./CONTROL ] && CONTROL=./CONTROL
|
|---|
| 112 | [ -d ./ipkg ] && CONTROL=./ipkg
|
|---|
| 113 | if [ -z "$CONTROL" ]; then
|
|---|
| 114 | echo "${SCRIPT_NAME}: Error: Directory $pkg_dir has no ipkg or CONTROL subdirectory."
|
|---|
| 115 | exit 1
|
|---|
| 116 | fi
|
|---|
| 117 |
|
|---|
| 118 | if ! 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
|
|---|
| 121 | fi
|
|---|
| 122 |
|
|---|
| 123 | echo "Package = $pkg"
|
|---|
| 124 | echo "Version = $version"
|
|---|
| 125 | version_up=`echo ${version} | sed "s/\-[0-9]\+//"`
|
|---|
| 126 | echo "Upstream Version = $version_up"
|
|---|
| 127 | pkg_upname=${pkg}-${version_up}
|
|---|
| 128 | echo "Package Name = $pkg_upname"
|
|---|
| 129 | pkg_tarball=${pkg_upname}.tar.gz
|
|---|
| 130 | echo "Tarball Name = $pkg_tarball"
|
|---|
| 131 |
|
|---|
| 132 | if [ ! -x ${CONTROL}/rules ]; then
|
|---|
| 133 | echo "${CONTROL}/rules not found or not executable."
|
|---|
| 134 | exit 1
|
|---|
| 135 | fi
|
|---|
| 136 |
|
|---|
| 137 | #
|
|---|
| 138 | # unpack upstream tarball and make diff
|
|---|
| 139 | #
|
|---|
| 140 | if [ -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 | )
|
|---|
| 174 | fi
|
|---|
| 175 |
|
|---|
| 176 | # build package
|
|---|
| 177 | if ! ${CONTROL}/rules build; then
|
|---|
| 178 | echo "Build failed"
|
|---|
| 179 | exit 1
|
|---|
| 180 | fi
|
|---|
| 181 |
|
|---|
| 182 | # install it to tmp directory
|
|---|
| 183 | if ! ${CONTROL}/rules install; then
|
|---|
| 184 | echo "Install failed"
|
|---|
| 185 | exit 1
|
|---|
| 186 | fi
|
|---|
| 187 |
|
|---|
| 188 | # copy contents of control directory
|
|---|
| 189 | mkdir /tmp/${pkg}/CONTROL
|
|---|
| 190 |
|
|---|
| 191 | files_required="control"
|
|---|
| 192 | files_optional="preinst postinst prerm postrm"
|
|---|
| 193 |
|
|---|
| 194 | for 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
|
|---|
| 202 | done
|
|---|
| 203 |
|
|---|
| 204 | for i in ${files_optional} ; do
|
|---|
| 205 | file=${CONTROL}/$i
|
|---|
| 206 |
|
|---|
| 207 | if [ -e ${file} ] ; then
|
|---|
| 208 | cp $file /tmp/${pkg}/CONTROL
|
|---|
| 209 | fi
|
|---|
| 210 | done
|
|---|
| 211 |
|
|---|
| 212 | # build the ipk package
|
|---|
| 213 | owd=`pwd`
|
|---|
| 214 | cd ..
|
|---|
| 215 | ipkg-build /tmp/${pkg} || exit 1
|
|---|
| 216 |
|
|---|
| 217 | rm -rf /tmp/${pkg}
|
|---|
| 218 |
|
|---|
| 219 | cd $owd
|
|---|
| 220 | if ! ${CONTROL}/rules clean; then
|
|---|
| 221 | echo "Clean failed"
|
|---|
| 222 | exit 1
|
|---|
| 223 | fi
|
|---|
| 224 |
|
|---|
| 225 | # Yep. That's it!
|
|---|
| 226 | exit 0
|
|---|