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".
13 FIND
="$(command -v find)"
14 FIND
="${FIND:-$(command -v gfind)}"
15 TAR
="${TAR:-$(command -v tar)}"
16 GZIP
="$(command -v gzip)"
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
24 GIT
="$(command -v git)"
25 TIMESTAMP
=$
(cd $TOPDIR; $GIT log
-1 -s --format=%ci
)
26 elif [ -d "$TOPDIR/.svn" ]; then
27 SVN
="$(command -v svn)"
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
81 usage
="Usage: $0 [-v] [-h] [-m] <pkg_directory> [<destination_directory>]"
82 while getopts "hvm:" opt
; do
87 h
) echo $usage >&2 ;;
88 m
) file_modes
=$OPTARG ;;
94 shift $
(($OPTIND - 1))
96 # continue on to process additional arguments
104 if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
116 if [ ! -d $pkg_dir ]; then
117 echo "*** Error: Directory $pkg_dir does not exist" >&2
121 # CONTROL is second so that it takes precedence
123 [ -d $pkg_dir/CONTROL
] && CONTROL
=CONTROL
124 if [ -z "$CONTROL" ]; then
125 echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
129 if ! pkg_appears_sane
$pkg_dir; then
131 echo "ipkg-build: Please fix the above errors and try again." >&2
135 tmp_dir
=$dest_dir/IPKG_BUILD.$$
138 echo $CONTROL > $tmp_dir/tarX
140 for file_mode
in $file_modes; do
145 echo "ERROR: file modes must use absolute path and contain user:group:mode"
150 path
=$
(echo "$file_mode" | cut
-d ':' -f 1)
151 user_group
=$
(echo "$file_mode" | cut
-d ':' -f 2-3)
152 mode
=$
(echo "$file_mode" | cut
-d ':' -f 4)
154 chown
"$user_group" "$pkg_dir/$path"
155 chmod "$mode" "$pkg_dir/$path"
157 $TAR -X $tmp_dir/tarX
--format=gnu
--sort=name
-cpf - --mtime="$TIMESTAMP" . |
$GZIP -n - > $tmp_dir/data.
tar.gz
159 installed_size
=`stat -c "%s" $tmp_dir/data.tar.gz`
160 sed -i -e "s/^Installed-Size: .*/Installed-Size: $installed_size/" \
161 $pkg_dir/$CONTROL/control
163 ( cd $pkg_dir/$CONTROL && $TAR --format=gnu
--sort=name
-cf - --mtime="$TIMESTAMP" . |
$GZIP -n - > $tmp_dir/control.
tar.gz
)
166 echo "2.0" > $tmp_dir/debian-binary
168 pkg_file
=$dest_dir/${pkg}_${version}_${arch}.ipk
170 ( cd $tmp_dir && $TAR --format=gnu
--sort=name
-cf - --mtime="$TIMESTAMP" .
/debian-binary .
/data.
tar.gz .
/control.
tar.gz |
$GZIP -n - > $pkg_file )
172 rm $tmp_dir/debian-binary
$tmp_dir/data.
tar.gz
$tmp_dir/control.
tar.gz
175 echo "Packaged contents of $pkg_dir into $pkg_file"