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 # try to use fixed source epoch
19 if [ -n "$SOURCE_DATE_EPOCH" ]; then
20 TIMESTAMP
=$
(date --date="@$SOURCE_DATE_EPOCH")
22 # look up date of last commit
23 elif [ -d "$TOPDIR/.git" ]; then
25 TIMESTAMP
=$
(cd $TOPDIR; $GIT log
-1 -s --format=%ci
)
26 elif [ -d "$TOPDIR/.svn" ]; then
28 TIMESTAMP
=$
($SVN info
"$TOPDIR" |
sed -n "s/^Last Changed Date: \(.*\)/\1/p")
33 ipkg_extract_value
() {
34 sed -e "s/^[^:]*:[[:space:]]*//"
40 grep "^$field:" < $CONTROL/control | ipkg_extract_value
50 pkg
=`required_field Package`
51 version
=`required_field Version | sed 's/Version://; s/^.://g;'`
52 arch
=`required_field Architecture`
54 if echo $pkg |
grep '[^a-zA-Z0-9_.+-]'; then
55 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
59 if [ -f $CONTROL/conffiles
]; then
60 rm -f $CONTROL/conffiles.resolved
62 for cf
in `$FIND $(sed -e "s!^/!$pkg_dir/!" $CONTROL/conffiles) -type f`; do
63 echo "${cf#$pkg_dir}" >> $CONTROL/conffiles.resolved
67 if [ -f $CONTROL/conffiles.resolved
]; then
68 mv $CONTROL/conffiles.resolved
$CONTROL/conffiles
69 chmod 0644 $CONTROL/conffiles
82 usage
="Usage: $0 [-c] [-C] [-o owner] [-g group] <pkg_directory> [<destination_directory>]"
83 while getopts "cg:ho:v" opt
; do
86 ogargs
="--owner=$owner"
89 ogargs
="$ogargs --group=$group"
96 h
) echo $usage >&2 ;;
102 shift $
(($OPTIND - 1))
104 # continue on to process additional arguments
112 if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
124 if [ ! -d $pkg_dir ]; then
125 echo "*** Error: Directory $pkg_dir does not exist" >&2
129 # CONTROL is second so that it takes precedence
131 [ -d $pkg_dir/CONTROL
] && CONTROL
=CONTROL
132 if [ -z "$CONTROL" ]; then
133 echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
137 if ! pkg_appears_sane
$pkg_dir; then
139 echo "ipkg-build: Please fix the above errors and try again." >&2
143 tmp_dir
=$dest_dir/IPKG_BUILD.$$
146 echo $CONTROL > $tmp_dir/tarX
147 # Preserve permissions (-p) when creating data.tar.gz as non-root user
148 ( cd $pkg_dir && $TAR $ogargs -X $tmp_dir/tarX
--format=gnu
--sort=name
-cpf - --mtime="$TIMESTAMP" . |
$GZIP -n - > $tmp_dir/data.
tar.gz
)
150 installed_size
=`stat -c "%s" $tmp_dir/data.tar.gz`
151 sed -i -e "s/^Installed-Size: .*/Installed-Size: $installed_size/" \
152 $pkg_dir/$CONTROL/control
154 ( cd $pkg_dir/$CONTROL && $TAR $ogargs --format=gnu
--sort=name
-cf - --mtime="$TIMESTAMP" . |
$GZIP -n - > $tmp_dir/control.
tar.gz
)
157 echo "2.0" > $tmp_dir/debian-binary
159 pkg_file
=$dest_dir/${pkg}_${version}_${arch}.ipk
161 ( cd $tmp_dir && $TAR $ogargs --format=gnu
--sort=name
-cf - --mtime="$TIMESTAMP" .
/debian-binary .
/data.
tar.gz .
/control.
tar.gz |
$GZIP -n - > $pkg_file )
163 rm $tmp_dir/debian-binary
$tmp_dir/data.
tar.gz
$tmp_dir/control.
tar.gz
166 echo "Packaged contents of $pkg_dir into $pkg_file"