aboutsummaryrefslogtreecommitdiff
path: root/eselect/repo.eselect
blob: 6644e45fdc0bc180edce9dca7a92332e0c372c9e (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright 1999-2006 Stephen Bennett <spb@gentoo.org>
# Distributed under the terms of the GNU General Public License v2
# $Id: $

DESCRIPTION="Manage Paludis repository config files"
MAINTAINER="spb@gentoo.org"
SVN_DATE='$Date: $'
VERSION=$(svn_date_to_version "${SVN_DATE}" )

REPO_CONFIG_FILE="${ROOT}/var/lib/eselect/repo/repo.config"

inherit config

## {{{ Utility functions

cat_file() {
	local filename=$1
	if [[ -r ${filename} ]]; then
		cat "${filename}"
	elif [[ ${filename} == http://* ]]; then
		wget -O - -q "${filename}"
	elif [[ ${filename} == svn://* ]]; then
		svn cat "${filename}"
	elif [[ ${filename} != */* ]]; then
		templateroot="$(get_var template_root)"
		cat_file "${templateroot}/${filename}.templ"
	else
		die -q "Couldn't load ${filename}"
	fi
}

get_var() {
	default_template_root="http://svn.pioto.org/paludis/repo-templates"
	default_repo_root="${ROOT}/var/paludis/repositories"
	default_config_root="${ROOT}/etc/paludis"
	if [[ -L /etc/make.profile ]]; then
		default_profiles="$(readlink -f /etc/make.profile)"
	fi
	local var=$1
	local defvar="default_$1"
	local value="$(load_config ${REPO_CONFIG_FILE} "${var}")"
	if [[ -z "${value}" ]]; then
		value=${!defvar}
	fi
	echo "${value}"
}

## }}}

### list action

## {{{ list stuff
describe_list() {
	echo "Show available repository templates"
}

do_list() {
	templateroot=$(get_var template_root)

	local -a list=( $(cat_file ${templateroot}/list) )
	write_list_start "Available repository templates: (* == installed)"
	local count=0
	for i in "${list[@]}"; do
		local inst=''
		if [[ -e $(get_var config_root)/repositories/${i}.conf ]]; then
			inst=$(highlight \*)
		fi
		write_numbered_list_entry $(( ++count )) "${i} ${inst}"
	done
}
## }}}

### install action

## {{{ install stuff
describe_install() {
	echo "Install a repository config from a given template name"
}

do_install() {
	local force=0
	if [[ $1 == -f ]] || [[ $1 == --force ]]; then
		force=1
		shift
	fi

	if [[ -e $(get_var config_root)/repositories/$1.conf ]] && [[ $force == 0 ]]; then
		write_error_msg "$1 appears to be already installed. "
		write_error_msg "To overwrite it, use --force or -f."
		die -q "Repository already exists and --force not specified"
	fi

	do_subst() {
		if [[ $1 == location_of ]]; then
			echo $(paludis --list-repositories --repository $2 | sed -n \
				's/.*location: *//p') || die -q "Couldn't find location of $2"
		elif [[ $1 == profiles ]]; then
			profiles=$(get_var profiles)
			if [[ -z ${profiles} ]]; then
				die -q "profile expansion requested but no profiles set."
			fi
			echo ${profiles}
		elif [[ $1 == repo_root ]]; then
			echo $(get_var repo_root)
		fi
	}

	( cat_file $1 || die -q "Couldn't read template $1" ) | (
		local format=portage
		while read line; do
			while [[ $line == *@*@* ]]; do
				subst=${line#*@}
				subst=${subst%%@*}
				line=${line%%@*}$(do_subst ${subst})${line#*@*@}
			done
			if [[ ${line} == format=* ]]; then
				format=${line#format=}
			fi
			echo $line
		done;
		if [[ ${format} == portage ]]; then
			distdir=$(get_var distdir)
			[[ -n ${distdir} ]] && echo "distdir=${distdir}"
		fi
	) >"$(get_var config_root)/repositories/$1.conf.tmp"

	if [[ ! -f "$(get_var config_root)/repositories/$1.conf)" ]]; then
		mv $(get_var config_root)/repositories/$1.conf{.tmp,}
	else
		die -q "Error creating ${1}.conf"
	fi
}

## }}}

### uninstall action

## {{{ uninstall stuff

describe_uninstall()
{
	echo "Remove a repository config"
}

do_uninstall() {
	repo_dir="$(get_var config_root)/repositories"
	for i in "$@"; do
		if [[ -f "${repo_dir}/${i}.conf" ]]; then
			rm -f "${repo_dir}/${i}.conf"
		else
			write_error_msg "Repository '${i}' not found at"
			write_error_msg "${repo_dir}/${i}.conf"
		fi
	done
}

## }}}

### set action

## {{{ set stuff

describe_set()
{
	echo "Set various config values"
}

do_set()
{
	if [[ $# -ge 2 ]]; then
		var=$1; shift
		store_config ${REPO_CONFIG_FILE} $var "$*"
	elif [[ $# -eq 1 ]]; then
		store_config ${REPO_CONFIG_FILE} $1 ""
	fi
}

## }}}

### show action

## {{{ show stuff

describe_show()
{
	echo "Display various configuration variables"
}

do_show()
{
	if [[ -n $1 ]]; then
		vars=$1
	else
		vars=( template_root repo_root profiles distdir config_root )
		write_list_start "Current configuration variables:"
		for i in ${vars[@]}; do
			value=$(load_config ${REPO_CONFIG_FILE} $i)
			if [[ -n ${value} ]]; then
				write_kv_list_entry $i "${value}"
			fi
		done
	fi
}

## }}}

# vim: ts=4 sw=4 noet fdm=marker