Gentoo Archives: gentoo-commits

From: Aaron Swenson <titanofold@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/postgresql/eselect:stateless commit in: /
Date: Sat, 04 Feb 2017 21:15:34
Message-Id: 1486242628.c92b58550953bdb5d82b1068bfb99225efd65e29.titanofold@gentoo
1 commit: c92b58550953bdb5d82b1068bfb99225efd65e29
2 Author: Aaron W. Swenson <aaron.w.swenson <AT> gmail <DOT> com>
3 AuthorDate: Sat Feb 4 21:10:28 2017 +0000
4 Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org>
5 CommitDate: Sat Feb 4 21:10:28 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/postgresql/eselect.git/commit/?id=c92b5855
7
8 Huge Changes
9
10 No longer use an environment file. All links are in locations that are
11 searched by default by man and pkgconfig.
12
13 Remove several files outright in /etc/eselect/postgresql as they’re
14 unnecessary.
15
16 Added linking for man pages and pkgconfig files.
17
18 Rename ${SLOT} to ${slot} as it isn’t a global variable.
19
20 Now compatible with the upcoming slot scheme where there is no
21 dot. (Release 10.0 is just 10.)
22
23 postgresql.eselect | 262 ++++++++++++++++++++++++++---------------------------
24 1 file changed, 129 insertions(+), 133 deletions(-)
25
26 diff --git a/postgresql.eselect b/postgresql.eselect
27 index 7ff9b83..b8ecbe1 100644
28 --- a/postgresql.eselect
29 +++ b/postgresql.eselect
30 @@ -1,4 +1,4 @@
31 -# Copyright 1999-2013 Gentoo Foundation
32 +# Copyright 1999-2017 Gentoo Foundation
33 # Distributed under the terms of the GNU General Public License v2
34 # $Id: $
35
36 @@ -6,12 +6,11 @@ inherit config multilib
37
38 DESCRIPTION="Manage active PostgreSQL client applications and libraries"
39 MAINTAINER="pgsql-bugs@g.o"
40 -VERSION="1.3"
41 +VERSION="2.0"
42
43 -# Global Data
44 +# We do a lot of things in /usr and it's a bit of a pain to write this
45 +# constantly.
46 USR_PATH="${EROOT%/}/usr"
47 -ETC_PATH="${EROOT%/}/etc/eselect/postgresql"
48 -ENV_FILE="${EROOT%/}/etc/env.d/50postgresql"
49
50 # This list of files/directories are the symbolic link targets that need to be
51 # created when a slot is set.
52 @@ -28,11 +27,11 @@ INCLUDE_TARGETS=(
53 )
54
55 active_slot() {
56 - # ${USR_PATH}/share/postgresql is a symlink. See if it's there, then
57 - # find out where it links to
58 + # ${USR_PATH}/share/postgresql is a symlink to the active
59 + # slot. See if it's there, then find out where it links to.
60 if [[ -h "${USR_PATH}/share/postgresql" ]] ; then
61 canonicalise "${USR_PATH}/share/postgresql" | \
62 - sed 's|.*postgresql-\([1-9][0-9.]*\)|\1|'
63 + sed -re 's#.*([1-9][0-9.]+)$#\1#'
64 else
65 echo "(none)"
66 fi
67 @@ -86,7 +85,7 @@ linker() {
68 local findings
69 local rel_source
70
71 - findings=$(finder "${source_dir}" ${pattern})
72 + findings=$(finder "${source_dir}" "${pattern}")
73
74 for link_source in ${findings} ; do
75 local link_target="${target_dir%/}/$(basename ${link_source})${suffix}"
76 @@ -109,9 +108,9 @@ get_slots() {
77 local slot
78 local found_slots
79
80 - for slot in $(find "${USR_PATH}/$(lib_dir)/" -maxdepth 1 -type d \
81 - -regex '.*/postgresql-[1-9][0-9]*\.*[0-9]*' | \
82 - sed -re 's#.*([1-9][0-9]*\.*[0-9]*)$#\1#' | sort -n)
83 + for slot in $(find "${USR_PATH}/$(lib_dir)/" \
84 + -mindepth 1 -maxdepth 1 -type d -name 'postgresql-*' | \
85 + sed -re 's#.*([1-9][0-9.]+)$#\1#' | sort -n)
86 do
87 # Check that pg_config exists for this slot, otherwise we have
88 # a false positive.
89 @@ -186,24 +185,21 @@ describe_set() {
90 }
91
92 do_set() {
93 - local SLOT=$1
94 + local slot=$1
95
96 - if [[ ! -d ${USR_PATH}/$(lib_dir)/postgresql-${SLOT} ]] ; then
97 + if [[ ! -d ${USR_PATH}/$(lib_dir)/postgresql-${slot} ]] ; then
98 die -q "Not a valid slot."
99 fi
100
101 # If there's an active slot, unset that one first
102 - if [[ "$(active_slot)" == "${SLOT}" ]] ; then
103 - echo $(highlight "No work to do.")
104 - echo "If you think the links need to be reset, use the reset action."
105 - return 0
106 - elif [[ "$(active_slot)" != "(none)" ]] ; then
107 - echo -ne "\tRemoving old links..."
108 - do_unset $(active_slot)
109 + local active_slot=$(active_slot)
110 + if [[ "${active_slot}" != "(none)" ]] ; then
111 + echo -ne "Unsetting ${active_slot} as default..."
112 + do_unset ${active_slot}
113 echo "done."
114 fi
115
116 - echo "Setting ${SLOT} as the default installation..."
117 + echo "Setting ${slot} as the default..."
118
119 echo -ne "\tGenerating new links..."
120 # Sources for header files
121 @@ -212,12 +208,12 @@ do_set() {
122 # If you change this list, you must change the INCLUDE_TARGETS list,
123 # too. And, they must be listed in the same order.
124 local include_sources=(
125 - "${USR_PATH}"/include/postgresql-${SLOT}
126 - "${USR_PATH}"/include/postgresql-${SLOT}/libpq-fe.h
127 - "${USR_PATH}"/include/postgresql-${SLOT}/pg_config_ext.h
128 - "${USR_PATH}"/include/postgresql-${SLOT}/pg_config_manual.h
129 - "${USR_PATH}"/include/postgresql-${SLOT}/libpq
130 - "${USR_PATH}"/include/postgresql-${SLOT}/postgres_ext.h
131 + "${USR_PATH}"/include/postgresql-${slot}
132 + "${USR_PATH}"/include/postgresql-${slot}/libpq-fe.h
133 + "${USR_PATH}"/include/postgresql-${slot}/pg_config_ext.h
134 + "${USR_PATH}"/include/postgresql-${slot}/pg_config_manual.h
135 + "${USR_PATH}"/include/postgresql-${slot}/libpq
136 + "${USR_PATH}"/include/postgresql-${slot}/postgres_ext.h
137 )
138
139 # The linker function cannot accommodate this special purpose.
140 @@ -227,38 +223,49 @@ do_set() {
141 # Some headers are present only in specific versions of PostgreSQL
142 [[ -e ${include_sources[$i]} ]] || continue
143
144 - # Create relative links so that they work both here and inside the new
145 + # Create relative links so that they work both here and inside a new
146 # root if $ROOT is not "/"
147 rel_source=$(relative_name "${include_sources[$i]}" "$(dirname "${INCLUDE_TARGETS[$i]}")")
148
149 ln -s "$rel_source" "${INCLUDE_TARGETS[$i]}" || \
150 - die -q "Unable to create link!"
151 + die -q "Unable to create link! $rel_source -> ${INCLUDE_TARGETS[$i]}"
152 done
153
154 # Link modules to /usr/lib{,32,64}/
155 local x
156 for x in $(list_libdirs) ; do
157 - if [[ -d ${USR_PATH}/${x}/postgresql-${SLOT}/${x} ]] ; then
158 + if [[ -d "${USR_PATH}/${x}/postgresql-${slot}/${x}" ]] ; then
159 # 'linker' function doesn't work for linking directories.
160 # Default lib path - create a relative link
161 - ln -s "postgresql-${SLOT}/${x}" "${USR_PATH}/${x}/postgresql"
162 + ln -s "postgresql-${slot}/${x}" "${USR_PATH}/${x}/postgresql"
163
164 # Linker works for files
165 - linker "${USR_PATH}/${x}/postgresql-${SLOT}/${x}/" \
166 + linker "${USR_PATH}/${x}/postgresql-${slot}/${x}/" \
167 "-name lib*" "${USR_PATH}/${x}"
168 fi
169 done
170
171 # Link binaries to /usr/bin/
172 - linker "${USR_PATH}/$(lib_dir)/postgresql-${SLOT}/bin/" \
173 - "-type f" "${USR_PATH}/bin"
174 + linker "${USR_PATH}/$(lib_dir)/postgresql-${slot}/bin/" \
175 + "" "${USR_PATH}/bin"
176 +
177 + # Link pkg-config metadata files
178 + linker "${USR_PATH}/$(lib_dir)/postgresql-${slot}/$(lib_dir)/pkgconfig/" \
179 + "" "${USR_PATH}/share/pkgconfig/"
180 +
181 + # Link man pages
182 + local mandir mansec
183 + for mandir in "${USR_PATH}"/share/postgresql-${slot}/man/man{1,3,7} ; do
184 + mansec=$(basename "${mandir}")
185 + linker "${mandir}" "" "${USR_PATH}/share/man/${mansec}"
186 + done
187
188 # Default share path - use a relative link here by just specifying the
189 # base name
190 - ln -s "postgresql-${SLOT}" "${USR_PATH}/share/postgresql"
191 + ln -s "postgresql-${slot}" "${USR_PATH}/share/postgresql"
192
193 echo "done."
194 - echo "Setting ${SLOT} as default was successful!"
195 + echo "Setting ${slot} as default was successful!"
196 }
197
198 ### Unset Action ###
199 @@ -268,35 +275,58 @@ describe_unset() {
200
201 # Undo everything done by do_set().
202 do_unset() {
203 - local SLOT=$1
204 - if [[ ${SLOT} != $(active_slot) ]] ; then
205 + local slot=$1
206 + if [[ ${slot} != $(active_slot) ]] ; then
207 echo "Slot already inactive; no work to do."
208 return 0
209 fi
210
211 - local l
212 - for l in ${INCLUDE_TARGETS[@]} "${USR_PATH}/share/postgresql" ; do
213 - [[ -h ${l} ]] && rm -f "${l}"
214 + # Start with some known locations that are, or will contain, symlinks.
215 + local paths=(
216 + "${INCLUDE_TARGETS[@]}"
217 + "${USR_PATH}"/share/man/man{1,3,7}
218 + "${USR_PATH}/share/postgresql"
219 + "${USR_PATH}/bin"
220 + "${USR_PATH}/share/pkgconfig"
221 + )
222
223 - # Check if include target still exists
224 - [[ -e ${l} ]] && \
225 - die -q "The target '${l}' exists and could not be removed!"
226 - done
227 + local lib
228 + for lib in $(list_libdirs) ; do
229 + # If $libdir is a symlink, it will point to a real lib directory that
230 + # will be or has been added in this loop.
231 + [[ -h "${USR_PATH}/${lib}" ]] && continue
232
233 - for l in $(find "${USR_PATH}/bin" -type l) ; do
234 - if [[ $(realpath ${l} | grep -c postgresql) -ge 1 ]] ; then
235 - rm "${l}"
236 + # If the $libdir/postgresql symlink exists, then there are certainly
237 + # others within that same directory that must be cleaned up.
238 + if [[ -h "${USR_PATH}/${lib}/postgresql" ]] ; then
239 + paths+=( "${USR_PATH}/${lib}" )
240 fi
241 done
242
243 - for x in $(list_libdirs) ; do
244 - if [[ -h "${USR_PATH}/${x}/postgresql" ]] ; then
245 - for l in $(find "${USR_PATH}/${x}" -type l) ; do
246 - if [[ $(realpath ${l} | grep -c postgresql) -ge 1 ]] ; then
247 - rm "${l}"
248 - fi
249 - done
250 + local l path
251 + for path in "${paths[@]}" ; do
252 + # If path is a link that belongs to the slot in question, it can be
253 + # removed without invoking find.
254 + if [[ -h "${path}" && \
255 + $(canonicalise "${path}") == *postgresql-${slot}* ]] ; then
256 + rm "${path}" || write_warning_msg "Couldn't remove: ${path}"
257 + continue
258 fi
259 +
260 + # If path is a real directory, symlinks need to be found within it.
261 + for l in $(find "${path}" -mindepth 1 -maxdepth 1 -type l) ; do
262 + # Skip the slot specific links (e.g., psql96) in /usr/bin and
263 + # /usr/share/man as they're managed by their ebuilds
264 + [[ ${l} == ${USR_PATH}/bin/*${slot/.} ]] && continue
265 + [[ ${l} == ${USR_PATH}/share/man/man?/*${slot/.}* ]] && continue
266 +
267 + # Get the file path that the link is pointing to. If it has the
268 + # string "postgresql-${slot}" somewhere in it, then it's a link that
269 + # needs to be removed.
270 + if [[ $(canonicalise "${l}") == *postgresql-${slot}* ]] ; then
271 + rm "${l}" || write_warning_msg "Couldn't remove: ${l}"
272 + fi
273 + done
274 done
275 }
276
277 @@ -306,10 +336,10 @@ describe_reset() {
278 }
279
280 do_reset() {
281 - local SLOT=$(active_slot)
282 - [[ ${SLOT} = "(none)" ]] && die -q "No active slot to reset."
283 - do_unset ${SLOT}
284 - do_set ${SLOT}
285 + local slot=$(active_slot)
286 + [[ ${slot} == "(none)" ]] && die -q "No active slot to reset."
287 + do_unset ${slot}
288 + do_set ${slot}
289 }
290
291 ### Update Action ###
292 @@ -318,99 +348,65 @@ describe_update() {
293 }
294
295 do_update() {
296 - local slot=$(active_slot)
297 -
298 - ## CLEAN UP ##
299 + ## ANTIQUITY CLEAN UP ##
300 #
301 # Older versions of this module generated state and environment files of
302 # some sort or another. They're useless now and are just a waste of space.
303 - # Remove environment files that have been generated by the ebuilds
304 - rm -f "${ENV_FILE}"-*
305
306 - if [[ -d ${ETC_PATH} ]] ; then
307 + # Environment files that have been generated by older ebuilds and
308 + # previous versions of this module serve no purpose now.
309 + rm -f "${EROOT%/}"/etc/env.d/50postgresql*
310 +
311 + local etc_path="${EROOT%/}/etc/eselect/postgresql"
312 + if [[ -d ${etc_path} ]] ; then
313 # Remove some files outright as they're entirely useless now.
314 - # ${ETC_PATH}/active: Contents was the active slot (e.g., 9.5)
315 - # ${ETC_PATH}/service: Told the initscript which slot to start
316 + # ${etc_path}/active: Contents was the active slot (e.g.,
317 + # 9.5), or it was a symlink to another file that was then
318 + # canonicalised and parsed to get the active slot
319 + # ${etc_path}/service: Told the initscript which slot to
320 + # start. We now have separate scripts for each slot
321 + # ${etc_path}/active.links*: Contained a list of symlinks
322 + # created. We now search the known directories for the
323 + # symlinks as only this module manage them.
324 local f
325 - for f in "${ETC_PATH}/active" "${ETC_PATH}/service" ; do
326 - [[ -e "${f}" ]] && rm -f "${f}"
327 - done
328 -
329 - local active_link_file
330 - for active_link_file in "${ETC_PATH}"/active.links* ; do
331 - local active_links=($(<"${active_link_file}"))
332 - for (( i=0; $i < ${#active_links[@]}; i++ )) ; do
333 - [[ -h "${ROOT%/}/${active_links[$i]}" ]] && \
334 - rm -f "${ROOT%/}/${active_links[$i]}"
335 - [[ -e "${ROOT%/}/${active_links[$i]}" ]] && \
336 - die -q "The target '${active_links[$i]}' still exists and could not be removed!"
337 - done
338 -
339 - rm "${active_link_file}" || \
340 - write_warning_msg "Can't remove '${active_link_file}'"
341 + for f in "${etc_path}"/active* "${etc_path}/service" ; do
342 + if [[ -e "${f}" ]] ; then
343 + rm "${f}" || write_warning_msg "Can't remove: '${f}'"
344 + fi
345 done
346
347 local unused_files
348 - unused_file=$(find "${ETC_PATH}" -type f -not -name '.keep*')
349 + unused_file=( $(find "${etc_path}" -type f -not -name '.keep*') )
350 if [[ -n "${unused_file[@]}" ]] ; then
351 write_warning_msg "You have unused files that should be removed:"
352 for f in ${unused_file[@]} ; do
353 write_warning_msg $f
354 done
355 else
356 - echo "It's should be safe for you to remove '${ETC_PATH}'"
357 + echo "It should be safe for you to remove '${etc_path}'"
358 fi
359 fi
360 + ## End Antiquity Clean Up
361
362 - ## End Clean Up
363 -
364 + local active_slot=$(active_slot)
365 local slots=($(get_slots))
366 - local index=${#slots[@]}
367 -
368 - if [[ ${index} -eq 0 ]] ; then
369 - write_warning_msg "No slots found!"
370 - rm -f "${ENV_FILE}"
371 - do_action env update &> /dev/null
372 - return 0
373 - fi
374
375 - # Reset, otherwise set the highest slot available.
376 - if [[ ${slots[@]} =~ ${slot} ]] ; then
377 - do_reset ${slot}
378 + if [[ ${slots[@]} =~ ${active_slot} ]] ; then
379 + # If active_slot is in the slots list, do a reset as the installation
380 + # may have changed.
381 + do_reset
382 + elif [[ ${#slots[@]} -ne 0 ]] ; then
383 + # If $slots is not empty but ${active_slot} is set, the active_slot
384 + # must have been unmerged and its links need to be cleaned before...
385 + [[ ${active_slot} != "(none)" ]] && do_unset ${active_slot}
386 +
387 + # Setting the highest slot available.
388 + do_set ${slots[-1]}
389 + elif [[ ${active_slot} != "(none)" ]] ; then
390 + # If slots is empty, but active_slot still has a value, an unset must
391 + # happen as the links are now pointing to nothing.
392 + do_unset ${active_slot}
393 else
394 - # best_version doesn't work here as pkg_postrm runs before the world
395 - # file is updated, thereby returning a false positive.
396 - do_set ${slots[$index-1]}
397 + echo "Apparently, I have nothing to do."
398 fi
399 -
400 - # Update paths to libs and man pages
401 - local ldpath
402 - local pcpath
403 - local x
404 - for x in $(list_libdirs) ; do
405 - if [[ -h ${USR_PATH}/${x}/postgresql ]] ; then
406 - ldpath+="${USR_PATH}/${x}/postgresql:"
407 - pcpath+="${USR_PATH}/${x}/postgresql/pkgconfig:"
408 - fi
409 - done
410 - ldpath="${ldpath%:}"
411 - pcdpath="${pcpath%:}"
412 - local manpath="${USR_PATH}/share/postgresql/man/"
413 - while [[ $[--index] -gt -1 ]] ; do
414 - local curslot="${slots[$index]}"
415 - for x in $(list_libdirs) ; do
416 - local lib_path="${USR_PATH}/${x}/postgresql-${curslot}/${x}/"
417 - local pkg_path="${lib_path}/pkgconfig"
418 - [[ -d ${lib_path} ]] && ldpath+=":${lib_path}"
419 - [[ -d ${pkg_path} ]] && pcpath+=":${pcpath}"
420 - done
421 - local tmp_manpath="${USR_PATH}/share/postgresql-${curslot}/man/"
422 - [[ -d ${tmp_manpath} ]] && manpath+=":${tmp_manpath}"
423 - echo "done."
424 - done
425 -
426 - store_config "${ENV_FILE}" LDPATH "${ldpath}"
427 - store_config "${ENV_FILE}" MANPATH "${manpath}"
428 - store_config "${ENV_FILE}" PKG_CONFIG_PATH "${pcpath}"
429 - do_action env update &> /dev/null
430 }