summaryrefslogtreecommitdiffstats
path: root/unpack-debuginfo.sh
diff options
context:
space:
mode:
Diffstat (limited to 'unpack-debuginfo.sh')
-rwxr-xr-xunpack-debuginfo.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/unpack-debuginfo.sh b/unpack-debuginfo.sh
new file mode 100755
index 0000000..b31a179
--- /dev/null
+++ b/unpack-debuginfo.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+# unpack-debuginfo.sh - a simple script to unpack an RPM in a manner
+# usable by debuginfofs.
+#
+# GPLv2+. BOILERPLATE SHOULD GO HERE.
+#
+# Copyright 2009 Red Hat, Inc.
+# Author: Will Woods <wwoods@redhat.com>
+
+source config.sh
+
+if [ -z "$libdir" ]; then
+ echo "Couldn't find config.sh - exiting."
+ exit 1
+fi
+
+if [ $# -lt 2 ]; then
+ echo "Usage: $0 reponame rpmfile [rpmfile...]"
+ echo "unpacks the given rpmfiles under $libdir/reponame"
+ exit 1
+fi
+
+function rpm_envra {
+ if [ -z "$1" ]; then return; fi
+ envra="$(rpm -qp $1 --qf '%{E}:%{N}-%{V}-%{R}.%{ARCH}' 2>/dev/null)"
+ if [ "${envra:0:1}" == ":" ]; then
+ envra="0$envra"
+ elif [ "${envra:0:6}" == "(none)" ]; then
+ envra="0${envra:6}"
+ fi
+ echo $envra
+}
+
+function unpack_rpm {
+ [ "$debug" ] && echo "unpack_rpm($1 $2)" >&2
+ rpmfile="$1"
+ targetdir="$2"
+ rpm2cpio $1 | ( cd $targetdir; cpio --quiet -iumd )
+ # Fix dir perms so that anyone can read the data
+ find $targetdir -type d -exec chmod a+rx {} +
+}
+
+reponame="$1"
+shift
+
+# TODO perm check
+
+# FIXME only do this if we're sure that reponame is OK?
+mkdir -p "$libdir/$reponame"
+
+if [ ! -d "$libdir/$reponame" ]; then
+ echo "$libdir/$reponame does not exist - please create it first."
+ exit 1
+fi
+
+while [ $# -gt 0 ]; do
+ envra="$(rpm_envra $1)"
+ nvra="${envra#*:}"
+ first_letter="${nvra:0:1}"
+ targetdir="$libdir/$reponame/$first_letter/$envra"
+ if [ -d $targetdir ]; then
+ [ "$verbose" ] && echo "$envra already unpacked; skipping..."
+ else
+ mkdir -p $targetdir
+ unpack_rpm $1 $targetdir
+ fi
+ shift
+done