Gentoo Archives: gentoo-commits

From: "Jonathan Callen (abcd)" <abcd@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-admin/eselect-unison/files: unison.eselect-0.3
Date: Sun, 28 Feb 2010 20:39:58
Message-Id: E1Nlpvf-0004bj-OG@stork.gentoo.org
1 abcd 10/02/28 20:39:55
2
3 Added: unison.eselect-0.3
4 Log:
5 Version bump to add prefix support
6 (Portage version: -svn/cvs/Linux i686)
7
8 Revision Changes Path
9 1.1 app-admin/eselect-unison/files/unison.eselect-0.3
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-unison/files/unison.eselect-0.3?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-unison/files/unison.eselect-0.3?rev=1.1&content-type=text/plain
13
14 Index: unison.eselect-0.3
15 ===================================================================
16 # -*-eselect-*- vim: ft=eselect
17 # Copyright 1999-2010 Gentoo Foundation
18 # Distributed under the terms of the GNU General Public License v2
19 # $Header: /var/cvsroot/gentoo-x86/app-admin/eselect-unison/files/unison.eselect-0.3,v 1.1 2010/02/28 20:39:55 abcd Exp $
20
21 DESCRIPTION="Manage /usr/bin/unison versions"
22 MAINTAINER="ml@g.o"
23 VERSION="0.3"
24
25 # find a list of unison symlink targets, best first
26 find_targets() {
27 local f
28 for f in "${EROOT}"/usr/bin/unison-[0-9]*; do
29 if [[ -f ${f} ]] ; then
30 echo "${f##*/unison-}"
31 fi
32 done | tac
33 }
34
35 # find version number of currently symlinked version
36 identify_target() {
37 local f
38 f="$(canonicalise "${EROOT}"/usr/bin/unison)"
39 echo "${f##*/unison-}"
40 }
41
42 # try to remove the unison symlink
43 remove_symlinks() {
44 rm -f "${EROOT}"/usr/bin/unison &>/dev/null
45 }
46
47 # set the unison 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 "${EROOT}/usr/bin/unison-${target}" ]] ; then
55 remove_symlinks
56 ln -s "unison-${target}" "${EROOT}/usr/bin/unison" || \
57 die "Could not set ${target} /usr/bin/unison symlink"
58 else
59 die -q "Target \"${target}\" doesn't appear to be valid!"
60 fi
61 }
62
63 ### show action ###
64
65 describe_show() {
66 echo "Show the current unison version"
67 }
68
69 do_show() {
70 [[ -z "${@}" ]] || die -q "Too many parameters"
71
72 write_list_start "Current unison verson:"
73 if [[ -L "${EROOT}/usr/bin/unison" ]] ; then
74 write_kv_list_entry "$(identify_target)" ""
75 elif [[ -e "${EROOT}/usr/bin/unison" ]] ; then
76 write_kv_list_entry "(not a symlink)" ""
77 else
78 write_kv_list_entry "(unset)" ""
79 fi
80 }
81
82 ### list action ###
83
84 describe_list() {
85 echo "List available unison versions"
86 }
87
88 do_list() {
89 [[ $# -eq 0 ]] || die -q "Too many parameters"
90
91 local i targets current
92 targets=( $(find_targets ) )
93 current=$(identify_target)
94 for (( i = 0; i < ${#targets[@]}; i++ )); do
95 [[ ${targets[i]} = ${current} ]] \
96 && targets[i]=$(highlight_marker "${targets[i]}")
97 done
98 write_list_start "Available unison versions:"
99 write_numbered_list -m "(none found)" "${targets[@]}"
100 }
101
102 ### set action ###
103
104 describe_set() {
105 echo "Set a new unison version"
106 }
107
108 describe_set_options() {
109 echo "target : Target version number or index from 'list' action"
110 }
111
112 describe_set_parameters() {
113 echo "<target>"
114 }
115
116 do_set() {
117 if [[ -z "${1}" ]] ; then
118 die -q "You didn't give me a version number"
119
120 elif [[ -n "${2}" ]] ; then
121 die -q "Too many parameters"
122
123 elif [[ -L "${EROOT}/usr/bin/unison" ]] ; then
124 if ! remove_symlinks ; then
125 die -q "Can't remove existing version symlink"
126 elif ! set_symlinks "${1}" ; then
127 die -q "Can't set new version"
128 fi
129
130 elif [[ -e "${EROOT}/usr/bin/unison" ]] ; then
131 die -q "${EROOT}/usr/bin/unison seems to be from an old ebuild, please remove manually"
132
133 else
134 set_symlinks "${1}" || die -q "Can't set new version"
135 fi
136 }
137
138 ### update action ###
139
140 describe_update() {
141 echo "Automatically update the unison version number"
142 }
143
144 describe_update_options() {
145 echo "--if-unset : Do not override currently selected version"
146 }
147
148 do_update() {
149 [[ -z "${1}" ]] || ( [[ -z "${2}" ]] && [[ "${1}" == "--if-unset" ]] ) || \
150 die -q "Usage error"
151
152 if [[ -L "${EROOT}/usr/bin/unison" ]] ; then
153 [[ ${1} == "--if-unset" ]] && return
154 remove_symlinks || die -q "Can't remove existing symlink"
155 fi
156 if [[ -e "${EROOT}/usr/bin/unison" ]] ; then
157 die -q "${EROOT}/usr/bin/unison seems to be from an old ebuild, please remove manually"
158 elif ! [[ -z $(find_targets ) ]] ; then
159 set_symlinks 1 || die -q "Can't set a new version"
160 fi
161 }