Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 214817 | Differences between
and this patch

Collapse All | Expand All

(-)sh.eselect-0.1 (-16 / +16 lines)
Lines 4-10 Link Here
4
4
5
DESCRIPTION="Manage /bin/sh (POSIX shell) implementations"
5
DESCRIPTION="Manage /bin/sh (POSIX shell) implementations"
6
MAINTAINER="gentoo@mgorny.alt.pl"
6
MAINTAINER="gentoo@mgorny.alt.pl"
7
VERSION="0.1"
7
VERSION="0.2_rc"
8
8
9
# Based on work of Erik Hahn; bug #214817
9
# Based on work of Erik Hahn; bug #214817
10
10
Lines 19-25 find_targets() { Link Here
19
			zsh \
19
			zsh \
20
			posh \
20
			posh \
21
		; do
21
		; do
22
		if [[ -x "${ROOT}"/bin/${t} ]]; then
22
		if [[ -x ${ROOT}/bin/${t} ]]; then
23
			echo ${t}
23
			echo ${t}
24
		fi
24
		fi
25
	done
25
	done
Lines 29-43 find_targets() { Link Here
29
set_symlinks() {
29
set_symlinks() {
30
	local target="${1}" targets
30
	local target="${1}" targets
31
31
32
	[[ ! -L "${ROOT}"/bin/sh && -e "${ROOT}"/bin/sh ]] && \
32
	[[ ! -L ${ROOT}/bin/sh && -e ${ROOT}/bin/sh ]] && \
33
		die -q "/bin/sh is not a symlink!"
33
		die -q "/bin/sh is not a symlink!"
34
34
35
	if is_number "${target}" && [[ ${target} -ge 1 ]]; then
35
	if is_number "${target}" && [[ ${target} -ge 1 ]]; then
36
		targets=( $(find_targets) )
36
		targets=( $(find_targets) )
37
		target=${targets[$(( ${target} - 1 ))]}
37
		target=${targets[target-1]}
38
	fi
38
	fi
39
39
40
	if [[ -x "${ROOT}"/bin/${target} ]]; then
40
	if [[ -x ${ROOT}/bin/${target} ]]; then
41
		local tmpf="${ROOT}"/bin/sh.new
41
		local tmpf="${ROOT}"/bin/sh.new
42
		# we could use 'ln -f' to directly replace the symlink
42
		# we could use 'ln -f' to directly replace the symlink
43
		# but 'mv' is an atomic operation so it should be more fault-proof
43
		# but 'mv' is an atomic operation so it should be more fault-proof
Lines 60-71 describe_show() { Link Here
60
}
60
}
61
61
62
do_show() {
62
do_show() {
63
	[[ -z "${@}" ]] || die -q "Too many parameters"
63
	[[ -z ${@} ]] || die -q "Too many parameters"
64
64
65
	write_list_start "Current POSIX shell implementation:"
65
	write_list_start "Current POSIX shell implementation:"
66
	if [[ -L "${ROOT}/bin/sh" ]]; then
66
	if [[ -L ${ROOT}/bin/sh ]]; then
67
		write_kv_list_entry "$(basename $(canonicalise ${ROOT}/bin/sh))" ""
67
		write_kv_list_entry "$(basename $(readlink ${ROOT}/bin/sh))" ""
68
	elif [[ -e "${ROOT}/bin/sh" ]]; then
68
	elif [[ -e ${ROOT}/bin/sh ]]; then
69
		write_kv_list_entry "(not a symlink)" ""
69
		write_kv_list_entry "(not a symlink)" ""
70
	else
70
	else
71
		write_kv_list_entry "(unset)" ""
71
		write_kv_list_entry "(unset)" ""
Lines 79-91 describe_list() { Link Here
79
}
79
}
80
80
81
do_list() {
81
do_list() {
82
	[[ -z "${@}" ]] || die -q "Too many parameters"
82
	[[ -z ${@} ]] || die -q "Too many parameters"
83
83
84
	local i targets
84
	local i targets
85
	targets=( $(find_targets) )
85
	targets=( $(find_targets) )
86
	if [[ -n ${targets[@]} ]]; then
86
	if [[ -n ${targets[@]} ]]; then
87
		for (( i = 0; i < ${#targets[@]}; i++ )) ; do
87
		for (( i = 0; i < ${#targets[@]}; i++ )) ; do
88
			[[ ${targets[${i}]} == $(basename $(canonicalise ${ROOT}/bin/sh)) ]] && \
88
			[[ ${targets[${i}]} == $(basename $(readlink ${ROOT}/bin/sh)) ]] && \
89
				targets[${i}]="${targets[${i}]} $(highlight '*')"
89
				targets[${i}]="${targets[${i}]} $(highlight '*')"
90
		done
90
		done
91
		write_list_start "Available POSIX shell implementations:"
91
		write_list_start "Available POSIX shell implementations:"
Lines 110-118 describe_set_parameters() { Link Here
110
}
110
}
111
111
112
do_set() {
112
do_set() {
113
	if [[ -z "${1}" ]]; then
113
	if [[ -z ${1} ]]; then
114
		die -q "Not enough parameters"
114
		die -q "Not enough parameters"
115
	elif [[ -n "${2}" ]]; then
115
	elif [[ -n ${2} ]]; then
116
		die -q "Too many parameters"
116
		die -q "Too many parameters"
117
	else
117
	else
118
		set_symlinks "${1}"
118
		set_symlinks "${1}"
Lines 126-139 describe_update() { Link Here
126
}
126
}
127
127
128
describe_update_options() {
128
describe_update_options() {
129
	echo "--if-unset : Do not override existing implementation"
129
	echo "ifunset : Do not override existing implementation"
130
}
130
}
131
131
132
do_update() {
132
do_update() {
133
	[[ -z "${1}" || ( -z "${2}" && "${1}" == "--if-unset" ) ]] || \
133
	[[ -z ${1} || ( -z ${2} && ( ${1} == ifunset || ${1} == '--if-unset' ) ]] || \
134
		die -q "Usage error"
134
		die -q "Usage error"
135
135
136
	[[ "${1}" == "--if-unset" && -L "${ROOT}"/bin/sh && -x "${ROOT}"/bin/sh ]] && \
136
	[[ ( ${1} == ifunset || ${1} == '--if-unset' ) && -L ${ROOT}/bin/sh && -x ${ROOT}/bin/sh ]] && \
137
		return
137
		return
138
138
139
	set_symlinks 1
139
	set_symlinks 1

Return to bug 214817