summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--lib/Makefile.in2
-rw-r--r--lib/archive72
-rw-r--r--src/opkbuild50
4 files changed, 117 insertions, 8 deletions
diff --git a/TODO b/TODO
index 31d2674..e67605e 100644
--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@ TODO:
* Fix oh-strip.
* Make oh-strip obey a missing '-l' option.
* Check on file ownership and modes.
- * Finish tar archive handling in opkhelper.
Future Plans:
* Package signing. [1]
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 526bf3a..07c5b35 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -27,7 +27,7 @@ LIBDIR = @libdir@
.SUFFIXES:
-OBJS = controlfields architecture
+OBJS = controlfields architecture archive
.PHONY: all
all: $(OBJS)
diff --git a/lib/archive b/lib/archive
new file mode 100644
index 0000000..90cec3a
--- /dev/null
+++ b/lib/archive
@@ -0,0 +1,72 @@
+#! /bin/sh
+#
+# opkhelper
+# lib/archive
+# Functions for handling archive files.
+#
+# Copyright (C) 2012 Patrick "P. J." McDermott
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+oh_archive_extract_source()
+{
+ _matches="../${OH_SRCPKG}_${OH_PKGVER}.tar.*"
+
+ if [ "${_matches}" = ../${OH_SRCPKG}_${OH_PKGVER}.tar.\* ]; then
+ # No archive found.
+ return 1
+ fi
+
+ if [ -n "$(echo "${_matches}" | grep ' ')" ]; then
+ # Multiple archives found.
+ return 2
+ fi
+
+ # Detect the compression format.
+ # Note: dpkg's source format version 3 supports gzip, bzip2, LZMA, and XZ.
+ # We support gzip, bzip2, LZMA, and compress, since these are the formats
+ # supported by BusyBox tar.
+ z_ext=${_matches#"../${OH_SRCPKG}_${OH_PKGVER}.tar."}
+ case ${_z_ext} in
+ gz)
+ _z=z
+ ;;
+ bz2)
+ _z=j
+ ;;
+ lz)
+ _z=a
+ ;;
+ Z)
+ _z=Z
+ ;;
+ *)
+ return 3
+ ;;
+ esac
+
+ _files=$(tar -t${_z}f ../${OH_SRCPKG}_${OH_PKGVER}.tar.${_z_ext} | \
+ grep -v '^./$')
+
+ if [ -z "$(echo "${_files}" | grep '/$')" ]; then
+ return 4
+ fi
+ if [ "$(echo "${_files}" | grep '/$' | wc -l)" -ne 1 ]; then
+ return 5
+ fi
+
+ tar -x${_z}f ../${OH_SRCPKG}_${OH_PKGVER}.tar.${_z_ext} || return 6
+
+ mv "${_files}" src || return 7
+}
diff --git a/src/opkbuild b/src/opkbuild
index 6cae035..d920da9 100644
--- a/src/opkbuild
+++ b/src/opkbuild
@@ -21,6 +21,7 @@
. @@LIBDIR@@/opkhelper/controlfields
. @@LIBDIR@@/opkhelper/architecture
+. @@LIBDIR@@/opkhelper/archive
print_usage()
{
@@ -171,16 +172,53 @@ for binpkgdir in ../*.pkg/; do
oh_is_buildable "${binpkg}"
if [ ${?} -eq 0 ]; then
printf 'opkbuild: Attempting to build package "%s"...\n' "${binpkg}"
- # Make installation directory.
- # TODO: Maybe this should be an FHS-compliant filesystem hierarchy.
- mkdir dest || error "${binpkg}"
# Copy or extract software sources to src.
if [ -d ../src ]; then
+ printf 'opkbuild: Copying sources into work area...\n'
cp -Rp ../src src || error "${binpkg}"
- elif [ -f ../${pkgname}_${pkgver}.tar.gz ]; then
- tar -xzf ../${pkgname}_${pkgver}.tar.gz || error "${binpkg}"
+ else
+ printf 'opkbuild: Extracting sources into work area...\n'
+ oh_archive_extract_source
+ case ${?} in
+ 1)
+ printf 'opkbuild: Error: No source archive found\n' >&2
+ exit 1
+ ;;
+ 2)
+ printf 'opkbuild: Error: Multiple source archives found\n' \
+ >&2
+ exit 1
+ ;;
+ 3)
+ printf 'opkbuild: Error: %s\n' \
+ 'Unsupported archive compression format detected' >&2
+ exit 1
+ ;;
+ 4)
+ printf 'opkbuild: Error: %s\n' \
+ 'No directories found in source archive' >&2
+ exit 1
+ ;;
+ 5)
+ printf 'opkbuild: Error: %s\n' \
+ 'Multiple top-level directories found in source archive' >&2
+ exit 1
+ ;;
+ 6)
+ printf 'opkbuild: Error: %s\n' \
+ 'Failed to extract source archive' >&2
+ exit 1
+ ;;
+ 7)
+ printf 'opkbuild: Error: %s\n' \
+ 'Failed to move extracted sources' >&2
+ exit 1
+ ;;
+ esac
fi
- # TODO: Other compression formats, putting things in src/, ...
+ # Make installation directory.
+ # TODO: Maybe this should be an FHS-compliant filesystem hierarchy.
+ mkdir dest || error "${binpkg}"
# Apply patches.
oh-applypatches
# Copy platform config files.