# -*-eselect-*- vim: ft=eselect # Copyright 1999-2015 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 or later # $Id: $ DESCRIPTION="Manage the /usr/bin/SmackBot symlink" MAINTAINER="flo@geekplace.eu" VERSION=0.1 # find a list of SmackBot symlink targets find_targets() { local f for f in "${EROOT}"/usr/bin/smackbot?(-bin)-[[:digit:]]*; do [[ -x ${f} ]] && basename "${f}" done } remove_symlink() { rm "${EROOT}/usr/bin/smackbot" \ || die -q "Could not remove symlink" } set_symlink() { local target=$1 if is_number "${target}"; then local targets=( $(find_targets) ) target=${targets[target-1]} fi [[ -z ${target} ]] \ && die -q "Target \"${1}\" doesn't apper to be valid!" [[ ! -x ${EROOT}/usr/bin/${target} ]] \ && die -q "${EROOT}/usr/bin/${target} is not an executable" ln -s "${target}" "${EROOT}/usr/bin/smackbot" \ || die -q "Could not set symlink" } describe_show() { echo "Shows the current smackbot symlink" } do_show() { write_list_start "Current smackbot symlink:" if [[ -L ${EROOT}/usr/bin/smackbot ]]; then local smackbot=$(cannonicalise "${EROOT}/usr/bin/smackbot") write_kv_list_entry "${smackbot}" "" else write_kv_list_entry "(unset)" "" fi } describe_list() { echo "list available smackbot symlink targets" } do_list() { local i targets=( $(find_targets) ) write_list_start "Available smackbot symlink targets:" for (( i = 0; i < ${#targets[@]}; i++ )); do # highligh the target where the symlink is pointing to [[ ${targets[i]} = \ $(basename "$(canonicalise "${EROOT}/usr/bin/smackbot")") ]] \ && targets[i]=$(highlight_marker "${targets[i]}") done write_numbered_list -m "(none found)" "${targets[@]}" } describe_set() { echo "Set a new smackbot symlink target" } describe_set_parameters() { echo "" } describe_set_options() { echo "target : Target name or number (from 'list' action)" } do_set() { [[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to" [[ $# -gt 1 ]] && die -q "Too many parameters" test_for_root if [[ -L ${EROOT}/usr/bin/smackbot ]]; then # existing symmlink remove_symlink set_symlink "$1" elif [[ -e ${EROOT}/usr/bin/smackbot ]]; then # we have someting strange die -q "${EROOT}/usr/bin/smackbot exists but is not a symlink" else set_symlink "$1" fi } describe_update() { echo "Automatically update the smackbot symlink" } describe_update_options() { echo "ifunset: Do not override currently set version" } do_update() { [[ -z $1 || $1 == ifunset ]] || die -q "Usage error" [[ $# -gt 1 ]] && die -q "Too many parameters" test_for_root if [[ -L ${EROOT}/usr/bin/smackbot ]]; then if [[ $1 == ifunset && -e ${EROOT}/usr/bin/smackbot ]]; then return fi remove_symlink elif [[ -e ${EROOT}/usr/bin/smackbot ]]; then die -q "${EROOT}/usr/bin/smackbot exists but is not a symlink" fi local targets=( $(find_targets) ) if [[ ${#targets[@]} -gt 0 ]]; then set_symlink "${targets[${#targets[@]}-1]}" fi } test_for_root() { [[ -w ${EROOT}/usr/bin ]] || die -q "${EROOT}/usr/bin not writeable by current user. Are you root?" }