diff options
author | Christoph Junghans <ottxor@gentoo.org> | 2012-06-04 20:06:02 +0100 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2022-10-10 20:06:07 +0100 |
commit | 098d7b1efee0412674d454bcf06c07a8d348d53d (patch) | |
tree | 1c2b75a21683453887cd058d69c05b919d9135ae | |
download | eselect-awk-098d7b1efee0412674d454bcf06c07a8d348d53d.tar.gz eselect-awk-098d7b1efee0412674d454bcf06c07a8d348d53d.tar.bz2 eselect-awk-098d7b1efee0412674d454bcf06c07a8d348d53d.zip |
awk.eselect: initial commit (0.2)0.2
Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r-- | awk.eselect | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/awk.eselect b/awk.eselect new file mode 100644 index 0000000..d4ee5cf --- /dev/null +++ b/awk.eselect @@ -0,0 +1,159 @@ +# Copyright 1999-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: $ + +DESCRIPTION="Manage {,/usr}/bin/awk implementations" +MAINTAINER="ottxor@gentoo.org" +VERSION="0.2" + +## Functions ## + +# find a list of awk symlink targets, best first +find_targets() { + local t + for t in \ + "${EROOT}/usr/bin/gawk" \ + "${EROOT}/usr/bin/mawk" \ + "${EROOT}/usr/bin/nawk" \ + "${EROOT}/bin/busybox" \ + ; do + if [[ -x ${t} ]]; then + echo ${t##*/} + fi + done +} + +# set the awk symlink +set_symlinks() { + local target=${1} targets extension dir i rel_target + + [[ ! -L ${EROOT}/bin/awk && -e ${EROOT}/bin/awk ]] && \ + die -q "/bin/awk is not a symlink!" + + [[ ! -L ${EROOT}/usr/bin/awk && -e ${EROOT}/usr/bin/awk ]] && \ + die -q "/usr/bin/awk is not a symlink!" + + if is_number "${target}" && [[ ${target} -ge 1 ]]; then + targets=( $(find_targets) ) + target=${targets[target-1]} + fi + + if [[ ${target} == "busybox" ]]; then + dir="${EROOT}/bin" + else + dir="${EROOT}/usr/bin" + fi + + [[ -x ${dir}/${target} ]] || die -q "Target '${target}' doesn't appear to be valid!" + + for i in /bin /usr/bin; do + rel_target=$(relative_name "${dir}/${target}" "${EROOT}${i}") + ln -sf "${rel_target}" "${EROOT}${i}/awk" || \ + die -q "Couldn't set ${target} ${i}/awk symlink" + done + + rm -f "${EROOT}"/usr/share/man/man1/awk.1{,.bz2,.gz,lzma} + for x in ".1" ".1.bz2" ".1.gz" ".1.lzma" ; do + if [[ -e ${EROOT}/usr/share/man/man1/${target}${x} ]] ; then + extension="${x}" + break + fi + done + + #busybox has no man page + if [[ -z "${extension}" ]] ; then + echo "Couldn't find a man page for ${target}; skipping." 1>&2 + return 1 + fi + + if ! ln -s "${target}${extension}" "${EROOT}/usr/share/man/man1/awk${extension}"; then + echo "Couldn't create man page symlink for ${target}; skipping." 1>&2 + return 1 + fi +} + +### show action ### + +describe_show() { + echo "Show the current awk implementation" +} + +do_show() { + [[ -z ${@} ]] || die -q "Too many parameters" + + write_list_start "Current awk implementation:" + if [[ -L ${EROOT}/usr/bin/awk ]]; then + write_kv_list_entry "$(basename $(readlink ${ROOT}/usr/bin/awk))" "" + elif [[ -e ${EROOT}/usr/bin/awk ]]; then + write_kv_list_entry "(not a symlink)" "" + else + write_kv_list_entry "(unset)" "" + fi +} + +### list action ### + +describe_list() { + echo "List available awk implementations" +} + +do_list() { + [[ -z ${@} ]] || die -q "Too many parameters" + + local i targets + + targets=( $(find_targets) ) + for (( i = 0; i < ${#targets[@]}; i++ )) ; do + [[ ${targets[${i}]} == $(basename $(readlink "${EROOT}"/usr/bin/awk)) ]] && \ + targets[${i}]=$(highlight_marker "${targets[${i}]}") + done + write_list_start "Available awk implementations:" + write_numbered_list -m '(none found)' "${targets[@]}" +} + +### set action ### + +describe_set() { + echo "Set a new awk implementation" +} + +describe_set_options() { + echo "target : Target name or number (from 'list' action)" +} + +describe_set_parameters() { + echo "<target>" +} + +do_set() { + if [[ -z ${1} ]]; then + die -q "Not enough parameters" + elif [[ -n ${2} ]]; then + die -q "Too many parameters" + else + set_symlinks "${1}" + fi +} + +### update action ### + +describe_update() { + echo "Automatically update the awk implementation" +} + +describe_update_options() { + echo "ifunset : Do not override existing implementation" +} + +do_update() { + [[ -z ${1} || ( -z ${2} && ( ${1} == ifunset || ${1} == '--if-unset' ) ) ]] || \ + die -q "Usage error" + + [[ ( ${1} == ifunset || ${1} == '--if-unset' ) \ + && -L ${EROOT}/usr/bin/awk && -x ${EROOT}/usr/bin/awk ]] && \ + return + + set_symlinks 1 +} + +# vim: set syn=sh : |