~ubuntu-branches/debian/wheezy/agtl/wheezy

« back to all changes in this revision

Viewing changes to ipkg-utils-1.7/ipkg-deb-build

  • Committer: Bazaar Package Importer
  • Author(s): Heiko Stuebner
  • Date: 2011-01-22 13:55:12 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110122135512-1mik0vssgpnx2fgu
Tags: 0.8.0.3-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# ipkg-deb-build -- construct a debian file format .ipk from a directory
 
4
# Jamey Hicks <jamey.hicks@hp.com>
 
5
# Carl Worth <cworth@east.isi.edu>
 
6
# based on a script by Steve Redler IV, steve@sr-tech.com 5-21-2001
 
7
set -e
 
8
 
 
9
ipkg_extract_value() {
 
10
        sed -e "s/^[^:]*:[[:space:]]*//"
 
11
}
 
12
 
 
13
required_field() {
 
14
        field=$1
 
15
 
 
16
        value=`grep "^$field:" < $CONTROL/control | ipkg_extract_value`
 
17
        if [ -z "$value" ]; then
 
18
                echo "*** Error: $CONTROL/control is missing field $field" >&2
 
19
                return 1
 
20
        fi
 
21
        echo $value
 
22
        return 0
 
23
}
 
24
 
 
25
pkg_appears_sane() {
 
26
        local pkg_dir=$1
 
27
 
 
28
        local owd=`pwd`
 
29
        cd $pkg_dir
 
30
 
 
31
        PKG_ERROR=0
 
32
 
 
33
        tilde_files=`find . -name '*~'`
 
34
        if [ -n "$tilde_files" ]; then
 
35
                echo "*** Warning: The following files have names ending in '~'.
 
36
You probably want to remove them: " >&2
 
37
                ls -ld $tilde_files
 
38
                echo >&2
 
39
        fi
 
40
 
 
41
        large_uid_files=`find . -uid +99`
 
42
        if [ -n "$large_uid_files" ]; then
 
43
                echo "*** Warning: The following files have a UID greater than 99.
 
44
You probably want to chown these to a system user: " >&2
 
45
                ls -ld $large_uid_files
 
46
                echo >&2
 
47
        fi
 
48
            
 
49
 
 
50
        if [ ! -f "$CONTROL/control" ]; then
 
51
                echo "*** Error: Control file $pkg_dir/$CONTROL/control not found." >&2
 
52
                cd $owd
 
53
                return 1
 
54
        fi
 
55
 
 
56
        pkg=`required_field Package`
 
57
        [ "$?" -ne 0 ] && PKG_ERROR=1
 
58
 
 
59
        version=`required_field Version | sed 's/.*://;'`
 
60
        [ "$?" -ne 0 ] && PKG_ERROR=1
 
61
 
 
62
        arch=`required_field Architecture`
 
63
        [ "$?" -ne 0 ] && PKG_ERROR=1
 
64
 
 
65
        required_field Maintainer >/dev/null
 
66
        [ "$?" -ne 0 ] && PKG_ERROR=1
 
67
 
 
68
        required_field Description >/dev/null
 
69
        [ "$?" -ne 0 ] && PKG_ERROR=1
 
70
 
 
71
        section=`required_field Section`
 
72
        [ "$?" -ne 0 ] && PKG_ERROR=1
 
73
        if [ -z "$section" ]; then
 
74
            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
 
76
        fi
 
77
 
 
78
        priority=`required_field Priority`
 
79
        [ "$?" -ne 0 ] && PKG_ERROR=1
 
80
        if [ -z "$priority" ]; then
 
81
            echo "The Priority field should have one of the following values:" >&2
 
82
            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
 
84
        fi
 
85
 
 
86
        if echo $pkg | grep '[^a-z0-9.+-]'; then
 
87
                echo "*** Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" >&2
 
88
                PKG_ERROR=1;
 
89
        fi
 
90
 
 
91
        local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
 
92
        if [ -n "$bad_fields" ]; then
 
93
                bad_fields=`echo $bad_fields`
 
94
                echo "*** Error: The following fields in $CONTROL/control are missing a ':'" >&2
 
95
                echo "  $bad_fields" >&2
 
96
                echo "ipkg-build: This may be due to a missing initial space for a multi-line field value" >&2
 
97
                PKG_ERROR=1
 
98
        fi
 
99
 
 
100
        for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do
 
101
                if [ -f $script -a ! -x $script ]; then
 
102
                        echo "*** Error: package script $script is not executable" >&2
 
103
                        PKG_ERROR=1
 
104
                fi
 
105
        done
 
106
 
 
107
        if [ -f $CONTROL/conffiles ]; then
 
108
                for cf in `cat $CONTROL/conffiles`; do
 
109
                        if [ ! -f ./$cf ]; then
 
110
                                echo "*** Error: $CONTROL/conffiles mentions conffile $cf which does not exist" >&2
 
111
                                PKG_ERROR=1
 
112
                        fi
 
113
                done
 
114
        fi
 
115
 
 
116
        cd $owd
 
117
        return $PKG_ERROR
 
118
}
 
119
 
 
120
###
 
121
# ipkg-build "main"
 
122
###
 
123
 
 
124
case $# in
 
125
1)
 
126
        dest_dir=.
 
127
        ;;
 
128
2)
 
129
        dest_dir=$2
 
130
        ;;
 
131
*)
 
132
        echo "Usage: ipkg-build <pkg_directory> [<destination_directory>]" >&2
 
133
        exit 1 
 
134
        ;;
 
135
esac
 
136
 
 
137
pkg_dir=$1
 
138
 
 
139
if [ ! -d $pkg_dir ]; then
 
140
        echo "*** Error: Directory $pkg_dir does not exist" >&2
 
141
        exit 1
 
142
fi
 
143
 
 
144
# CONTROL is second so that it takes precedence
 
145
CONTROL=
 
146
[ -d $pkg_dir/DEBIAN ] && CONTROL=DEBIAN
 
147
[ -d $pkg_dir/CONTROL ] && CONTROL=CONTROL
 
148
if [ -z "$CONTROL" ]; then
 
149
        echo "*** Error: Directory $pkg_dir has no CONTROL subdirectory." >&2
 
150
        exit 1
 
151
fi
 
152
 
 
153
if ! pkg_appears_sane $pkg_dir; then
 
154
        echo >&2
 
155
        echo "ipkg-build: Please fix the above errors and try again." >&2
 
156
        exit 1
 
157
fi
 
158
 
 
159
tmp_dir=$dest_dir/IPKG_BUILD.$$
 
160
mkdir $tmp_dir
 
161
 
 
162
tar -C $pkg_dir -czf $tmp_dir/data.tar.gz . --exclude=$CONTROL
 
163
tar -C $pkg_dir/$CONTROL -czf $tmp_dir/control.tar.gz .
 
164
 
 
165
echo "2.0" > $tmp_dir/debian-binary
 
166
 
 
167
pkg_file=${pkg}_${version}_${arch}.ipk
 
168
pkg_dir=$PWD
 
169
cd $tmp_dir
 
170
ar crf $pkg_dir/$pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz
 
171
cd $pkg_dir
 
172
mv $pkg_file $dest_dir
 
173
rm -f $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz
 
174
rmdir $tmp_dir
 
175
 
 
176
echo "Packaged contents of $pkg_dir into $pkg_file"