summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Orlitzky <mjo@gentoo.org>2015-12-06 17:05:45 -0500
committerMichael Orlitzky <mjo@gentoo.org>2015-12-06 17:05:45 -0500
commitc3a380e35fcae0b80fedb28a76a0d9e1127cc259 (patch)
treedb45cd003eeab4c9d435263f61e21aa6edf04117
downloadeselect-php-c3a380e35fcae0b80fedb28a76a0d9e1127cc259.tar.gz
eselect-php-c3a380e35fcae0b80fedb28a76a0d9e1127cc259.tar.bz2
eselect-php-c3a380e35fcae0b80fedb28a76a0d9e1127cc259.zip
Initial commit of the current release, v0.7.1.
-rw-r--r--src/eselect-php-0.7.1352
1 files changed, 352 insertions, 0 deletions
diff --git a/src/eselect-php-0.7.1 b/src/eselect-php-0.7.1
new file mode 100644
index 0000000..9fe631c
--- /dev/null
+++ b/src/eselect-php-0.7.1
@@ -0,0 +1,352 @@
+# -*-eselect-*- vim: ft=eselect
+# Copyright 2010-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+
+inherit config multilib
+
+DESCRIPTION="Manage php installations"
+MAINTAINER="php-bugs@gentoo.org"
+
+MODULES="cli apache2 fpm cgi"
+
+cli_link="${EROOT}"/usr/bin/php
+fpm_link="${EROOT}"/usr/bin/php-fpm
+cgi_link="${EROOT}"/usr/bin/php-cgi
+
+cleanup_sapis() {
+ local m
+ local link
+ for m in $MODULES ; do
+ cleanup_sapi $m
+ done
+}
+
+cleanup_sapi() {
+ local l=${1}_link
+ local link=${!l}
+ if [[ -L $link && ! -e $link ]] ; then
+ echo -n "Broken link for $1"
+ if update_sapi $1 ; then
+ echo ", updated version to $(get_active_$1)"
+ return
+ else
+ rm $link
+
+ return
+ fi
+ fi
+ return 1
+}
+
+update_sapi() {
+ local target=$(find_targets_$1 | tail -n 1)
+ local current=$(get_active_$1)
+ [[ -z $target ]] && return 1
+ [[ $current = $target ]] && return 1
+ set_$1 $target
+}
+
+get_libdirs() {
+ local dir libdirs
+ for dir in $(list_libdirs); do
+ [[ -L ${EROOT}/usr/${dir} ]] && continue
+ ls "${EROOT}"/usr/${dir}/php*.* > /dev/null 2>&1 || continue
+
+ libdirs+=' '/usr/${dir}
+ done
+ echo ${libdirs:-/usr/lib}
+}
+
+get_active_libdir() {
+ local dir
+ for dir in $(get_libdirs); do
+ echo ${dir}
+ return
+ done
+ echo /usr/lib
+}
+
+get_libname() {
+ # probe on a well-known library
+ local lib ret=.so
+ for lib in "${EROOT}"$(get_active_libdir)/libz.* ; do
+ case "${lib##*/}" in
+ libz.a) ret=.a ;; # some platforms use .a as ext
+ libz.*.*) continue ;;
+ libz.*)
+ ret=${lib##*libz}
+ break
+ ;;
+ esac
+ done
+ echo ${ret}
+}
+
+apache2_link="${EROOT}"$(get_active_libdir)/apache2/modules/libphp5$(get_libname)
+
+cleanup() {
+ local target=$(find_targets_$1 | tail -n 1)
+ [[ -z $target ]] &&
+ set_$1 $target
+}
+
+find_targets() {
+ local dir dirs libdir
+ for libdir in $(get_libdirs); do
+ for dir in "${EROOT}"${libdir}/php*.*; do
+ t=$(basename $dir)
+ has $t $dirs || dirs="${dirs} $t"
+ done
+ done
+ echo $dirs
+}
+
+find_targets_apache2() {
+ local target libdir
+ for target in $(find_targets); do
+ for libdir in $(get_libdirs); do
+ [[ -f ${EROOT}${libdir}/$target/apache2/libphp5$(get_libname) ]] && echo $target
+ done
+ done | sort -u
+}
+
+find_targets_cli() {
+ local target libdir
+ for target in $(find_targets); do
+ for libdir in $(get_libdirs); do
+ [[ -f ${EROOT}${libdir}/$target/bin/php ]] && echo $target
+ done
+ done | sort -u
+}
+
+find_targets_fpm() {
+ local target libdir
+ for target in $(find_targets); do
+ for libdir in $(get_libdirs); do
+ [[ -f ${EROOT}${libdir}/$target/bin/php-fpm ]] && echo $target
+ done
+ done | sort -u
+}
+
+find_targets_cgi() {
+ local target libdir
+ for target in $(find_targets); do
+ for libdir in $(get_libdirs); do
+ [[ -f ${EROOT}${libdir}/$target/bin/php-cgi ]] && echo $target
+ done
+ done | sort -u
+}
+
+get_active_cli() {
+ readlink -e "${EROOT}"/usr/bin/php | sed -ne "s:.*/usr/.*/\(php[0-9]\.[0-9][0-9]*\)/bin/php:\1:p"
+}
+
+get_active_cgi() {
+ readlink -e "${EROOT}"/usr/bin/php-cgi | sed -ne "s:.*/usr/.*/\(php[0-9]\.[0-9]\)/bin/php-cgi:\1:p"
+}
+
+get_active_fpm() {
+ readlink -e "${EROOT}"/usr/bin/php-fpm | sed -ne "s:.*/usr/.*/\(php[0-9]\.[0-9]\)/bin/php-fpm:\1:p"
+}
+
+get_active_apache2() {
+ readlink -e "${EROOT}"$(get_active_libdir)/apache2/modules/libphp5$(get_libname) | sed -ne "s:.*/usr/.*/\(php[0-9]\.[0-9]\)/apache2/libphp5$(get_libname):\1:p"
+}
+
+resolv_target() {
+ local targets=( $(find_targets_$1) )
+ if is_number $2; then
+ [[ $2 -le ${#targets[@]} && $2 -gt 0 ]] && echo "${targets[ $(( $2 - 1 )) ]}"
+ elif has $2 ${targets[@]}; then
+ echo $2
+ fi
+}
+
+check_module() {
+ has $1 $(echo $MODULES) || die -q "Please chose one of the following modules: ${MODULES}"
+}
+
+## Actual actions
+
+list_apache2() {
+ local targets
+ local a
+ targets=( $(find_targets_apache2) )
+ a=$(get_active_apache2)
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ [[ $a == ${targets[i]} ]] && targets[i]=$(highlight_marker "${targets[i]}")
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
+}
+
+list_cli() {
+ local targets
+ local a
+ targets=( $(find_targets_cli) )
+ a=$(get_active_cli)
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ [[ $a == ${targets[i]} ]] && targets[i]=$(highlight_marker "${targets[i]}")
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
+}
+
+list_cgi() {
+ local targets
+ local a
+ targets=( $(find_targets_cgi) )
+ a=$(get_active_cgi)
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ [[ $a == ${targets[i]} ]] && targets[i]=$(highlight_marker "${targets[i]}")
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
+}
+
+list_fpm() {
+ local targets
+ local a
+ targets=( $(find_targets_fpm) )
+ a=$(get_active_fpm)
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ [[ $a == ${targets[i]} ]] && targets[i]=$(highlight_marker "${targets[i]}")
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
+}
+
+set_apache2() {
+ local libdir t=$(resolv_target apache2 $1)
+ [[ -z $t ]] && die -q "Bad target"
+ for libdir in $(get_libdirs); do
+ ln -sf ../../$t/apache2/libphp5$(get_libname) "${EROOT}"${libdir}/apache2/modules/ || \
+ die -q "Failed to set symlink for ${EPREFIX}${libdir}/apache2/modules/libphp5$(get_libname)"
+ done
+ echo "You have to run \`${EPREFIX}/etc/init.d/apache2 restart' for the changes to take effect"
+}
+
+set_cli() {
+ local file libdir t=$(resolv_target cli $1)
+ [[ -z $t ]] && die -q "Bad target"
+ for file in php phpize php-config; do
+ ln -sf ../..$(get_active_libdir)/$t/bin/$file "${EROOT}"/usr/bin/$file || \
+ die -q "Failed to create symlink for ${file}"
+ done
+}
+
+set_cgi() {
+ t=$(resolv_target cgi $1)
+ [[ -z $t ]] && die -q "Bad target"
+ ln -sf ../..$(get_active_libdir)/$t/bin/php-cgi "${EROOT}"/usr/bin/php-cgi || \
+ die -q "Failed to create symlink for php-cgi"
+}
+
+set_fpm() {
+ local t=$(resolv_target fpm $1)
+ [[ -z $t ]] && die -q "Bad target"
+ ln -sf ../..$(get_active_libdir)/$t/bin/php-fpm "${EROOT}"/usr/bin/php-fpm || \
+ die -q "Failed to create symlink for the php-fpm binary"
+ echo "You have to run \`${EPREFIX}/etc/init.d/php-fpm restart' for the changes to take effect"
+}
+## set action
+
+describe_set() {
+ echo "Sets the current configuration for a module"
+}
+
+describe_set_parameters() {
+ echo "<module> <target>"
+}
+
+describe_set_options() {
+ echo "module: one of ${MODULES}"
+ echo "target: Target name or number (from the 'list' action)"
+}
+
+
+do_set() {
+ check_module $1
+ set_$1 $2
+}
+
+
+
+## List action
+
+describe_list() {
+ echo "Lists available php installs for a module"
+}
+
+describe_list_parameters() {
+ echo "<module>"
+}
+
+describe_list_options() {
+ echo "module: one of ${MODULES}"
+}
+
+do_list() {
+ check_module $1
+ list_$1
+}
+
+## Show action
+
+describe_show() {
+ echo "Lists available php installs for a module"
+}
+
+describe_show_parameters() {
+ echo "<module>"
+}
+
+describe_show_options() {
+ echo "module: one of ${MODULES}"
+}
+
+do_show() {
+ check_module $1
+ get_active_$1
+}
+
+## update action
+
+describe_update() {
+ echo "Automatically update the php versions"
+}
+
+describe_update_parameters() {
+ echo "<module> [ifunset]"
+}
+
+describe_update_options() {
+ echo "module: one of ${MODULES}"
+ echo "ifunset : Do not override existing implementation"
+}
+
+do_update() {
+ check_module $1
+ [[ -z ${2} || ( -z ${3} && ( ${2} == ifunset || ${2} == '--if-unset' ) ) ]] || \
+ die -q "Usage error"
+
+ [[ ( ${2} == ifunset || ${2} == '--if-unset' ) && -n $(get_active_$1) ]] && \
+ return
+
+ update_sapi $1 || echo "Nothing to update"
+}
+
+## cleanup action
+
+describe_cleanup() {
+ echo "Automatically clean up stale links"
+}
+
+describe_cleanup_parameters() {
+ echo
+}
+
+describe_cleanup_options() {
+ echo
+}
+
+do_cleanup() {
+ cleanup_sapis
+}