Gentoo Archives: gentoo-commits

From: "Alexis Ballier (aballier)" <aballier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-admin/eselect-mpost/files: mpost.eselect-0.1
Date: Tue, 09 Sep 2008 16:46:34
Message-Id: E1Kd6MJ-0003vp-Ke@stork.gentoo.org
1 aballier 08/09/09 16:46:31
2
3 Added: mpost.eselect-0.1
4 Log:
5 Initial import: manages /usr/bin/mpost symlinks to allow easy usage of mplib's mpost.
6 (Portage version: 2.2_rc8/cvs/Linux 2.6.26.3 x86_64)
7
8 Revision Changes Path
9 1.1 app-admin/eselect-mpost/files/mpost.eselect-0.1
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-mpost/files/mpost.eselect-0.1?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-mpost/files/mpost.eselect-0.1?rev=1.1&content-type=text/plain
13
14 Index: mpost.eselect-0.1
15 ===================================================================
16 # Copyright 1999-2007 Gentoo Foundation
17 # Distributed under the terms of the GNU General Public License v2
18 # $Id: mpost.eselect-0.1,v 1.1 2008/09/09 16:46:31 aballier Exp $
19
20 DESCRIPTION="Manage /usr/bin/mpost implementations"
21 MAINTAINER="ml@g.o"
22 SVN_DATE='$Date: 2008/09/09 16:46:31 $'
23 VERSION=$(svn_date_to_version "${SVN_DATE}" )
24
25 # find a list of mpost symlink targets, best first
26 find_targets() {
27 local f
28 for f in "${ROOT}"/usr/bin/mpost-*; do
29 if [[ -f ${f} ]] ; then
30 echo "${f##*/mpost-}"
31 fi
32 done | sort
33 }
34
35 # find version number of currently symlinked version
36 identify_target() {
37 local f
38 f="$(canonicalise "${ROOT}"/usr/bin/mpost)"
39 echo "${f##*/mpost-}"
40 }
41
42 # try to remove the mpost symlink
43 remove_symlinks() {
44 rm -f "${ROOT}"/usr/bin/mpost &>/dev/null
45 }
46
47 # set the mpost symlink
48 set_symlinks() {
49 local target="${1}" targets
50 if is_number "${target}" && [[ ${target} -ge 1 ]] ; then
51 targets=( $(find_targets ) )
52 target=${targets[$(( ${target} - 1 ))]}
53 fi
54 if [[ -f "${ROOT}/usr/bin/mpost-${target}" ]] ; then
55 remove_symlinks
56 ln -s "mpost-${target}" "${ROOT}/usr/bin/mpost" || \
57 die "Could not set ${target} /usr/bin/mpost symlink"
58 echo "Updating TeX formats"
59 [ -z "${ROOT}" ] && fmtutil-sys --all &>/dev/null || write_warning_msg "Could not update TeX formats for some reason, mpost may not work properly."
60 else
61 die -q "Target \"${target}\" doesn't appear to be valid!"
62 fi
63 }
64
65 ### show action ###
66
67 describe_show() {
68 echo "Show the current mpost version"
69 }
70
71 do_show() {
72 [[ -z "${@}" ]] || die -q "Too many parameters"
73
74 write_list_start "Current mpost verson:"
75 if [[ -L "${ROOT}/usr/bin/mpost" ]] ; then
76 write_kv_list_entry "$(identify_target)" ""
77 elif [[ -e "${ROOT}/usr/bin/mpost" ]] ; then
78 write_kv_list_entry "(not a symlink)" ""
79 else
80 write_kv_list_entry "(unset)" ""
81 fi
82 }
83
84 ### list action ###
85
86 describe_list() {
87 echo "List available mpost versions"
88 }
89
90 do_list() {
91 [[ -z "${@}" ]] || die -q "Too many parameters"
92
93 local i targets current
94 targets=( $(find_targets ) )
95 current=$(identify_target)
96 if [[ -n ${targets[@]} ]] ; then
97 for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do
98 [[ ${targets[${i}]} == ${current} ]] && \
99 targets[${i}]="${targets[${i}]} $(highlight '*' )"
100 done
101 write_list_start "Available mpost versions:"
102 write_numbered_list "${targets[@]}"
103 else
104 write_kv_list_entry "(none found)" ""
105 fi
106 }
107
108 ### set action ###
109
110 describe_set() {
111 echo "Set a new mpost version"
112 }
113
114 describe_set_options() {
115 echo "target : Target version number or index from 'list' action"
116 }
117
118 describe_set_parameters() {
119 echo "<target>"
120 }
121
122 do_set() {
123 if [[ -z "${1}" ]] ; then
124 die -q "You didn't give me a version number"
125
126 elif [[ -n "${2}" ]] ; then
127 die -q "Too many parameters"
128
129 elif [[ -L "${ROOT}/usr/bin/mpost" ]] ; then
130 if ! remove_symlinks ; then
131 die -q "Can't remove existing version symlink"
132 elif ! set_symlinks "${1}" ; then
133 die -q "Can't set new version"
134 fi
135
136 elif [[ -e "${ROOT}/usr/bin/mpost" ]] ; then
137 die -q "${ROOT}/usr/bin/mpost seems to be from an old ebuild, please remove manually"
138 else
139 set_symlinks "${1}" || die -q "Can't set new version"
140 fi
141 }
142
143 ### update action ###
144
145 describe_update() {
146 echo "Automatically update the mpost version number"
147 }
148
149 describe_update_options() {
150 echo "--if-unset : Do not override currently selected version"
151 }
152
153 do_update() {
154 [[ -z "${1}" ]] || ( [[ -z "${2}" ]] && [[ "${1}" == "--if-unset" ]] ) || \
155 die -q "Usage error"
156
157 if [[ -L "${ROOT}/usr/bin/mpost" ]] ; then
158 [[ ${1} == "--if-unset" ]] && return
159 remove_symlinks || die -q "Can't remove existing symlink"
160 fi
161 if [[ -e "${ROOT}/usr/bin/mpost" ]] ; then
162 die -q "${ROOT}/usr/bin/mpost seems to be from an old ebuild, please remove manually"
163 elif ! [[ -z $(find_targets ) ]] ; then
164 set_symlinks 1 || die -q "Can't set a new version"
165 fi
166 }
167
168 # vim: set ft=eselect :