diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make-debian-package	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,57 @@
+#!/bin/bash
+# A v. 2.0 Debian package is nothing but an ar(1) archive that contains
+# three members:
+# 1. A debian-binary file containing the string "2.0" and a newline,
+# 2. A compressed tar archive with a name of control,
+# 3. A compressed tar archive with a name of data.
+# (See https://en.wikipedia.org/wiki/Deb_%28file_format%29.) Make one.
+#
+# There are other ways to do this, but they tend to be so complex and
+# badly-documented that I found it easier to just roll my own.
+
+# Name executed as
+myname="${0##*/}"
+
+# We must specify single directory name and an output file.
+if [ $# -ne 2 ]
+then
+    1>&2 echo "$myname: expecting directory and output file"
+    exit 2
+fi
+
+# Change to the directory, die if we can't
+cd "$1" || exit 2
+
+# Do some sanity checks.
+for i in data control
+do
+    if [ ! -d "$i" ]
+    then
+        1>&2 echo "$myname: '$1/$i', no such directory"
+        exit 2
+    fi
+done
+
+# If there is no debian-binary file, make one.
+dbin="debian-binary"
+if [ ! -e "$dbin" ]
+then
+    1>&2 echo "$myname: warning - '$dbin' does not exist, creating it"
+    echo "2.0" > "$dbin" || exit 1
+fi
+
+# Remember where we are, and bail on errors
+set -e
+
+# Process data
+cd data
+find * -type f -print0 | xargs -0 md5sum > ../control/md5sums
+tar -c -z --owner=0 --group=0 -f ../data.tar.gz *
+
+# Process control
+cd ../control
+tar -c -z --owner=0 --group=0 -f ../control.tar.gz *
+
+# Finally, make deb file
+cd ..
+ar r "$2" "$dbin" control.tar.gz data.tar.gz