Gentoo Archives: gentoo-commits

From: Aaron Swenson <titanofold@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/pgsql-patches:eselect commit in: /
Date: Tue, 29 Mar 2011 19:35:22
Message-Id: 954bb1574c657e05084c7d3f58f6d5eae1ba2244.titanofold@gentoo
1 commit: 954bb1574c657e05084c7d3f58f6d5eae1ba2244
2 Author: Aaron W. Swenson <titanofold <AT> gentoo <DOT> org>
3 AuthorDate: Tue Mar 29 17:52:15 2011 +0000
4 Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org>
5 CommitDate: Tue Mar 29 17:52:15 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pgsql-patches.git;a=commit;h=954bb157
7
8 Switched from 'ls' to 'find'. Addressed issues from
9 http://archives.gentoo.org/gentoo-dev/msg_5825580bbfa5b8b2f6dab9faa880ddd3.xml
10
11 ---
12 postgresql.eselect | 124 +++++++++++++++++++++++++++++++---------------------
13 1 files changed, 74 insertions(+), 50 deletions(-)
14
15 diff --git a/postgresql.eselect b/postgresql.eselect
16 index 9a7e0c5..211dbc5 100644
17 --- a/postgresql.eselect
18 +++ b/postgresql.eselect
19 @@ -2,48 +2,59 @@
20 # Distributed under the terms of the GNU General Public License v2
21 # $Id: $
22
23 -inherit config multilib output package-manager path-manipulation
24 +inherit config multilib
25
26 DESCRIPTION="Manage active PostgreSQL client applications and libraries"
27 MAINTAINER="pgsql-bugs@g.o"
28 SVN_DATE='$Date: $'
29 -VERSION="1.0.4"
30 +VERSION="1.0.5"
31
32 # Global Data
33 B_PATH="${EROOT%/}/usr"
34 E_PATH="${EROOT%/}/etc/eselect/postgresql"
35 ENV_FILE="${EROOT%/}/etc/env.d/50postgresql"
36 -if [ -r ${E_PATH}/active -a -n ${E_PATH}/active ] ; then
37 - ACTIVE_SLOT=$(<${E_PATH}/active)
38 -else
39 - ACTIVE_SLOT="(none)"
40 -fi
41 -LIB_LIST=$(list_libdirs)
42 -if [[ ${LIB_LIST} =~ .*lib64.* && "$(ls -d ${B_PATH}/lib64/postgresql-*/lib)" != "" ]] ; then
43 - LIBDIR="lib64"
44 -elif [[ ${LIB_LIST} =~ .*lib32.* && "$(ls -d ${B_PATH}/lib32/postgresql-*/lib)" != "" ]] ; then
45 - LIBDIR="lib32"
46 -else
47 - LIBDIR="lib"
48 -fi
49 +
50 +active_slot() {
51 + if [[ -r ${E_PATH}/active && -n ${E_PATH}/active ]] ; then
52 + echo $( <${E_PATH}/active )
53 + else
54 + echo "(none)"
55 + fi
56 +}
57 +
58 +lib_dir() {
59 + local lib_list=$(list_libdirs)
60 + if [[ ${lib_list} =~ .*lib64.* && \
61 + "$(ls -d ${B_PATH}/lib64/postgresql-*/lib)" != "" ]] ; then
62 + echo "lib64"
63 + elif [[ ${lib_list} =~ .*lib32.* && \
64 + "$(ls -d ${B_PATH}/lib32/postgresql-*/lib)" != "" ]] ; then
65 + echo "lib32"
66 + else
67 + echo "lib"
68 + fi
69 +}
70
71 ### Linker Function ###
72 # Takes three arguments:
73 -# - Full source path (e.g. /usr/lib/postgresql-9.0/lib/lib*.{a,so})
74 +# - Full source path (e.g. /usr/lib/postgresql-9.0/lib)
75 +# _ Pattern to search for
76 # - Full target directory path (e.g. /usr/bin)
77 # - Suffix (Optional) (e.g 84 to make /usr/bin/psql84)
78 linker() {
79 local source_dir=$1
80 - local target_dir=$2
81 - local suffix=$3
82 + local pattern=$2
83 + local target_dir=$3
84 + local suffix=$4
85 local link_source
86
87 - for link_source in $(eval ls ${source_dir} 2> /dev/null) ; do
88 + for link_source in $(find ${source_dir} -maxdepth 1 ${pattern}) ; do
89 local link_target="${target_dir%/}/$(basename ${link_source})${suffix}"
90
91 # For good measure, remove target before creating the symlink
92 - [ -h ${link_target} ] && rm -f ${link_target}
93 - [ -e ${link_target} ] && die -q "The target '${link_target}' still exists and could not be removed!"
94 + [[ -h ${link_target} ]] && rm -f ${link_target}
95 + [[ -e ${link_target} ]] && \
96 + die -q "The target '${link_target}' still exists and could not be removed!"
97
98 ln -s ${link_source} ${link_target} || die -q "Unable to create link!"
99 echo ${link_target} >> ${E_PATH}/active.links${suffix}
100 @@ -59,7 +70,8 @@ unlinker() {
101 local active_links=($(<${active_link_file}))
102 for (( i=0; $i < ${#active_links[@]}; i++ )) ; do
103 [ -h ${active_links[$i]} ] && rm -f ${active_links[$i]}
104 - [ -e ${active_links[$i]} ] && die -q "The target '${active_links[$i]}' still exists and could not be removed!"
105 + [ -e ${active_links[$i]} ] && \
106 + die -q "The target '${active_links[$i]}' still exists and could not be removed!"
107 done
108
109 rm -f ${active_link_file}
110 @@ -67,9 +79,9 @@ unlinker() {
111 }
112
113 ### Get Slots Function ###
114 -# Find all available slots in the preferred LIBDIR and return them.
115 +# Find all available slots in the preferred lib_dir() and return them.
116 get_slots() {
117 - echo $(ls -dv ${B_PATH}/${LIBDIR}/postgresql-* 2> /dev/null | sed -re 's#^.+-##')
118 + echo $(ls -dv ${B_PATH}/$(lib_dir)/postgresql-* 2> /dev/null | sed -re 's#^.+-##')
119 }
120
121 ### List Action ###
122 @@ -92,8 +104,10 @@ do_list() {
123 done
124
125 case "${slot}" in
126 - "${ACTIVE_SLOT}" ) write_kv_list_entry "$(highlight_marker ${slot})" "${postgres_ebuilds//postgresql-/}";;
127 - * ) write_kv_list_entry "${slot}" "${postgres_ebuilds//postgresql-/}";;
128 + "$(active_slot)" ) write_kv_list_entry \
129 + "$(highlight_marker ${slot})" "${postgres_ebuilds//postgresql-/}";;
130 + * ) write_kv_list_entry \
131 + "${slot}" "${postgres_ebuilds//postgresql-/}";;
132 esac
133 done
134
135 @@ -107,7 +121,7 @@ describe_show() {
136 }
137
138 do_show() {
139 - echo ${ACTIVE_SLOT}
140 + echo $(active_slot)
141 }
142
143 ### Show Service Action ###
144 @@ -127,7 +141,7 @@ describe_set() {
145
146 do_set() {
147 local SLOT=$1
148 - if [ ! -d ${B_PATH}/${LIBDIR}/postgresql-${SLOT} ] ; then
149 + if [ ! -d ${B_PATH}/$(lib_dir)/postgresql-${SLOT} ] ; then
150 die -q "Not a valid slot."
151 fi
152
153 @@ -161,7 +175,8 @@ do_set() {
154 rm -f ${targets[$i]}
155
156 # Check if link_target still exists
157 - [ -e ${targets[$i]} ] && die -q "The target '${targets[$i]}' exists and could not be removed!"
158 + [[ -e ${targets[$i]} ]] && \
159 + die -q "The target '${targets[$i]}' exists and could not be removed!"
160
161 ln -s ${sources[$i]} ${targets[$i]} || die -q "Unable to create link!"
162 echo ${targets[$i]} >> ${E_PATH}/active.links
163 @@ -169,19 +184,21 @@ do_set() {
164
165 # Link modules to /usr/lib{,lib32,lib64}/
166 local x
167 - for x in ${LIB_LIST} ; do
168 - if [ -d ${B_PATH}/${x}/postgresql-${SLOT}/${x} ] ; then
169 + for x in $(list_libdirs) ; do
170 + if [[ -d ${B_PATH}/${x}/postgresql-${SLOT}/${x} ]] ; then
171 # 'linker' function doesn't work for linking directories.
172 # Default lib path
173 ln -s ${B_PATH}/${x}/postgresql-${SLOT}/${x} ${B_PATH}/${x}/postgresql
174 echo ${B_PATH}/${x}/postgresql >> ${E_PATH}/active.links
175 # Linker works for files
176 - linker "${B_PATH}/${x}/postgresql-${SLOT}/${x}/lib*.{a,dylib,so}" "${B_PATH}/${x}"
177 + linker "${B_PATH}/${x}/postgresql-${SLOT}/${x}" \
178 + "-name lib*[a|dylib|so]" "${B_PATH}/${x}"
179 fi
180 done
181
182 # Link binaries to /usr/bin/
183 - linker "${B_PATH}/${LIBDIR}/postgresql-${SLOT}/bin/*" "${B_PATH}/bin"
184 + linker "${B_PATH}/$(lib_dir)/postgresql-${SLOT}/bin/" \
185 + "-xtype f" "${B_PATH}/bin"
186
187 # Default share path
188 ln -s ${B_PATH}/share/postgresql-${SLOT} ${B_PATH}/share/postgresql
189 @@ -189,7 +206,7 @@ do_set() {
190
191 echo ${SLOT} > ${E_PATH}/active
192 echo "done."
193 - echo -e "\033[1mSetting ${SLOT} as default was successful!\033[0m"
194 + echo "Setting ${SLOT} as default was successful!"
195 }
196
197 ### Unset Action ###
198 @@ -199,7 +216,7 @@ describe_unset() {
199
200 do_unset() {
201 local SLOT=$1
202 - if [ "${SLOT}" = "${ACTIVE_SLOT}" ] ; then
203 + if [[ "${SLOT}" = "$(active_slot)" ]] ; then
204 echo -n "Unsetting ${SLOT} as the default installation..."
205 unlinker ${E_PATH}/active.links
206 rm -f ${E_PATH}/active
207 @@ -215,9 +232,10 @@ describe_reset() {
208 }
209
210 do_reset() {
211 - [ "${ACTIVE_SLOT}" = "(none)" ] && die -q "No active slot to reset."
212 - do_unset ${ACTIVE_SLOT}
213 - do_set ${ACTIVE_SLOT}
214 + local SLOT=$(active_slot)
215 + [[ "${SLOT}" = "(none)" ]] && die -q "No active slot to reset."
216 + do_unset ${SLOT}
217 + do_set ${SLOT}
218 }
219
220 ### Update Action ###
221 @@ -226,20 +244,23 @@ describe_update() {
222 }
223
224 do_update() {
225 + local slot=$(active_slot)
226 # Check for files managed by postgresql.eselect before 1.0
227 - [ -h /etc/eselect/postgresql/active ] && ACTIVE_SLOT="$(basename $(canonicalise /etc/eselect/postgesql/active))"
228 + [[ -h /etc/eselect/postgresql/active ]] && \
229 + slot="$(basename $(canonicalise /etc/eselect/postgesql/active))"
230 # Remove service file outright.
231 - [ -h /etc/eselect/postgresql/service ] && rm -f /etc/eselect/postgresql/service
232 + [[ -h /etc/eselect/postgresql/service ]] && \
233 + rm -f /etc/eselect/postgresql/service
234
235 local slots=($(get_slots))
236 local index=${#slots[@]}
237
238 # In case all slots have been unmerged
239 - if [ ${index} -eq 0 ] ; then
240 + if [[ ${index} -eq 0 ]] ; then
241 write_warning_msg "No slots found!"
242 write_warning_msg "Removing files (Control-C to abort) in..."
243 local i=6
244 - while [ $[i--] -gt 0 ] ; do
245 + while [[ $[i--] -gt 0 ]] ; do
246 echo -n " $i"
247 sleep 1
248 done
249 @@ -254,7 +275,7 @@ do_update() {
250 fi
251
252 # Reset, otherwise set the highest slot available.
253 - if [[ ${slots[@]} =~ ${ACTIVE_SLOT} ]] ; then
254 + if [[ ${slots[@]} =~ ${slot} ]] ; then
255 do_reset
256 else
257 # best_version doesn't work here as pkg_postrm runs before the world
258 @@ -272,21 +293,24 @@ do_update() {
259 # Update paths to libs and docs
260 local ldpath
261 local x
262 - for x in ${LIB_LIST} ; do
263 - [ -h ${B_PATH}/${x}/postgresql ] && ldpath+="${B_PATH}/${x}/postgresql:"
264 + for x in $(list_libdirs) ; do
265 + [[ -h ${B_PATH}/${x}/postgresql ]] && \
266 + ldpath+="${B_PATH}/${x}/postgresql:"
267 done
268 ldpath="${ldpath%:}"
269 local manpath="${B_PATH}/share/postgresql/"
270 - while [ $[--index] -gt -1 ] ; do
271 + while [[ $[--index] -gt -1 ]] ; do
272 local curslot="${slots[$index]}"
273 - echo -n "Refreshing symbolic links for ${curslot} applications (like /usr/bin/psql${curslot//.})..."
274 + echo -n "Refreshing symbolic links for ${curslot} applications (like "
275 + echo -n "/usr/bin/psql${curslot//.})..."
276 for x in ${LIB_LIST} ; do
277 local lib_path="${B_PATH}/${x}/postgresql-${curslot}/${x}/"
278 - [ -d ${lib_path} ] && ldpath+=":${lib_path}"
279 + [[ -d ${lib_path} ]] && ldpath+=":${lib_path}"
280 done
281 local share_path="${B_PATH}/share/postgresql-${curslot}/"
282 - [ -d ${share_path} ] && manpath+=":${share_path}"
283 - linker "${B_PATH}/${LIBDIR}/postgresql-${curslot}/bin/*" "${B_PATH}/bin" "${curslot//.}"
284 + [[ -d ${share_path} ]] && manpath+=":${share_path}"
285 + linker "${B_PATH}/$(lib_dir)/postgresql-${curslot}/bin/" \
286 + "-xtype f" "${B_PATH}/bin" "${curslot//.}"
287 echo "done."
288 done