diff options
Diffstat (limited to 'scripts/stage-manager-ipkg-build')
-rwxr-xr-x | scripts/stage-manager-ipkg-build | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/scripts/stage-manager-ipkg-build b/scripts/stage-manager-ipkg-build new file mode 100755 index 0000000000..77367ac35a --- /dev/null +++ b/scripts/stage-manager-ipkg-build | |||
@@ -0,0 +1,246 @@ | |||
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 | # 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". | ||
10 | set -e | ||
11 | |||
12 | version=1.0 | ||
13 | |||
14 | ipkg_extract_value() { | ||
15 | sed -e "s/^[^:]*:[[:space:]]*//" | ||
16 | } | ||
17 | |||
18 | required_field() { | ||
19 | field=$1 | ||
20 | |||
21 | value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value` | ||
22 | if [ -z "$value" ]; then | ||
23 | echo "*** Error: $CONTROL/control is missing field $field" >&2 | ||
24 | return 1 | ||
25 | fi | ||
26 | echo $value | ||
27 | return 0 | ||
28 | } | ||
29 | |||
30 | disallowed_field() { | ||
31 | field=$1 | ||
32 | |||
33 | value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value` | ||
34 | if [ -n "$value" ]; then | ||
35 | echo "*** Error: $CONTROL/control contains disallowed field $field" >&2 | ||
36 | return 1 | ||
37 | fi | ||
38 | echo $value | ||
39 | return 0 | ||
40 | } | ||
41 | |||
42 | pkg_appears_sane() { | ||
43 | local pkg_dir=$1 | ||
44 | |||
45 | local owd=`pwd` | ||
46 | cd $pkg_dir | ||
47 | |||
48 | PKG_ERROR=0 | ||
49 | |||
50 | tilde_files=`find . -name '*~'` | ||
51 | if [ -n "$tilde_files" ]; then | ||
52 | if [ "$noclean" = "1" ]; then | ||
53 | echo "*** Warning: The following files have names ending in '~'. | ||
54 | You probably want to remove them: " >&2 | ||
55 | ls -ld $tilde_files | ||
56 | echo >&2 | ||
57 | else | ||
58 | echo "*** Removing the following files: $tilde_files" | ||
59 | rm -f "$tilde_files" | ||
60 | fi | ||
61 | fi | ||
62 | |||
63 | large_uid_files=`find . -uid +99 || true` | ||
64 | |||
65 | if [ "$ogargs" = "" ] && [ -n "$large_uid_files" ]; then | ||
66 | echo "*** Warning: The following files have a UID greater than 99. | ||
67 | You probably want to chown these to a system user: " >&2 | ||
68 | ls -ld $large_uid_files | ||
69 | echo >&2 | ||
70 | fi | ||
71 | |||
72 | |||
73 | if [ ! -f "$CONTROL/control" ]; then | ||
74 | echo "*** Error: Control file $pkg_dir/$CONTROL/control not found." >&2 | ||
75 | cd $owd | ||
76 | return 1 | ||
77 | fi | ||
78 | |||
79 | pkg=`required_field Package` | ||
80 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
81 | |||
82 | version=`required_field Version | sed 's/Version://; s/^.://g;'` | ||
83 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
84 | |||
85 | arch=`required_field Architecture` | ||
86 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
87 | |||
88 | required_field Maintainer >/dev/null | ||
89 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
90 | |||
91 | required_field Description >/dev/null | ||
92 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
93 | |||
94 | section=`required_field Section` | ||
95 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
96 | if [ -z "$section" ]; then | ||
97 | echo "The Section field should have one of the following values:" >&2 | ||
98 | echo "admin, base, comm, editors, extras, games, graphics, kernel, libs, misc, net, text, web, x11" >&2 | ||
99 | fi | ||
100 | |||
101 | priority=`required_field Priority` | ||
102 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
103 | if [ -z "$priority" ]; then | ||
104 | echo "The Priority field should have one of the following values:" >&2 | ||
105 | echo "required, important, standard, optional, extra." >&2 | ||
106 | echo "If you don't know which priority value you should be using, then use \`optional'" >&2 | ||
107 | fi | ||
108 | |||
109 | source=`required_field Source` | ||
110 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
111 | if [ -z "$source" ]; then | ||
112 | echo "The Source field contain the URL's or filenames of the source code and any patches" | ||
113 | echo "used to build this package. Either gnu-style tarballs or Debian source packages " | ||
114 | echo "are acceptable. Relative filenames may be used if they are distributed in the same" | ||
115 | echo "directory as the .ipk file." | ||
116 | fi | ||
117 | |||
118 | disallowed_filename=`disallowed_field Filename` | ||
119 | [ "$?" -ne 0 ] && PKG_ERROR=1 | ||
120 | |||
121 | if echo $pkg | grep '[^a-z0-9.+-]'; then | ||
122 | echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2 | ||
123 | PKG_ERROR=1; | ||
124 | fi | ||
125 | |||
126 | local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'` | ||
127 | if [ -n "$bad_fields" ]; then | ||
128 | bad_fields=`echo $bad_fields` | ||
129 | echo "*** Error: The following fields in $CONTROL/control are missing a ':'" >&2 | ||
130 | echo " $bad_fields" >&2 | ||
131 | echo "ipkg-build: This may be due to a missing initial space for a multi-line field value" >&2 | ||
132 | PKG_ERROR=1 | ||
133 | fi | ||
134 | |||
135 | for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do | ||
136 | if [ -f $script -a ! -x $script ]; then | ||
137 | echo "*** Error: package script $script is not executable" >&2 | ||
138 | PKG_ERROR=1 | ||
139 | fi | ||
140 | done | ||
141 | |||
142 | if [ -f $CONTROL/conffiles ]; then | ||
143 | for cf in `cat $CONTROL/conffiles`; do | ||
144 | if [ ! -f ./$cf ]; then | ||
145 | echo "*** Error: $CONTROL/conffiles mentions conffile $cf which does not exist" >&2 | ||
146 | PKG_ERROR=1 | ||
147 | fi | ||
148 | done | ||
149 | fi | ||
150 | |||
151 | cd $owd | ||
152 | return $PKG_ERROR | ||
153 | } | ||
154 | |||
155 | ### | ||
156 | # ipkg-build "main" | ||
157 | ### | ||
158 | ogargs="" | ||
159 | outer=ar | ||
160 | noclean=0 | ||
161 | usage="Usage: $0 [-c] [-C] [-o owner] [-g group] <pkg_directory> [<destination_directory>]" | ||
162 | while getopts "cg:ho:v" opt; do | ||
163 | case $opt in | ||
164 | o ) owner=$OPTARG | ||
165 | ogargs="--owner=$owner" | ||
166 | ;; | ||
167 | g ) group=$OPTARG | ||
168 | ogargs="$ogargs --group=$group" | ||
169 | ;; | ||
170 | c ) outer=tar | ||
171 | ;; | ||
172 | C ) noclean=1 | ||
173 | ;; | ||
174 | v ) echo $version | ||
175 | exit 0 | ||
176 | ;; | ||
177 | h ) echo $usage >&2 ;; | ||
178 | \? ) echo $usage >&2 | ||
179 | esac | ||
180 | done | ||
181 | |||
182 | |||
183 | shift $(($OPTIND - 1)) | ||
184 | |||
185 | # continue on to process additional arguments | ||
186 | |||
187 | case $# in | ||
188 | 1) | ||
189 | dest_dir=$PWD | ||
190 | ;; | ||
191 | 2) | ||
192 | dest_dir=$2 | ||
193 | if [ "$dest_dir" = "." -o "$dest_dir" = "./" ] ; then | ||
194 | dest_dir=$PWD | ||
195 | fi | ||
196 | ;; | ||
197 | *) | ||
198 | echo $usage >&2 | ||
199 | exit 1 | ||
200 | ;; | ||
201 | esac | ||
202 | |||
203 | pkg_dir=$1 | ||
204 | |||
205 | if [ ! -d $pkg_dir ]; then | ||
206 | echo "*** Error: Directory $pkg_dir does not exist" >&2 | ||
207 | exit 1 | ||
208 | fi | ||
209 | |||
210 | # CONTROL is second so that it takes precedence | ||
211 | CONTROL= | ||
212 | [ -d $pkg_dir/DEBIAN ] && CONTROL=DEBIAN | ||
213 | [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL | ||
214 | if [ -z "$CONTROL" ]; then | ||
215 | echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2 | ||
216 | exit 1 | ||
217 | fi | ||
218 | |||
219 | if ! pkg_appears_sane $pkg_dir; then | ||
220 | echo >&2 | ||
221 | echo "ipkg-build: Please fix the above errors and try again." >&2 | ||
222 | exit 1 | ||
223 | fi | ||
224 | |||
225 | tmp_dir=$dest_dir/IPKG_BUILD.$$ | ||
226 | mkdir $tmp_dir | ||
227 | |||
228 | echo $CONTROL > $tmp_dir/tarX | ||
229 | ( cd $pkg_dir && tar $ogargs -X $tmp_dir/tarX -czf $tmp_dir/data.tar.gz . ) | ||
230 | ( cd $pkg_dir/$CONTROL && tar $ogargs -czf $tmp_dir/control.tar.gz . ) | ||
231 | rm $tmp_dir/tarX | ||
232 | |||
233 | echo "2.0" > $tmp_dir/debian-binary | ||
234 | |||
235 | pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk | ||
236 | rm -f $pkg_file | ||
237 | if [ "$outer" = "ar" ] ; then | ||
238 | ( cd $tmp_dir && ar -crf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz ) | ||
239 | else | ||
240 | ( cd $tmp_dir && tar -zcf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz ) | ||
241 | fi | ||
242 | |||
243 | rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz | ||
244 | rmdir $tmp_dir | ||
245 | |||
246 | echo "Packaged contents of $pkg_dir into $pkg_file" | ||