The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / ipkg / ipkg-build
1 #!/bin/sh
2
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 set -e
7
8 ipkg_extract_value() {
9         sed -e "s/^[^:]*:[[:space:]]*//"
10 }
11
12 required_field() {
13         field=$1
14
15         value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value`
16         if [ -z "$value" ]; then
17                 echo "ipkg-build: Error: $CONTROL/control is missing field $field" ;
18                 PKG_ERROR=1
19         fi
20         echo $value
21 }
22
23 pkg_appears_sane() {
24         local pkg_dir=$1
25
26         local owd=`pwd`
27         cd $pkg_dir
28
29         PKG_ERROR=0
30         if [ ! -f "$CONTROL/control" ]; then
31                 echo "ipkg-build: Error: Control file $pkg_dir/$CONTROL/control not found."
32                 cd $owd
33                 return 1
34         fi
35
36         pkg=`required_field Package`
37         version=`required_field Version`
38         arch=`required_field Architecture`
39         required_field Maintainer >/dev/null
40         required_field Description >/dev/null
41
42         if echo $pkg | grep '[^a-z0-9.+-]'; then
43                 echo "ipkg-build: Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])"
44                 PKG_ERROR=1;
45         fi
46
47         local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
48         if [ -n "$bad_fields" ]; then
49                 bad_fields=`echo $bad_fields`
50                 echo "ipkg-build: Error: The following fields in $CONTROL/control are missing a ':'"
51                 echo "  $bad_fields"
52                 echo "ipkg-build: This may be due to a missing initial space for a multi-line field value"
53                 PKG_ERROR=1
54         fi
55
56         for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do
57                 if [ -f $script -a ! -x $script ]; then
58                         echo "ipkg-build: Error: package script $script is not executable"
59                         PKG_ERROR=1
60                 fi
61         done
62
63         if [ -f $CONTROL/conffiles ]; then
64                 for cf in `cat $CONTROL/conffiles`; do
65                         if [ ! -f ./$cf ]; then
66                                 echo "ipkg-build: Error: $CONTROL/conffiles mentions conffile $cf which does not exist"
67                                 PKG_ERROR=1
68                         fi
69                 done
70         fi
71
72         cd $owd
73         return $PKG_ERROR
74 }
75
76 ###
77 # ipkg-build "main"
78 ###
79
80 case $# in
81 1)
82         dest_dir=.
83         ;;
84 2)
85         dest_dir=$2
86         ;;
87 *)
88         echo "Usage: ipkg-build <pkg_directory> [<destination_directory>]" ;
89         exit 1 
90         ;;
91 esac
92
93 pkg_dir=$1
94
95 if [ ! -d $pkg_dir ]; then
96         echo "ipkg-build: Error: Directory $pkg_dir does not exist"
97         exit 1
98 fi
99
100 # CONTROL is second so that it takes precedence
101 CONTROL=
102 [ -d $pkg_dir/DEBIAN ] && CONTROL=DEBIAN
103 [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL
104 if [ -z "$CONTROL" ]; then
105         echo "ipkg-build: Error: Directory $pkg_dir has no CONTROL subdirectory."
106         exit 1
107 fi
108
109 if ! pkg_appears_sane $pkg_dir; then
110         echo "Please fix the above errors and try again."
111         exit 1
112 fi
113
114 tmp_dir=$dest_dir/IPKG_BUILD.$$
115 mkdir $tmp_dir
116
117 tar -C $pkg_dir -czf $tmp_dir/data.tar.gz . --exclude=$CONTROL
118 tar -C $pkg_dir/$CONTROL -czf $tmp_dir/control.tar.gz .
119
120 echo "2.0" > $tmp_dir/debian-binary
121
122 pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk
123 tar -C $tmp_dir -czf $pkg_file debian-binary data.tar.gz control.tar.gz
124 rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz
125 rmdir $tmp_dir
126
127 echo "Packaged contents of $pkg_dir into $pkg_file"