3 # ipkg-build -- construct a .ipk 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
6 # 2003-04-25 rea@sr.unh.edu
7 # Updated to work on Familiar Pre0.7rc1, with busybox tar.
8 # Note it Requires: binutils-ar (since the busybox ar can't create)
9 # For UID debugging it needs a better "find".
14 FIND="${FIND:-$(which gfind)}"
15 TAR="${TAR:-$(which tar)}"
18 ipkg_extract_value() {
19 sed -e "s/^[^:]*:[[:space:]]*//"
25 grep "^$field:" < $CONTROL/control | ipkg_extract_value
35 pkg=`required_field Package`
36 version=`required_field Version | sed 's/Version://; s/^.://g;'`
37 arch=`required_field Architecture`
39 if echo $pkg | grep '[^a-zA-Z0-9_.+-]'; then
40 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
44 if [ -f $CONTROL/conffiles ]; then
45 rm -f $CONTROL/conffiles.resolved
47 for cf in `$FIND $(sed -e "s!^/!$pkg_dir/!" $CONTROL/conffiles) -type f`; do
48 echo "${cf#$pkg_dir}" >> $CONTROL/conffiles.resolved
52 mv $CONTROL/conffiles.resolved $CONTROL/conffiles
53 chmod 0644 $CONTROL/conffiles
65 usage="Usage: $0 [-c] [-C] [-o owner] [-g group] <pkg_directory> [<destination_directory>]"
66 while getopts "cg:ho:v" opt; do
69 ogargs="--owner=$owner"
72 ogargs="$ogargs --group=$group"
79 h ) echo $usage >&2 ;;
85 shift $(($OPTIND - 1))
87 # continue on to process additional arguments
95 if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
107 if [ ! -d $pkg_dir ]; then
108 echo "*** Error: Directory $pkg_dir does not exist" >&2
112 # CONTROL is second so that it takes precedence
114 [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL
115 if [ -z "$CONTROL" ]; then
116 echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
120 if ! pkg_appears_sane $pkg_dir; then
122 echo "ipkg-build: Please fix the above errors and try again." >&2
126 tmp_dir=$dest_dir/IPKG_BUILD.$$
129 echo $CONTROL > $tmp_dir/tarX
130 # Preserve permissions (-p) when creating data.tar.gz as non-root user
131 ( cd $pkg_dir && $TAR $ogargs -X $tmp_dir/tarX --format=gnu -czpf $tmp_dir/data.tar.gz . )
133 installed_size=`stat -c "%s" $tmp_dir/data.tar.gz`
134 sed -i -e "s/^Installed-Size: .*/Installed-Size: $installed_size/" \
135 $pkg_dir/$CONTROL/control
137 ( cd $pkg_dir/$CONTROL && $TAR $ogargs --format=gnu -czf $tmp_dir/control.tar.gz . )
140 echo "2.0" > $tmp_dir/debian-binary
142 pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk
144 ( cd $tmp_dir && $TAR --format=gnu -zcf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz )
146 rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz
149 echo "Packaged contents of $pkg_dir into $pkg_file"