From 3ad9b0f39e50e4853ab6529e49f24fd0536cdcdb Mon Sep 17 00:00:00 2001
From: P. J. McDermott <pjm@nac.net>
Date: Thu, 19 Jan 2012 23:08:25 -0500
Subject: Add sanity checks and comments to opkbuild.

---
diff --git a/src/opkbuild b/src/opkbuild
index e4d8d60..ce9fe34 100644
--- a/src/opkbuild
+++ b/src/opkbuild
@@ -24,8 +24,17 @@ print_usage()
 	printf 'Usage: %s\n' "$1"
 }
 
-# TODO: Sanity checks.
+# Sanity checks.
+if [ ! -f format -o ! -f build -o ! -f control ]; then
+	printf 'Error: Current working directory is not a source package.\n' >&2
+	exit 1
+fi
+if [ "$(cat format)" != '1.0' ]; then
+	printf 'Error: Source package is of an incompatible version.\n' >&2
+	exit 1
+fi
 
+# Build *-src package.
 mkdir -p tmp/dest/usr/src/${pkgname}_${pkgver}
 cd tmp
 for file in ../*; do
@@ -41,10 +50,14 @@ done
 oh-buildpkg ${pkgname}-src
 rm -Rf dest
 
+# Build other binary packages.
 for binpkgdir in ../*.pkg/; do
 	# TODO: Check architecture.
 	if true; then
+		# Make installation directory.
+		# TODO: Maybe this should be an FHS-compliant filesystem hierarchy.
 		mkdir dest
+		# Copy or extract software sources to src.
 		if [ -d ../src ]; then
 			cp -Rp ../src src
 		elif [ -f ../${pkgname}_${pkgver}.tar.gz ]; then
@@ -53,7 +66,9 @@ for binpkgdir in ../*.pkg/; do
 		# TODO: Other compression formats, putting things in src/, ...
 		binpkg=${binpkgdir#'../'}
 		binpkg=${binpkg%'.pkg/}
+		# Build the package.
 		../build ${binpkg}
+		# Clean up everything except the build stamps.
 		for file in *; do
 			case ${file} in
 				*.buildstamp)
--
cgit v0.9.1