summaryrefslogtreecommitdiff
blob: e1bdd1f61b62c5dc802e8adf1dbe220ce21d8788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# 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:
NATIVE_FEED_DIR="/usr/share/0install.net/native_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//\//#}
	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.native_feed

	if [[ -n "${ZEROINSTALL_STRIP_REQUIRES}" ]]; then
		# Strip out all 'requires' sections
		sed -i -e '/<requires.*\/>/d' \
			-e '/<requires.*\>/,/<\/requires>/d' tmp.native_feed
	fi

	(
		insinto $(dirname ${output})
		newins tmp.native_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}" "${NATIVE_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_native_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_native_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}" "${NATIVE_FEED_DIR}/${feedname}"
}