-rwxr-xr-x | scripts/ipkg-build | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/scripts/ipkg-build b/scripts/ipkg-build index c6af056..b661bbf 100755 --- a/scripts/ipkg-build +++ b/scripts/ipkg-build | |||
@@ -1,47 +1,82 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | # ipkg-build -- construct a .ipk from a directory | 3 | # ipkg-build -- construct a .ipk from a directory |
4 | # Carl Worth <cworth@east.isi.edu> | 4 | # Carl Worth <cworth@east.isi.edu> |
5 | # based on a script by Steve Redler IV, steve@sr-tech.com 5-21-2001 | 5 | # based on a script by Steve Redler IV, steve@sr-tech.com 5-21-2001 |
6 | set -e | 6 | set -e |
7 | 7 | ||
8 | ipkg_extract_value() { | 8 | #declare array for values and fields found in control file |
9 | sed -e "s/^[^:]*:[[:space:]]*//" | 9 | declare -a AllValues AllFields |
10 | |||
11 | collect_values() { | ||
12 | local i line | ||
13 | |||
14 | i=0 | ||
15 | while read line | ||
16 | do | ||
17 | AllFields[$i]=${line%%:*} | ||
18 | AllValues[$i]=`echo ${line#*:}` # echo to remove spaces | ||
19 | let i=i+1 | ||
20 | done < ${pkg_dir}/${CONTROL}/control | ||
10 | } | 21 | } |
11 | 22 | ||
12 | required_field() { | 23 | required_field() { |
24 | local field i | ||
13 | field=$1 | 25 | field=$1 |
14 | 26 | ||
15 | value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value` | 27 | i=0 |
16 | if [ -z "$value" ]; then | 28 | for af in "${AllFields[@]}" |
29 | do | ||
30 | if [ "$field" = "$af" ] | ||
31 | then | ||
32 | # return value | ||
33 | echo "${AllValues[$i]}" | ||
34 | return 0; | ||
35 | fi | ||
36 | let i=i+1 | ||
37 | done | ||
38 | # not found | ||
17 | echo "*** Error: $CONTROL/control is missing field $field" >&2 | 39 | echo "*** Error: $CONTROL/control is missing field $field" >&2 |
18 | return 1 | 40 | return 1 |
19 | fi | ||
20 | echo $value | ||
21 | return 0 | ||
22 | } | 41 | } |
23 | 42 | ||
43 | #ipkg_extract_value() { | ||
44 | #sed -e "s/^[^:]*:[[:space:]]*//" | ||
45 | #} | ||
46 | # | ||
47 | #required_field() { | ||
48 | #field=$1 | ||
49 | # | ||
50 | #value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value` | ||
51 | #if [ -z "$value" ]; then | ||
52 | # echo "*** Error: $CONTROL/control is missing field $field" >&2 | ||
53 | # return 1 | ||
54 | #fi | ||
55 | #echo $value | ||
56 | #return 0 | ||
57 | #} | ||
58 | |||
24 | pkg_appears_sane() { | 59 | pkg_appears_sane() { |
25 | local pkg_dir=$1 | 60 | local pkg_dir=$1 |
26 | 61 | ||
27 | local owd=`pwd` | 62 | local owd=`pwd` |
28 | cd $pkg_dir | 63 | cd $pkg_dir |
29 | 64 | ||
30 | PKG_ERROR=0 | 65 | PKG_ERROR=0 |
31 | 66 | ||
32 | tilde_files=`find . -name '*~'` | 67 | tilde_files=`find . -name '*~'` |
33 | if [ -n "$tilde_files" ]; then | 68 | if [ -n "$tilde_files" ]; then |
34 | echo "*** Warning: The following files have names ending in '~'. | 69 | echo "*** Warning: The following files have names ending in '~'. |
35 | You probably want to remove them: " >&2 | 70 | You probably want to remove them: " >&2 |
36 | ls -ld $tilde_files | 71 | ls -ld $tilde_files |
37 | echo >&2 | 72 | echo >&2 |
38 | fi | 73 | fi |
39 | 74 | ||
40 | large_uid_files=`find . -uid +99` | 75 | large_uid_files=`find . -uid +99` |
41 | 76 | ||
42 | if [ "$ogargs" = "" ] && [ -n "$large_uid_files" ]; then | 77 | if [ "$ogargs" = "" ] && [ -n "$large_uid_files" ]; then |
43 | echo "*** Warning: The following files have a UID greater than 99. | 78 | echo "*** Warning: The following files have a UID greater than 99. |
44 | You probably want to chown these to a system user: " >&2 | 79 | You probably want to chown these to a system user: " >&2 |
45 | ls -ld $large_uid_files | 80 | ls -ld $large_uid_files |
46 | echo >&2 | 81 | echo >&2 |
47 | fi | 82 | fi |
@@ -116,82 +151,88 @@ You probably want to chown these to a system user: " >&2 | |||
116 | cd $owd | 151 | cd $owd |
117 | return $PKG_ERROR | 152 | return $PKG_ERROR |
118 | } | 153 | } |
119 | 154 | ||
120 | ### | 155 | ### |
121 | # ipkg-build "main" | 156 | # ipkg-build "main" |
122 | ### | 157 | ### |
123 | ogargs="" | 158 | ogargs="" |
124 | outer=ar | 159 | outer=ar |
125 | usage="Usage: $0 [-c] [-o owner] [-g group] <pkg_directory> [<destination_directory>]" | 160 | usage="Usage: $0 [-c] [-o owner] [-g group] <pkg_directory> [<destination_directory>]" |
126 | while getopts "cg:o:" opt; do | 161 | while getopts "cg:o:" opt; do |
127 | case $opt in | 162 | case $opt in |
128 | o ) owner=$OPTARG | 163 | o ) owner=$OPTARG |
129 | ogargs="--owner=$owner" | 164 | ogargs="--owner=$owner" |
130 | ;; | 165 | ;; |
131 | g ) group=$OPTARG | 166 | g ) group=$OPTARG |
132 | ogargs="$ogargs --group=$group" | 167 | ogargs="$ogargs --group=$group" |
133 | ;; | 168 | ;; |
134 | c ) outer=tar | 169 | c ) outer=tar |
135 | ;; | 170 | ;; |
136 | \? ) echo $usage >&2 | 171 | \? ) echo $usage >&2 |
137 | esac | 172 | esac |
138 | done | 173 | done |
139 | 174 | ||
175 | # maks sure that tar produces headers compatible with busybox format | ||
176 | # debian needs this | ||
177 | ogargs="$ogargs --format=oldgnu" | ||
140 | 178 | ||
141 | shift $(($OPTIND - 1)) | 179 | shift $(($OPTIND - 1)) |
142 | 180 | ||
143 | # continue on to process additional arguments | 181 | # continue on to process additional arguments |
144 | 182 | ||
145 | case $# in | 183 | case $# in |
146 | 1) | 184 | 1) |
147 | dest_dir=. | 185 | dest_dir=. |
148 | ;; | 186 | ;; |
149 | 2) | 187 | 2) |
150 | dest_dir=$2 | 188 | dest_dir=$2 |
151 | ;; | 189 | ;; |
152 | *) | 190 | *) |
153 | echo echo $usage >&2 | 191 | echo echo $usage >&2 |
154 | exit 1 | 192 | exit 1 |
155 | ;; | 193 | ;; |
156 | esac | 194 | esac |
157 | 195 | ||
158 | pkg_dir=$1 | 196 | pkg_dir=$1 |
159 | 197 | ||
160 | if [ ! -d $pkg_dir ]; then | 198 | if [ ! -d $pkg_dir ]; then |
161 | echo "*** Error: Directory $pkg_dir does not exist" >&2 | 199 | echo "*** Error: Directory $pkg_dir does not exist" >&2 |
162 | exit 1 | 200 | exit 1 |
163 | fi | 201 | fi |
164 | 202 | ||
165 | # CONTROL is second so that it takes precedence | 203 | # CONTROL is second so that it takes precedence |
166 | CONTROL= | 204 | CONTROL= |
167 | [ -d $pkg_dir/DEBIAN ] && CONTROL=DEBIAN | 205 | [ -d $pkg_dir/DEBIAN ] && CONTROL=DEBIAN |
168 | [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL | 206 | [ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL |
169 | if [ -z "$CONTROL" ]; then | 207 | if [ -z "$CONTROL" ]; then |
170 | echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2 | 208 | echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2 |
171 | exit 1 | 209 | exit 1 |
172 | fi | 210 | fi |
173 | 211 | ||
212 | # load values | ||
213 | collect_values | ||
214 | |||
174 | if ! pkg_appears_sane $pkg_dir; then | 215 | if ! pkg_appears_sane $pkg_dir; then |
175 | echo >&2 | 216 | echo >&2 |
176 | echo "ipkg-build: Please fix the above errors and try again." >&2 | 217 | echo "ipkg-build: Please fix the above errors and try again." >&2 |
177 | exit 1 | 218 | exit 1 |
178 | fi | 219 | fi |
179 | 220 | ||
180 | tmp_dir=$dest_dir/IPKG_BUILD.$$ | 221 | tmp_dir=$dest_dir/IPKG_BUILD.$$ |
181 | mkdir $tmp_dir | 222 | mkdir $tmp_dir |
182 | 223 | ||
183 | tar $ogargs -C $pkg_dir -czf $tmp_dir/data.tar.gz . --exclude=$CONTROL | 224 | tar $ogargs -C $pkg_dir -czf $tmp_dir/data.tar.gz . --exclude=$CONTROL |
184 | tar $ogargs -C $pkg_dir/$CONTROL -czf $tmp_dir/control.tar.gz . | 225 | tar $ogargs -C $pkg_dir/$CONTROL -czf $tmp_dir/control.tar.gz . |
185 | 226 | ||
186 | echo "2.0" > $tmp_dir/debian-binary | 227 | echo "2.0" > $tmp_dir/debian-binary |
187 | 228 | ||
188 | pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk | 229 | pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk |
189 | here_dir=$PWD | 230 | here_dir=$PWD |
190 | ## tar -C $tmp_dir -czf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz | 231 | ## tar -C $tmp_dir -czf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz |
191 | rm -f $pkg_file | 232 | rm -f $pkg_file |
192 | if [ "$outer" = "ar" ] ; then | 233 | if [ "$outer" = "ar" ] ; then |
193 | cd $tmp_dir ; ar crf $here_dir/$pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz | 234 | cd $tmp_dir ; ar crf $here_dir/$pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz |
194 | else | 235 | else |
195 | cd $tmp_dir ; tar -zcf $here_dir/$pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz | 236 | cd $tmp_dir ; tar -zcf $here_dir/$pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz |
196 | fi | 237 | fi |
197 | cd $here_dir | 238 | cd $here_dir |