annotate make-debian-package @ 28:c310ec097194

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