summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'eclass/0install.eclass')
-rw-r--r--eclass/0install.eclass137
1 files changed, 137 insertions, 0 deletions
diff --git a/eclass/0install.eclass b/eclass/0install.eclass
new file mode 100644
index 0000000..303371a
--- /dev/null
+++ b/eclass/0install.eclass
@@ -0,0 +1,137 @@
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+#
+# Original Author: Jim Ramsay <lack@gentoo.org>
+# Purpose: Utility functions for 0install compatibility
+#
+
+# TODO: Install this all the time?
+RDEPEND="rox-base/zeroinstall-injector"
+
+# Environment:
+LOCAL_FEED_DIR="/etc/xdg/0install.net/local_feeds"
+ZEROINSTALL_STRIP_REQUIRES=""
+
+# Escapes a http-style URI into a 0install-compatible filename
+#
+# 0install_escape_uri <uri>
+# uri - The URI to escape
+0install_escape_uri() {
+ local uri=${1}
+ uri=${uri//:/%3a}
+ uri=${uri//\//%2f}
+ echo $uri
+}
+
+# Parses an implementation, returning the interface URI
+#
+# 0install_parse_uri <src>
+# src - The XML document to parse
+0install_parse_uri() {
+ local src="${1}"
+
+ [ -f "${src}" ] || die "Source file not found"
+ local feed_for=$(grep '<feed-for.*interface=' "${src}")
+ [ -n "${feed_for}" ] || die "No 'feed-for' element"
+ feed_for=${feed_for##*interface=[\"\']}
+ feed_for=${feed_for%[\'\"]*>}
+ echo $feed_for
+}
+
+# Edits a feed, replacing stability and id
+#
+# 0install_edit_feed <input> <stability>
+# input - The file to edit
+# output - The final install location (relative to ${D})
+0install_edit_feed() {
+ local input="${1}"; shift
+ local output="${1}"; shift
+
+ [ -f "${input}" ] || die "No input file"
+
+ # Basic editing:
+ # - Remove stability="*"
+ # - Remove uri="*"
+ # - Replace id="*" with id=".", add in stability="packaged"
+ # - Force main="AppRun"
+ sed -e 's/stability="[^"]*"//' \
+ -e "s/stability='[^']*'//" \
+ -e 's/uri="[^"]*"//' \
+ -e "s/uri='[^']*'//" \
+ -e 's/id="[^"]*"/id="." stability="packaged"/' \
+ -e "s/id='[^']*'/id=\".\" stability=\"packaged\"/" \
+ -e 's/main="[^"]*"/main="AppRun"/' \
+ -e "s/main='[^']*'/main=\"AppRun\"/" \
+ ${input} > tmp.local_feed
+
+ if [[ -n "${ZEROINSTALL_STRIP_REQUIRES}" ]]; then
+ # Strip out all 'requires' sections
+ sed -i -e '/<requires.*\/>/d' \
+ -e '/<requires.*\>/,/<\/requires>/d' tmp.local_feed
+ fi
+
+ (
+ insinto $(dirname ${output})
+ newins tmp.local_feed $(basename ${output})
+ )
+}
+
+# Installs an ebuild-provided feed
+#
+# 0install_install_feed <src> <destpath>
+# src - The XML file we will install and point at
+# path - The path where the implementation will be installed
+# IE, the final xml will be at <path>/<basename of src>
+0install_install_feed() {
+ local src="${1}"; shift
+ local path="${1}"; shift
+ local feedfile=$(basename "${src}")
+ local dest="${path}/$feedfile"
+
+ # Step 1: Find the URI
+ local uri=$(0install_parse_uri "${src}")
+
+ # Step 2: Install the feed in the proper location
+ (
+ insinto $(dirname "${dest}")
+ newins "${src}" $(basename "${dest}")
+ )
+
+ # Step 3: Install the symlink so 0install can find it
+ local feedname=$(0install_escape_uri ${uri})
+ dosym "${dest}" "${LOCAL_FEED_DIR}/${feedname}"
+}
+
+# Does all the local feed magic you could want:
+# - Parses the input file to get the interface URI
+# - Edits the input file and installs it to the final location
+# - Installs a local feed pointer
+#
+# Environment variables:
+# ZEROINSTALL_STRIP_REQUIRES - If set, strips all 'requires' sections from the XML
+# on editing. Default: Not set
+#
+# 0install_local_feed <src> <destpath>
+# src - The XML file we will edit, install, and point at
+# path - The path where the implementation will be installed
+# IE, the final edited xml will be at <path>/<basename of src>
+0install_local_feed() {
+ local src="${1}"; shift
+ local path="${1}"; shift
+ local feedfile=$(basename "${src}")
+ local dest="${path}/$feedfile"
+
+ # Step 1: Find the URI
+ local uri=$(0install_parse_uri "${src}")
+
+ # Step 2: Edit the input and install it in the proper location
+ 0install_edit_feed "${src}" "${dest}"
+
+ # Step 3: Install the symlink so 0install can find it
+ local feedname=$(0install_escape_uri ${uri})
+ dosym "${dest}" "${LOCAL_FEED_DIR}/${feedname}"
+}
+
+