-
Notifications
You must be signed in to change notification settings - Fork 0
/
vala.eselect.m4
118 lines (95 loc) · 2.61 KB
/
vala.eselect.m4
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
# -*-eselect-*- vim: ft=eselect
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: $
DESCRIPTION="Manage what version of Vala to be used by default"
MAINTAINER="Gavrilov Maksim <ulltor@gmail.com>"
VERSION=PV # set by m4 from Makefile
# Tools to manage symlinks to
TOOLS="vala valac vala-gen-introspect vapigen"
# Find a list of valac symlink targets
find_targets() {
local f
for f in "${EROOT}"/usr/bin/valac-[[:digit:]]* ; do
[[ -f ${f} ]] && basename "${f}"
done
}
# Remove symlink
remove_symlink() {
local tool=${1}
rm "${EROOT}/usr/bin/${tool}"
}
# Set symlink
set_symlink() {
local tool=${1}
local target=${2}
if is_number "${target}" ; then
local targets=( $(find_targets) )
target=${targets[target - 1]}
fi
# Extract version number from whole string
# Ex.: '0.12' from 'vala-0.12'
target=${target##*-}
if [[ -z ${target} ]] ; then
die -q "Target \"${1}\" doesn't appear to be valid!"
elif [[ -f ${EROOT}/usr/bin/${tool}-${target} ]] ; then
ln -s "${EROOT}/usr/bin/${tool}-${target}" "${EROOT}/usr/bin/${tool}"
else
die -q "Target \"$1\" doesn't appear to be valid!"
fi
}
### show action ###
describe_show() {
echo "Show active valac version"
}
do_show() {
write_list_start "Active valac version:"
if [[ -L ${EROOT}/usr/bin/valac ]] ; then
local version=$(canonicalise "${EROOT}/usr/bin/valac")
write_kv_list_entry "${version%/}" ""
else
write_kv_list_entry "(unset)" ""
fi
}
### list action ###
describe_list() {
echo "List available valac versions"
}
do_list() {
local i targets=( $(find_targets) )
write_list_start "Available valac versions:"
for (( i = 0; i < ${#targets[@]}; i++ )) ; do
[[ ${targets[i]} = \
$(basename "$(canonicalise "${EROOT}/usr/bin/valac")") ]] \
&& targets[i]=$(highlight_marker "${targets[i]}")
done
write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###
describe_set() {
echo "Set an active version of valac"
}
describe_set_parameters() {
echo "<target>"
}
describe_set_options() {
echo "target : Target name, vesion or number (from 'list' action)"
}
do_set() {
if [[ -z ${1} ]] ; then
# no parameter
die -q "You didn't tell me what version to use"
else
for tool in ${TOOLS}; do
if [[ -L ${EROOT}/usr/bin/${tool} ]]; then
if ! remove_symlink ${tool} ; then
die -q "Couldn't remove existing symlinks"
fi
elif [[ -e ${EROOT}/usr/bin/${tool} ]] ; then
# we have something strange
die -q "${EROOT}/usr/bin/${tool} exists but is not a symlink"
fi
set_symlink ${tool} ${1} || die -q "Couldn't set new symlinks"
done
fi
}