diff options
author | Aaron W. Swenson <titanofold@gentoo.org> | 2011-03-29 13:52:15 -0400 |
---|---|---|
committer | Aaron W. Swenson <titanofold@gentoo.org> | 2011-03-29 13:52:15 -0400 |
commit | 954bb1574c657e05084c7d3f58f6d5eae1ba2244 (patch) | |
tree | c5de27f90c3c26084084e0648a4be8b34cc94c37 | |
parent | Cleaned up output and localized variables. (diff) | |
download | eselect-954bb1574c657e05084c7d3f58f6d5eae1ba2244.tar.gz eselect-954bb1574c657e05084c7d3f58f6d5eae1ba2244.tar.bz2 eselect-954bb1574c657e05084c7d3f58f6d5eae1ba2244.zip |
Switched from 'ls' to 'find'. Addressed issues from
http://archives.gentoo.org/gentoo-dev/msg_5825580bbfa5b8b2f6dab9faa880ddd3.xml
-rw-r--r-- | postgresql.eselect | 124 |
1 files changed, 74 insertions, 50 deletions
diff --git a/postgresql.eselect b/postgresql.eselect index 9a7e0c5..211dbc5 100644 --- a/postgresql.eselect +++ b/postgresql.eselect @@ -2,48 +2,59 @@ # Distributed under the terms of the GNU General Public License v2 # $Id: $ -inherit config multilib output package-manager path-manipulation +inherit config multilib DESCRIPTION="Manage active PostgreSQL client applications and libraries" MAINTAINER="pgsql-bugs@gentoo.org" SVN_DATE='$Date: $' -VERSION="1.0.4" +VERSION="1.0.5" # Global Data B_PATH="${EROOT%/}/usr" E_PATH="${EROOT%/}/etc/eselect/postgresql" ENV_FILE="${EROOT%/}/etc/env.d/50postgresql" -if [ -r ${E_PATH}/active -a -n ${E_PATH}/active ] ; then - ACTIVE_SLOT=$(<${E_PATH}/active) -else - ACTIVE_SLOT="(none)" -fi -LIB_LIST=$(list_libdirs) -if [[ ${LIB_LIST} =~ .*lib64.* && "$(ls -d ${B_PATH}/lib64/postgresql-*/lib)" != "" ]] ; then - LIBDIR="lib64" -elif [[ ${LIB_LIST} =~ .*lib32.* && "$(ls -d ${B_PATH}/lib32/postgresql-*/lib)" != "" ]] ; then - LIBDIR="lib32" -else - LIBDIR="lib" -fi + +active_slot() { + if [[ -r ${E_PATH}/active && -n ${E_PATH}/active ]] ; then + echo $( <${E_PATH}/active ) + else + echo "(none)" + fi +} + +lib_dir() { + local lib_list=$(list_libdirs) + if [[ ${lib_list} =~ .*lib64.* && \ + "$(ls -d ${B_PATH}/lib64/postgresql-*/lib)" != "" ]] ; then + echo "lib64" + elif [[ ${lib_list} =~ .*lib32.* && \ + "$(ls -d ${B_PATH}/lib32/postgresql-*/lib)" != "" ]] ; then + echo "lib32" + else + echo "lib" + fi +} ### Linker Function ### # Takes three arguments: -# - Full source path (e.g. /usr/lib/postgresql-9.0/lib/lib*.{a,so}) +# - Full source path (e.g. /usr/lib/postgresql-9.0/lib) +# _ Pattern to search for # - Full target directory path (e.g. /usr/bin) # - Suffix (Optional) (e.g 84 to make /usr/bin/psql84) linker() { local source_dir=$1 - local target_dir=$2 - local suffix=$3 + local pattern=$2 + local target_dir=$3 + local suffix=$4 local link_source - for link_source in $(eval ls ${source_dir} 2> /dev/null) ; do + for link_source in $(find ${source_dir} -maxdepth 1 ${pattern}) ; do local link_target="${target_dir%/}/$(basename ${link_source})${suffix}" # For good measure, remove target before creating the symlink - [ -h ${link_target} ] && rm -f ${link_target} - [ -e ${link_target} ] && die -q "The target '${link_target}' still exists and could not be removed!" + [[ -h ${link_target} ]] && rm -f ${link_target} + [[ -e ${link_target} ]] && \ + die -q "The target '${link_target}' still exists and could not be removed!" ln -s ${link_source} ${link_target} || die -q "Unable to create link!" echo ${link_target} >> ${E_PATH}/active.links${suffix} @@ -59,7 +70,8 @@ unlinker() { local active_links=($(<${active_link_file})) for (( i=0; $i < ${#active_links[@]}; i++ )) ; do [ -h ${active_links[$i]} ] && rm -f ${active_links[$i]} - [ -e ${active_links[$i]} ] && die -q "The target '${active_links[$i]}' still exists and could not be removed!" + [ -e ${active_links[$i]} ] && \ + die -q "The target '${active_links[$i]}' still exists and could not be removed!" done rm -f ${active_link_file} @@ -67,9 +79,9 @@ unlinker() { } ### Get Slots Function ### -# Find all available slots in the preferred LIBDIR and return them. +# Find all available slots in the preferred lib_dir() and return them. get_slots() { - echo $(ls -dv ${B_PATH}/${LIBDIR}/postgresql-* 2> /dev/null | sed -re 's#^.+-##') + echo $(ls -dv ${B_PATH}/$(lib_dir)/postgresql-* 2> /dev/null | sed -re 's#^.+-##') } ### List Action ### @@ -92,8 +104,10 @@ do_list() { done case "${slot}" in - "${ACTIVE_SLOT}" ) write_kv_list_entry "$(highlight_marker ${slot})" "${postgres_ebuilds//postgresql-/}";; - * ) write_kv_list_entry "${slot}" "${postgres_ebuilds//postgresql-/}";; + "$(active_slot)" ) write_kv_list_entry \ + "$(highlight_marker ${slot})" "${postgres_ebuilds//postgresql-/}";; + * ) write_kv_list_entry \ + "${slot}" "${postgres_ebuilds//postgresql-/}";; esac done @@ -107,7 +121,7 @@ describe_show() { } do_show() { - echo ${ACTIVE_SLOT} + echo $(active_slot) } ### Show Service Action ### @@ -127,7 +141,7 @@ describe_set() { do_set() { local SLOT=$1 - if [ ! -d ${B_PATH}/${LIBDIR}/postgresql-${SLOT} ] ; then + if [ ! -d ${B_PATH}/$(lib_dir)/postgresql-${SLOT} ] ; then die -q "Not a valid slot." fi @@ -161,7 +175,8 @@ do_set() { rm -f ${targets[$i]} # Check if link_target still exists - [ -e ${targets[$i]} ] && die -q "The target '${targets[$i]}' exists and could not be removed!" + [[ -e ${targets[$i]} ]] && \ + die -q "The target '${targets[$i]}' exists and could not be removed!" ln -s ${sources[$i]} ${targets[$i]} || die -q "Unable to create link!" echo ${targets[$i]} >> ${E_PATH}/active.links @@ -169,19 +184,21 @@ do_set() { # Link modules to /usr/lib{,lib32,lib64}/ local x - for x in ${LIB_LIST} ; do - if [ -d ${B_PATH}/${x}/postgresql-${SLOT}/${x} ] ; then + for x in $(list_libdirs) ; do + if [[ -d ${B_PATH}/${x}/postgresql-${SLOT}/${x} ]] ; then # 'linker' function doesn't work for linking directories. # Default lib path ln -s ${B_PATH}/${x}/postgresql-${SLOT}/${x} ${B_PATH}/${x}/postgresql echo ${B_PATH}/${x}/postgresql >> ${E_PATH}/active.links # Linker works for files - linker "${B_PATH}/${x}/postgresql-${SLOT}/${x}/lib*.{a,dylib,so}" "${B_PATH}/${x}" + linker "${B_PATH}/${x}/postgresql-${SLOT}/${x}" \ + "-name lib*[a|dylib|so]" "${B_PATH}/${x}" fi done # Link binaries to /usr/bin/ - linker "${B_PATH}/${LIBDIR}/postgresql-${SLOT}/bin/*" "${B_PATH}/bin" + linker "${B_PATH}/$(lib_dir)/postgresql-${SLOT}/bin/" \ + "-xtype f" "${B_PATH}/bin" # Default share path ln -s ${B_PATH}/share/postgresql-${SLOT} ${B_PATH}/share/postgresql @@ -189,7 +206,7 @@ do_set() { echo ${SLOT} > ${E_PATH}/active echo "done." - echo -e "\033[1mSetting ${SLOT} as default was successful!\033[0m" + echo "Setting ${SLOT} as default was successful!" } ### Unset Action ### @@ -199,7 +216,7 @@ describe_unset() { do_unset() { local SLOT=$1 - if [ "${SLOT}" = "${ACTIVE_SLOT}" ] ; then + if [[ "${SLOT}" = "$(active_slot)" ]] ; then echo -n "Unsetting ${SLOT} as the default installation..." unlinker ${E_PATH}/active.links rm -f ${E_PATH}/active @@ -215,9 +232,10 @@ describe_reset() { } do_reset() { - [ "${ACTIVE_SLOT}" = "(none)" ] && die -q "No active slot to reset." - do_unset ${ACTIVE_SLOT} - do_set ${ACTIVE_SLOT} + local SLOT=$(active_slot) + [[ "${SLOT}" = "(none)" ]] && die -q "No active slot to reset." + do_unset ${SLOT} + do_set ${SLOT} } ### Update Action ### @@ -226,20 +244,23 @@ describe_update() { } do_update() { + local slot=$(active_slot) # Check for files managed by postgresql.eselect before 1.0 - [ -h /etc/eselect/postgresql/active ] && ACTIVE_SLOT="$(basename $(canonicalise /etc/eselect/postgesql/active))" + [[ -h /etc/eselect/postgresql/active ]] && \ + slot="$(basename $(canonicalise /etc/eselect/postgesql/active))" # Remove service file outright. - [ -h /etc/eselect/postgresql/service ] && rm -f /etc/eselect/postgresql/service + [[ -h /etc/eselect/postgresql/service ]] && \ + rm -f /etc/eselect/postgresql/service local slots=($(get_slots)) local index=${#slots[@]} # In case all slots have been unmerged - if [ ${index} -eq 0 ] ; then + if [[ ${index} -eq 0 ]] ; then write_warning_msg "No slots found!" write_warning_msg "Removing files (Control-C to abort) in..." local i=6 - while [ $[i--] -gt 0 ] ; do + while [[ $[i--] -gt 0 ]] ; do echo -n " $i" sleep 1 done @@ -254,7 +275,7 @@ do_update() { fi # Reset, otherwise set the highest slot available. - if [[ ${slots[@]} =~ ${ACTIVE_SLOT} ]] ; then + if [[ ${slots[@]} =~ ${slot} ]] ; then do_reset else # best_version doesn't work here as pkg_postrm runs before the world @@ -272,21 +293,24 @@ do_update() { # Update paths to libs and docs local ldpath local x - for x in ${LIB_LIST} ; do - [ -h ${B_PATH}/${x}/postgresql ] && ldpath+="${B_PATH}/${x}/postgresql:" + for x in $(list_libdirs) ; do + [[ -h ${B_PATH}/${x}/postgresql ]] && \ + ldpath+="${B_PATH}/${x}/postgresql:" done ldpath="${ldpath%:}" local manpath="${B_PATH}/share/postgresql/" - while [ $[--index] -gt -1 ] ; do + while [[ $[--index] -gt -1 ]] ; do local curslot="${slots[$index]}" - echo -n "Refreshing symbolic links for ${curslot} applications (like /usr/bin/psql${curslot//.})..." + echo -n "Refreshing symbolic links for ${curslot} applications (like " + echo -n "/usr/bin/psql${curslot//.})..." for x in ${LIB_LIST} ; do local lib_path="${B_PATH}/${x}/postgresql-${curslot}/${x}/" - [ -d ${lib_path} ] && ldpath+=":${lib_path}" + [[ -d ${lib_path} ]] && ldpath+=":${lib_path}" done local share_path="${B_PATH}/share/postgresql-${curslot}/" - [ -d ${share_path} ] && manpath+=":${share_path}" - linker "${B_PATH}/${LIBDIR}/postgresql-${curslot}/bin/*" "${B_PATH}/bin" "${curslot//.}" + [[ -d ${share_path} ]] && manpath+=":${share_path}" + linker "${B_PATH}/$(lib_dir)/postgresql-${curslot}/bin/" \ + "-xtype f" "${B_PATH}/bin" "${curslot//.}" echo "done." done |