# -*-eselect-*- vim: ft=eselect # Copyright 2005-2014 Gentoo Foundation # Distributed under the terms of the GNU GPL version 2 or later DESCRIPTION="Manage the /usr/bin/valac symlink" MAINTAINER="rastersoft@gmail.com" # sort function for vala versions, to be used in a pipe sort_kernel_versions() { local vsort="sort --version-sort" # Test if our sort supports the --version-sort option # (should be GNU sort, since the kernel module is GNU/Linux specific) ${vsort} /dev/null || vsort=sort # We sort vala versions as follows: # 1. Run sed to prepend the version string by the numeric version # and an additional rank indicator that is 0 for release candidates # or 1 otherwise. After this step we have, for example: # 2.6.29 1 valac-0.22 # 2.6.29 0 valac-0.22-rc2 # 2. sort --version-sort # 3. Run sed again to remove the prepended keys from step 1. sed -e 's/^\(valac-\)\?\([[:digit:].]\+\)[-_]rc/\2 0 &/' \ -e 't;s/^\(valac-\)\?\([[:digit:].]\+\)/\2 1 &/' \ | LC_ALL=C ${vsort} | sed 's/.* //' } # find a list of vala symlink targets find_targets() { local f for f in "${EROOT}"/usr/bin/valac-[[:digit:]]*\.[[:digit:]]*; do basename "${f}" | sed 's/valac-//' done } # remove the vala symlink remove_symlink() { rm "${EROOT}/usr/bin/valac" rm -f "${EROOT}/usr/bin/vala" rm -f "${EROOT}/usr/bin/vala-gen-introspect" rm -f "${EROOT}/usr/bin/vapigen" rm -f "${EROOT}/usr/bin/vapicheck" } # set the vala symlink set_symlink() { local target=$1 if is_number "${target}"; then local targets=( $(find_targets) ) target=${targets[target-1]} fi if [[ -z "valac-${target}" ]]; then die -q "Target \"$1\" doesn't appear to be valid!" elif [[ -f ${EROOT}/usr/bin/valac-${target} ]]; then ln -s "valac-${target}" "${EROOT}/usr/bin/valac" ln -s "valac-${target}" "${EROOT}/usr/bin/vala" ln -s "vala-gen-introspect-${target}" "${EROOT}/usr/bin/vala-gen-introspect" ln -s "vapigen-${target}" "${EROOT}/usr/bin/vapigen" ln -s "vapicheck-${target}" "${EROOT}/usr/bin/vapicheck" else die -q "Target \"$1\" doesn't appear to be valid!" fi } ### show action ### describe_show() { echo "Show the current vala symlink" } do_show() { write_list_start "Current vala symlink:" if [[ -L ${EROOT}/usr/bin/valac ]]; then local valac=$(canonicalise "${EROOT}/usr/bin/valac") write_kv_list_entry "${valac%/}" "" else write_kv_list_entry "(unset)" "" fi } ### list action ### describe_list() { echo "List available vala symlink targets" } do_list() { local i targets=( $(find_targets) ) write_list_start "Available vala symlink targets:" for (( i = 0; i < ${#targets[@]}; i++ )); do [[ ${targets[i]} = \ $(basename "$(canonicalise "${EROOT}/usr/bin/valac")" | sed 's/valac-//') ]] \ && targets[i]=$(highlight_marker "${targets[i]}") done write_numbered_list -m "(none found)" "${targets[@]}" } ### set action ### describe_set() { echo "Set a new vala 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" if [[ -L ${EROOT}/usr/bin/valac ]]; then # existing symlink remove_symlink || die -q "Couldn't remove existing symlink" set_symlink "$1" || die -q "Couldn't set a new symlink" elif [[ -e ${EROOT}/usr/bin/valac ]]; then # we have something strange die -q "${EROOT}/usr/bin/valac exists but is not a symlink" else set_symlink "$1" || die -q "Couldn't set a new symlink" fi }