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 "$PKG_SOURCE_DATE_EPOCH" ]; then
20 TIMESTAMP
=$
(date --date="@$PKG_SOURCE_DATE_EPOCH")
21 elif [ -n "$SOURCE_DATE_EPOCH" ]; then
22 TIMESTAMP
=$
(date --date="@$SOURCE_DATE_EPOCH")
27 ipkg_extract_value
() {
28 sed -e "s/^[^:]*:[[:space:]]*//"
34 grep "^$field:" < $CONTROL/control | ipkg_extract_value
44 pkg
=`required_field Package`
45 version
=`required_field Version | sed 's/Version://; s/^.://g;'`
46 arch
=`required_field Architecture`
48 if echo $pkg |
grep '[^a-zA-Z0-9_.+-]'; then
49 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
53 if [ -f $CONTROL/conffiles
]; then
54 rm -f $CONTROL/conffiles.resolved
56 for cf
in `$FIND $(sed -e "s!^/!$pkg_dir/!" $CONTROL/conffiles) -type f`; do
57 echo "${cf#$pkg_dir}" >> $CONTROL/conffiles.resolved
61 if [ -f $CONTROL/conffiles.resolved
]; then
62 mv $CONTROL/conffiles.resolved
$CONTROL/conffiles
63 chmod 0644 $CONTROL/conffiles
71 resolve_file_mode_id
() {
72 local var
=$1 type=$2 name
=$3 id
79 id
=$
(sed -ne "s#^$type $name \\([0-9]\\+\\)\\b.*\$#\\1#p" "$TOPDIR/tmp/.packageusergroup" 2>/dev
/null
)
95 usage
="Usage: $0 [-v] [-h] [-m] <pkg_directory> [<destination_directory>]"
96 while getopts "hvm:" opt
; do
101 h
) echo $usage >&2 ;;
102 m
) file_modes
=$OPTARG ;;
108 shift $
(($OPTIND - 1))
110 # continue on to process additional arguments
118 if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then
130 if [ ! -d $pkg_dir ]; then
131 echo "*** Error: Directory $pkg_dir does not exist" >&2
135 # CONTROL is second so that it takes precedence
137 [ -d $pkg_dir/CONTROL
] && CONTROL
=CONTROL
138 if [ -z "$CONTROL" ]; then
139 echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
143 if ! pkg_appears_sane
$pkg_dir; then
145 echo "ipkg-build: Please fix the above errors and try again." >&2
149 tmp_dir
=$dest_dir/IPKG_BUILD.$$
152 echo $CONTROL > $tmp_dir/tarX
154 for file_mode
in $file_modes; do
159 echo "ERROR: file modes must use absolute path and contain user:group:mode"
165 mode
=${file_mode##*:}; path
=${file_mode%:*}
166 group
=${path##*:}; path
=${path%:*}
167 user
=${path##*:}; path
=${path%:*}
169 if ! resolve_file_mode_id uid user
"$user"; then
170 echo "ERROR: unable to resolve uid of $user" >&2
174 if ! resolve_file_mode_id gid group
"$group"; then
175 echo "ERROR: unable to resolve gid of $group" >&2
179 chown
"$uid:$gid" "$pkg_dir/$path"
180 chmod "$mode" "$pkg_dir/$path"
182 $TAR -X $tmp_dir/tarX
--format=gnu
--sort=name
-cpf - --mtime="$TIMESTAMP" . |
$GZIP -n - > $tmp_dir/data.
tar.gz
184 installed_size
=`stat -c "%s" $tmp_dir/data.tar.gz`
185 sed -i -e "s/^Installed-Size: .*/Installed-Size: $installed_size/" \
186 $pkg_dir/$CONTROL/control
188 ( cd $pkg_dir/$CONTROL && $TAR --format=gnu
--sort=name
-cf - --mtime="$TIMESTAMP" . |
$GZIP -n - > $tmp_dir/control.
tar.gz
)
191 echo "2.0" > $tmp_dir/debian-binary
193 pkg_file
=$dest_dir/${pkg}_${version}_${arch}.ipk
195 ( cd $tmp_dir && $TAR --format=gnu
--sort=name
-cf - --mtime="$TIMESTAMP" .
/debian-binary .
/data.
tar.gz .
/control.
tar.gz |
$GZIP -n - > $pkg_file )
197 rm $tmp_dir/debian-binary
$tmp_dir/data.
tar.gz
$tmp_dir/control.
tar.gz
200 echo "Packaged contents of $pkg_dir into $pkg_file"