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)}"
17 ipkg_extract_value
() {
18 sed -e "s/^[^:]*:[[:space:]]*//"
24 grep "^$field:" < $CONTROL/control | ipkg_extract_value
34 pkg
=`required_field Package`
35 version
=`required_field Version | sed 's/Version://; s/^.://g;'`
36 arch
=`required_field Architecture`
38 if echo $pkg |
grep '[^a-zA-Z0-9_.+-]'; then
39 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
43 if [ -f $CONTROL/conffiles
]; then
44 rm -f $CONTROL/conffiles.resolved
46 for cf
in `$FIND $(sed -e "s!^/!$pkg_dir/!" $CONTROL/conffiles) -type f`; do
47 echo "${cf#$pkg_dir}" >> $CONTROL/conffiles.resolved
51 mv $CONTROL/conffiles.resolved
$CONTROL/conffiles
52 chmod 0644 $CONTROL/conffiles
64 usage
="Usage: $0 [-c] [-C] [-o owner] [-g group] <pkg_directory> [<destination_directory>]"
65 while getopts "cg:ho:v" opt
; do
68 ogargs
="--owner=$owner"
71 ogargs
="$ogargs --group=$group"
78 h
) echo $usage >&2 ;;
84 shift $
(($OPTIND - 1))
86 # continue on to process additional arguments
94 if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
106 if [ ! -d $pkg_dir ]; then
107 echo "*** Error: Directory $pkg_dir does not exist" >&2
111 # CONTROL is second so that it takes precedence
113 [ -d $pkg_dir/CONTROL
] && CONTROL
=CONTROL
114 if [ -z "$CONTROL" ]; then
115 echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
119 if ! pkg_appears_sane
$pkg_dir; then
121 echo "ipkg-build: Please fix the above errors and try again." >&2
125 tmp_dir
=$dest_dir/IPKG_BUILD.$$
128 echo $CONTROL > $tmp_dir/tarX
129 # Preserve permissions (-p) when creating data.tar.gz as non-root user
130 ( cd $pkg_dir && $TAR $ogargs -X $tmp_dir/tarX
--format=gnu
-czpf $tmp_dir/data.
tar.gz .
)
132 installed_size
=`stat -c "%s" $tmp_dir/data.tar.gz`
133 sed -i -e "s/^Installed-Size: .*/Installed-Size: $installed_size/" \
134 $pkg_dir/$CONTROL/control
136 ( cd $pkg_dir/$CONTROL && $TAR $ogargs --format=gnu
-czf $tmp_dir/control.
tar.gz .
)
139 echo "2.0" > $tmp_dir/debian-binary
141 pkg_file
=$dest_dir/${pkg}_${version}_${arch}.ipk
143 ( cd $tmp_dir && $TAR --format=gnu
-zcf $pkg_file .
/debian-binary .
/data.
tar.gz .
/control.
tar.gz
)
145 rm $tmp_dir/debian-binary
$tmp_dir/data.
tar.gz
$tmp_dir/control.
tar.gz
148 echo "Packaged contents of $pkg_dir into $pkg_file"