summaryrefslogtreecommitdiff
path: root/scripts/ipkg-build
Unidiff
Diffstat (limited to 'scripts/ipkg-build') (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/ipkg-build63
1 files changed, 52 insertions, 11 deletions
diff --git a/scripts/ipkg-build b/scripts/ipkg-build
index c6af056..b661bbf 100755
--- a/scripts/ipkg-build
+++ b/scripts/ipkg-build
@@ -1,201 +1,242 @@
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
6set -e 6set -e
7 7
8ipkg_extract_value() { 8#declare array for values and fields found in control file
9 sed -e "s/^[^:]*:[[:space:]]*//" 9declare -a AllValues AllFields
10
11collect_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
12required_field() { 23required_field() {
13 field=$1 24 local field i
14 25 field=$1
15 value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value` 26
16 if [ -z "$value" ]; then 27 i=0
17 echo "*** Error: $CONTROL/control is missing field $field" >&2 28 for af in "${AllFields[@]}"
18 return 1 29 do
19 fi 30 if [ "$field" = "$af" ]
20 echo $value 31 then
21 return 0 32 # return value
33 echo "${AllValues[$i]}"
34 return 0;
35 fi
36 let i=i+1
37 done
38 # not found
39 echo "*** Error: $CONTROL/control is missing field $field" >&2
40 return 1
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
24pkg_appears_sane() { 59pkg_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 '~'.
35You probably want to remove them: " >&2 70You 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.
44You probably want to chown these to a system user: " >&2 79You 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
48 83
49 84
50 if [ ! -f "$CONTROL/control" ]; then 85 if [ ! -f "$CONTROL/control" ]; then
51 echo "*** Error: Control file $pkg_dir/$CONTROL/control not found." >&2 86 echo "*** Error: Control file $pkg_dir/$CONTROL/control not found." >&2
52 cd $owd 87 cd $owd
53 return 1 88 return 1
54 fi 89 fi
55 90
56 pkg=`required_field Package` 91 pkg=`required_field Package`
57 [ "$?" -ne 0 ] && PKG_ERROR=1 92 [ "$?" -ne 0 ] && PKG_ERROR=1
58 93
59 version=`required_field Version | sed 's/Version://; s/^.://g;'` 94 version=`required_field Version | sed 's/Version://; s/^.://g;'`
60 [ "$?" -ne 0 ] && PKG_ERROR=1 95 [ "$?" -ne 0 ] && PKG_ERROR=1
61 96
62 arch=`required_field Architecture` 97 arch=`required_field Architecture`
63 [ "$?" -ne 0 ] && PKG_ERROR=1 98 [ "$?" -ne 0 ] && PKG_ERROR=1
64 99
65 required_field Maintainer >/dev/null 100 required_field Maintainer >/dev/null
66 [ "$?" -ne 0 ] && PKG_ERROR=1 101 [ "$?" -ne 0 ] && PKG_ERROR=1
67 102
68 required_field Description >/dev/null 103 required_field Description >/dev/null
69 [ "$?" -ne 0 ] && PKG_ERROR=1 104 [ "$?" -ne 0 ] && PKG_ERROR=1
70 105
71 section=`required_field Section` 106 section=`required_field Section`
72 [ "$?" -ne 0 ] && PKG_ERROR=1 107 [ "$?" -ne 0 ] && PKG_ERROR=1
73 if [ -z "$section" ]; then 108 if [ -z "$section" ]; then
74 echo "The Section field should have one of the following values:" >&2 109 echo "The Section field should have one of the following values:" >&2
75 echo "admin, base, comm, editors, extras, games, graphics, kernel, libs, misc, net, text, web, x11" >&2 110 echo "admin, base, comm, editors, extras, games, graphics, kernel, libs, misc, net, text, web, x11" >&2
76 fi 111 fi
77 112
78 priority=`required_field Priority` 113 priority=`required_field Priority`
79 [ "$?" -ne 0 ] && PKG_ERROR=1 114 [ "$?" -ne 0 ] && PKG_ERROR=1
80 if [ -z "$priority" ]; then 115 if [ -z "$priority" ]; then
81 echo "The Priority field should have one of the following values:" >&2 116 echo "The Priority field should have one of the following values:" >&2
82 echo "required, important, standard, optional, extra." >&2 117 echo "required, important, standard, optional, extra." >&2
83 echo "If you don't know which priority value you should be using, then use \`optional'" >&2 118 echo "If you don't know which priority value you should be using, then use \`optional'" >&2
84 fi 119 fi
85 120
86 if echo $pkg | grep '[^a-z0-9.+-]'; then 121 if echo $pkg | grep '[^a-z0-9.+-]'; then
87 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2 122 echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
88 PKG_ERROR=1; 123 PKG_ERROR=1;
89 fi 124 fi
90 125
91 local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'` 126 local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
92 if [ -n "$bad_fields" ]; then 127 if [ -n "$bad_fields" ]; then
93 bad_fields=`echo $bad_fields` 128 bad_fields=`echo $bad_fields`
94 echo "*** Error: The following fields in $CONTROL/control are missing a ':'" >&2 129 echo "*** Error: The following fields in $CONTROL/control are missing a ':'" >&2
95 echo "$bad_fields" >&2 130 echo "$bad_fields" >&2
96 echo "ipkg-build: This may be due to a missing initial space for a multi-line field value" >&2 131 echo "ipkg-build: This may be due to a missing initial space for a multi-line field value" >&2
97 PKG_ERROR=1 132 PKG_ERROR=1
98 fi 133 fi
99 134
100 for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do 135 for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do
101 if [ -f $script -a ! -x $script ]; then 136 if [ -f $script -a ! -x $script ]; then
102 echo "*** Error: package script $script is not executable" >&2 137 echo "*** Error: package script $script is not executable" >&2
103 PKG_ERROR=1 138 PKG_ERROR=1
104 fi 139 fi
105 done 140 done
106 141
107 if [ -f $CONTROL/conffiles ]; then 142 if [ -f $CONTROL/conffiles ]; then
108 for cf in `cat $CONTROL/conffiles`; do 143 for cf in `cat $CONTROL/conffiles`; do
109 if [ ! -f ./$cf ]; then 144 if [ ! -f ./$cf ]; then
110 echo "*** Error: $CONTROL/conffiles mentions conffile $cf which does not exist" >&2 145 echo "*** Error: $CONTROL/conffiles mentions conffile $cf which does not exist" >&2
111 PKG_ERROR=1 146 PKG_ERROR=1
112 fi 147 fi
113 done 148 done
114 fi 149 fi
115 150
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###
123ogargs="" 158ogargs=""
124outer=ar 159outer=ar
125usage="Usage: $0 [-c] [-o owner] [-g group] <pkg_directory> [<destination_directory>]" 160usage="Usage: $0 [-c] [-o owner] [-g group] <pkg_directory> [<destination_directory>]"
126while getopts "cg:o:" opt; do 161while 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
138done 173done
139 174
175# maks sure that tar produces headers compatible with busybox format
176# debian needs this
177ogargs="$ogargs --format=oldgnu"
140 178
141shift $(($OPTIND - 1)) 179shift $(($OPTIND - 1))
142 180
143# continue on to process additional arguments 181# continue on to process additional arguments
144 182
145case $# in 183case $# in
1461) 1841)
147 dest_dir=. 185 dest_dir=.
148 ;; 186 ;;
1492) 1872)
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 ;;
156esac 194esac
157 195
158pkg_dir=$1 196pkg_dir=$1
159 197
160if [ ! -d $pkg_dir ]; then 198if [ ! -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
163fi 201fi
164 202
165# CONTROL is second so that it takes precedence 203# CONTROL is second so that it takes precedence
166CONTROL= 204CONTROL=
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
169if [ -z "$CONTROL" ]; then 207if [ -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
172fi 210fi
173 211
212# load values
213collect_values
214
174if ! pkg_appears_sane $pkg_dir; then 215if ! 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
178fi 219fi
179 220
180tmp_dir=$dest_dir/IPKG_BUILD.$$ 221tmp_dir=$dest_dir/IPKG_BUILD.$$
181mkdir $tmp_dir 222mkdir $tmp_dir
182 223
183tar $ogargs -C $pkg_dir -czf $tmp_dir/data.tar.gz . --exclude=$CONTROL 224tar $ogargs -C $pkg_dir -czf $tmp_dir/data.tar.gz . --exclude=$CONTROL
184tar $ogargs -C $pkg_dir/$CONTROL -czf $tmp_dir/control.tar.gz . 225tar $ogargs -C $pkg_dir/$CONTROL -czf $tmp_dir/control.tar.gz .
185 226
186echo "2.0" > $tmp_dir/debian-binary 227echo "2.0" > $tmp_dir/debian-binary
187 228
188pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk 229pkg_file=$dest_dir/${pkg}_${version}_${arch}.ipk
189here_dir=$PWD 230here_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
191rm -f $pkg_file 232rm -f $pkg_file
192if [ "$outer" = "ar" ] ; then 233if [ "$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
194else 235else
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
196fi 237fi
197cd $here_dir 238cd $here_dir
198rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz 239rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz
199rmdir $tmp_dir 240rmdir $tmp_dir
200 241
201echo "Packaged contents of $pkg_dir into $pkg_file" 242echo "Packaged contents of $pkg_dir into $pkg_file"