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 # look up date of last commit
19 if [ -d "$TOPDIR/.git" ]; then
21 TIMESTAMP
=$
(cd $TOPDIR; $GIT log
-1 -s --format=%ci
)
22 elif [ -d "$TOPDIR/.svn" ]; then
24 TIMESTAMP
=$
($SVN info
"$TOPDIR" |
sed -n "s/^Last Changed Date: \(.*\)/\1/p")
29 ipkg_extract_value
() {
30 sed -e "s/^[^:]*:[[:space:]]*//"
36 grep "^$field:" < $CONTROL/control | ipkg_extract_value
46 pkg
=`required_field Package`
47 version
=`required_field Version | sed 's/Version://; s/^.://g;'`
48 arch
=`required_field Architecture`
50 if echo $pkg |
grep '[^a-zA-Z0-9_.+-]'; then
51 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
55 if [ -f $CONTROL/conffiles
]; then
56 rm -f $CONTROL/conffiles.resolved
58 for cf
in `$FIND $(sed -e "s!^/!$pkg_dir/!" $CONTROL/conffiles) -type f`; do
59 echo "${cf#$pkg_dir}" >> $CONTROL/conffiles.resolved
63 if [ -f $CONTROL/conffiles.resolved
]; then
64 mv $CONTROL/conffiles.resolved
$CONTROL/conffiles
65 chmod 0644 $CONTROL/conffiles
78 usage
="Usage: $0 [-c] [-C] [-o owner] [-g group] <pkg_directory> [<destination_directory>]"
79 while getopts "cg:ho:v" opt
; do
82 ogargs
="--owner=$owner"
85 ogargs
="$ogargs --group=$group"
92 h
) echo $usage >&2 ;;
98 shift $
(($OPTIND - 1))
100 # continue on to process additional arguments
108 if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
120 if [ ! -d $pkg_dir ]; then
121 echo "*** Error: Directory $pkg_dir does not exist" >&2
125 # CONTROL is second so that it takes precedence
127 [ -d $pkg_dir/CONTROL
] && CONTROL
=CONTROL
128 if [ -z "$CONTROL" ]; then
129 echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
133 if ! pkg_appears_sane
$pkg_dir; then
135 echo "ipkg-build: Please fix the above errors and try again." >&2
139 tmp_dir
=$dest_dir/IPKG_BUILD.$$
142 echo $CONTROL > $tmp_dir/tarX
143 # Preserve permissions (-p) when creating data.tar.gz as non-root user
144 ( cd $pkg_dir && $TAR $ogargs -X $tmp_dir/tarX
--format=gnu
--sort=name
-cpf - --mtime="$TIMESTAMP" . |
$GZIP -n - > $tmp_dir/data.
tar.gz
)
146 installed_size
=`stat -c "%s" $tmp_dir/data.tar.gz`
147 sed -i -e "s/^Installed-Size: .*/Installed-Size: $installed_size/" \
148 $pkg_dir/$CONTROL/control
150 ( cd $pkg_dir/$CONTROL && $TAR $ogargs --format=gnu
--sort=name
-cf - --mtime="$TIMESTAMP" . |
$GZIP -n - > $tmp_dir/control.
tar.gz
)
153 echo "2.0" > $tmp_dir/debian-binary
155 pkg_file
=$dest_dir/${pkg}_${version}_${arch}.ipk
157 ( cd $tmp_dir && $TAR $ogargs --format=gnu
--sort=name
-cf - --mtime="$TIMESTAMP" .
/debian-binary .
/data.
tar.gz .
/control.
tar.gz |
$GZIP -n - > $pkg_file )
159 rm $tmp_dir/debian-binary
$tmp_dir/data.
tar.gz
$tmp_dir/control.
tar.gz
162 echo "Packaged contents of $pkg_dir into $pkg_file"