]> git.pld-linux.org Git - packages/phpenv.git/commitdiff
add phpenv system-php plugin: detect system php packages and create their
authorElan Ruusamäe <glen@delfi.ee>
Sun, 30 Nov 2014 20:47:22 +0000 (22:47 +0200)
committerElan Ruusamäe <glen@delfi.ee>
Sun, 30 Nov 2014 20:48:05 +0000 (22:48 +0200)
phpenv-system-php [new file with mode: 0755]
phpenv.spec

diff --git a/phpenv-system-php b/phpenv-system-php
new file mode 100755 (executable)
index 0000000..fdb74a4
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+# detect system php packages and create their versions
+# inspired by rbenv-alternatives:
+# https://github.com/terceiro/rbenv-alternatives
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+# Date: 2014-11-30
+
+set -e
+[ -n "$PHPENV_DEBUG" ] && set -x
+
+if [ "$1" = '--version' ]; then
+       echo '0.4.0'
+       exit 0
+fi
+
+if ! which rpm >/dev/null; then
+       echo "Sorry, it seems like you do not have rpm available on your PATH."
+       echo "Are you sure this is a RPM based system?"
+       exit 1
+fi
+
+for php in /usr/bin/php??; do
+       pkg=$(rpm -qf $php) || continue
+       version=$(rpm -q --qf '%{VERSION}' $pkg)
+       # use php-X.Y only for version selection
+       version=${version%.${version#*.*.}}-pld
+       echo "* Found $php (via $pkg) using $version as version"
+
+       if [ -d "${PHPENV_ROOT}/versions/$version" ]; then
+               echo "Skipping $version, it already exists"
+       else
+               rm -rf "${PHPENV_ROOT}/versions/$version"
+               mkdir -p "${PHPENV_ROOT}/versions/$version/bin"
+               ln -s "$php" "${PHPENV_ROOT}/versions/$version/bin/php"
+               echo "Added $version"
+       fi
+done
index ed134333596bd88eca73ca500179fc96dc8a2232..cb02ada77590d197f1c2a6fda50044e366ce1749 100644 (file)
@@ -2,6 +2,7 @@
 # - use similar recipe as done by CHH (https://github.com/CHH/phpenv)
 #   however, make it more rbenv compatible: code in /usr/share, env files in ~/.phpenv
 # - actually don't need code from CHH/phpenv as all is inlined in this .spec
+# - adds phpenv system-php to add php versions from installed system (may be renamed if better name provided)
 Summary:       Thin Wrapper around rbenv for PHP version managment
 Name:          phpenv
 Version:       0.4.0
@@ -10,6 +11,7 @@ License:      MIT
 Group:         Development/Languages/PHP
 Source0:       https://github.com/sstephenson/rbenv/archive/v%{version}/rbenv-%{version}.tar.gz
 # Source0-md5: c4a15a4dccf3dc1d28d08e87fb7c7789
+Source1:       phpenv-system-php
 URL:           https://github.com/CHH/phpenv
 Requires:      bash
 BuildArch:     noarch
@@ -75,6 +77,9 @@ rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT{%{_bindir},%{_appdir}/hooks}
 cp -a libexec completions $RPM_BUILD_ROOT%{_appdir}
 
+# phpenv system-php: detect system php packages and create their versions
+install -p %{SOURCE1} $RPM_BUILD_ROOT%{_appdir}/libexec
+
 ln -s %{_appdir}/libexec/%{name} $RPM_BUILD_ROOT%{_bindir}/%{name}
 
 %clean
This page took 0.069724 seconds and 4 git commands to generate.