28
|
1 #!/bin/bash
|
|
2 # A v. 2.0 Debian package is nothing but an ar(1) archive that contains
|
|
3 # three members:
|
|
4 # 1. A debian-binary file containing the string "2.0" and a newline,
|
|
5 # 2. A compressed tar archive with a name of control,
|
|
6 # 3. A compressed tar archive with a name of data.
|
|
7 # (See https://en.wikipedia.org/wiki/Deb_%28file_format%29.) Make one.
|
|
8 #
|
|
9 # There are other ways to do this, but they tend to be so complex and
|
|
10 # badly-documented that I found it easier to just roll my own.
|
|
11
|
|
12 # Name executed as
|
|
13 myname="${0##*/}"
|
|
14
|
|
15 # We must specify single directory name and an output file.
|
|
16 if [ $# -ne 2 ]
|
|
17 then
|
|
18 1>&2 echo "$myname: expecting directory and output file"
|
|
19 exit 2
|
|
20 fi
|
|
21
|
|
22 # Change to the directory, die if we can't
|
|
23 cd "$1" || exit 2
|
|
24
|
|
25 # Do some sanity checks.
|
|
26 for i in data control
|
|
27 do
|
|
28 if [ ! -d "$i" ]
|
|
29 then
|
|
30 1>&2 echo "$myname: '$1/$i', no such directory"
|
|
31 exit 2
|
|
32 fi
|
|
33 done
|
|
34
|
|
35 # If there is no debian-binary file, make one.
|
|
36 dbin="debian-binary"
|
|
37 if [ ! -e "$dbin" ]
|
|
38 then
|
|
39 1>&2 echo "$myname: warning - '$dbin' does not exist, creating it"
|
|
40 echo "2.0" > "$dbin" || exit 1
|
|
41 fi
|
|
42
|
|
43 # Remember where we are, and bail on errors
|
|
44 set -e
|
|
45
|
|
46 # Process data
|
|
47 cd data
|
|
48 find * -type f -print0 | xargs -0 md5sum > ../control/md5sums
|
|
49 tar -c -z --owner=0 --group=0 -f ../data.tar.gz *
|
|
50
|
|
51 # Process control
|
|
52 cd ../control
|
|
53 tar -c -z --owner=0 --group=0 -f ../control.tar.gz *
|
|
54
|
|
55 # Finally, make deb file
|
|
56 cd ..
|
|
57 ar r "$2" "$dbin" control.tar.gz data.tar.gz
|