blob: 7ea66c71bd53ed0da52ef87f8b874771d8e66943 (
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
|
#!@BASH@
# -*-eselect-*- vim: ft=eselect
# Copyright (c) 2005-2011 Gentoo Foundation
# $Id$
# This file is part of the 'eselect' tools framework.
#
# eselect 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 2 of the License, or (at your option) any later
# version.
#
# eselect 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
# eselect. If not, see <http://www.gnu.org/licenses/>.
# Where are our data?
ESELECT_DATA_PATH="@DATADIR@/eselect"
# Where are modules installed by default?
ESELECT_DEFAULT_MODULES_PATH="${ESELECT_DATA_PATH}/modules"
# Look in these places for modules
ESELECT_MODULES_PATH=( \
"${HOME}/.eselect/modules" \
"${ESELECT_DEFAULT_MODULES_PATH}" )
# Look in this place for libraries
ESELECT_CORE_PATH="${ESELECT_DATA_PATH}/libs"
# Look here for the default contents of a module
ESELECT_DEFAULT_ACTIONS="${ESELECT_CORE_PATH}/default.eselect"
# Our program name and version
ESELECT_VERSION="@VERSION@"
ESELECT_PROGRAM_NAME="eselect"
# Invocation information
ESELECT_BINARY_NAME="${0}"
ESELECT_KILL_TARGET="$$"
# Global options
ESELECT_OPTIONS=""
# Support variables for Gentoo Prefix
EPREFIX="@EPREFIX@"
EROOT="${ROOT}${EPREFIX}"
# Remove all alias definitions. Unset functions and variables that are
# known to cause trouble.
"unalias" -a
unset -f rm
unset CDPATH GLOBIGNORE
IFS=$' \t\n'
shopt -s extglob
shopt -s expand_aliases
# Load core functions
source "${ESELECT_CORE_PATH}/core.bash" || exit 255
# Load necessary functions for the main script
inherit manip output path-manipulation tests
# Sneaky trick to make die in subshells work. If you don't get
# it, don't ask...
trap 'echo "exiting" >&2; exit 250' 15
# es_find_module foo
# Find and echo the filename of the foo module. If there's no foo module,
# die.
es_find_module() {
local modname="$1" modpath="" modfile=""
[[ -z ${modname} ]] && die "Usage: ${FUNCNAME} <module>"
for modpath in "${ESELECT_MODULES_PATH[@]}" ; do
[[ -f ${modpath}/${modname}.eselect ]] && break
done
modfile="${modpath}/${modname}.eselect"
[[ -r ${modfile} ]] || die -q "Can't load module ${modname}"
echo ${modfile}
}
# es_do_usage
# Display eselect usage
es_do_usage() {
echo "Usage: eselect <global options> <module name> <module options>"
}
# es_do_help
# Display eselect help
es_do_help() {
set_output_mode default
es_do_usage
echo
es_do_list_options
echo
es_do_list_modules
}
# es_do_version
# Display eselect version
es_do_version() {
echo "eselect ${ESELECT_VERSION}"
echo
echo "Copyright (c) 2005-2011 Gentoo Foundation."
echo "Distributed under the terms of the GNU GPL version 2 or later."
}
# es_do_list_options
# Display all recognized global options
es_do_list_options() {
write_list_start "Global options:"
write_kv_list_entry "--brief" "Make output shorter"
write_kv_list_entry "--no-color,--no-colour" "Disable coloured output"
}
# es_do_list_modules
# Display all available eselect modules DEPRECATED
es_do_list_modules() {
do_action modules list "$@"
}
### main code ###
# enable colour output and get width of terminal iff stdout is a tty
if [[ -t 1 ]]; then
colours
init_columns
else
nocolours
fi
# figure out what the action is. we need to know whether we're
# invoked as a something-config/something-update.
action=""
for suffix in config update{,r} tool manager reader ; do
if [[ ${0%%-${suffix}} != ${0} ]] ; then
action=$(basename "${0}" )
action=${action%%-${suffix}}
break
fi
done
unset suffix
if [[ -z ${action} ]] ; then
binname=$(basename "${0}" )
for prefix in config update{,r} manage 'read' ; do
if [[ ${binname##${prefix}-} != ${binname} ]] ; then
action=$(basename "${0}" )
action=${action##${prefix}-}
break
fi
done
unset binname prefix
fi
if [[ -z ${action} ]] && [[ -n ${1##--} ]] ; then
while [[ ${1##--} != ${1} ]] ; do
case ${1##--} in
brief)
ESELECT_OPTIONS="${ESELECT_OPTIONS} brief"
set_output_mode brief
;;
no-colour|no-color)
ESELECT_OPTIONS="${ESELECT_OPTIONS} no-colour"
nocolours
;;
help|version)
action=${1##--}
;;
*)
die -q "Unknown option ${1}"
;;
esac
shift
done
if [[ -z ${action} ]]; then
action=${1}
shift
fi
fi
if [[ -n ${action} ]] ; then
if is_function "es_do_${action//-/_}" ; then
[[ $# -gt 0 ]] && die -q "Too many parameters"
es_do_${action//-/_}
else
do_action "${action}" "$@"
fi
else
es_do_help
fi
|