├── LICENSE
├── README.md
└── bin
└── phpenv-installer
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Rogerio Prado de Jesus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # phpenv-installer
2 |
3 | Install [CHH/phpenv](https://github.com/CHH/phpenv) +
4 | [php-build/php-build](https://github.com/php-build/php-build) (and
5 | other plugins), updating all of them when you want to!
6 |
7 | ## Installation
8 |
9 | It's the standard way: installs `phpenv` in $HOME/.phpenv (default
10 | $PHPENV_ROOT value).
11 |
12 | ```shell
13 | curl -L http://git.io/phpenv-installer \
14 | | bash
15 | ```
16 |
17 | ### Optional: Installation in other directory (i.e. system-wide)
18 |
19 | If you prefer to install `phpenv` in other directory (i.e
20 | `$HOME/myphpenv`), or perhaps system-wide (i.e. `/usr/local/bin/phpenv`),
21 | it's easy: just set $PHPENV_ROOT before the installer command:
22 |
23 | ```shell
24 | # $HOME/myphpenv
25 | curl -L http://git.io/phpenv-installer \
26 | | PHPENV_ROOT=$HOME/myphpenv bash
27 | ```
28 |
29 | ```shell
30 | # /usr/local/bin/phpenv
31 | curl -L http://git.io/phpenv-installer \
32 | | PHPENV_ROOT=/usr/local/bin/phpenv bash
33 | ```
34 |
35 | > Note: depends on the path, you will need superuser (sudo)
36 | permission. Feel free to ask if you need some help!
37 |
38 | ## Updating
39 |
40 | ```shell
41 | phpenv update
42 | ```
43 |
44 | ## Uninstallation
45 |
46 | ```shell
47 | rm -rf $(phpenv root)
48 | ```
49 |
50 |
51 |
52 | Inspired by [rbenv-installer](https://github.com/fesplugas/rbenv-installer) and [pyenv-installer](https://github.com/yyuu/pyenv-installer)
53 |
--------------------------------------------------------------------------------
/bin/phpenv-installer:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e
4 | [ -n "$PHPENV_DEBUG" ] && set -x
5 |
6 | if [ -z "$PHPENV_ROOT" ]; then
7 | PHPENV_ROOT="${HOME}/.phpenv"
8 | fi
9 |
10 | shell="$1"
11 | if [ -z "$shell" ]; then
12 | shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
13 | shell="${shell##-}"
14 | shell="${shell%% *}"
15 | shell="$(basename "${shell:-$SHELL}")"
16 | fi
17 |
18 | indent_output() {
19 | while read data; do
20 | echo -e " \033[1;32m|\033[0m $data"
21 | done
22 | }
23 |
24 | colorize_output() {
25 | while read data; do
26 | echo -e "\033[1;32m$data\033[0m"
27 | done
28 | }
29 |
30 | checkout() {
31 | if [ ! -d "$2" ] ;then
32 | git clone "$1" "$2"
33 | else
34 | git pull --no-rebase --ff
35 | fi
36 | }
37 |
38 | test_write_permission_in_install_folder() {
39 | local cmd_output=""
40 | local file_test="$(dirname ${PHPENV_ROOT})/1"
41 | set +e
42 | cmd_output=$(touch $file_test 3>&1 2>&3 )
43 | set -e
44 |
45 | if [[ $cmd_output =~ "Permission denied" ]]; then
46 | echo "ERROR" | colorize_output
47 | echo "Permission denied when trying to write in ${PHPENV_ROOT}." | indent_output
48 | echo "Adjust your \$PHPENV_ROOT or try to use sudo." | indent_output
49 | exit 1
50 | else
51 | rm -rf $file_test
52 | fi
53 | }
54 |
55 |
56 | install_phpenv() {
57 | local sh="https://raw.githubusercontent.com/CHH/phpenv/master/bin/phpenv-install.sh"
58 |
59 | echo "Installing phpenv" | colorize_output
60 |
61 | if [ -d "$PHPENV_ROOT" ]; then
62 | curl -L --silent ${sh} | UPDATE=yes PHPENV_ROOT=${PHPENV_ROOT} bash &>/dev/null
63 | else
64 | curl -L --silent ${sh} | PHPENV_ROOT=${PHPENV_ROOT} bash &>/dev/null
65 | fi
66 |
67 | echo "Done." | indent_output
68 | echo
69 | }
70 |
71 | install_plugin() {
72 | local vendor=${1%/*}
73 | local plugin=${1#*/}
74 |
75 | echo "Installing $vendor/$plugin" | colorize_output
76 | checkout "https://github.com/${vendor}/${plugin}.git" "${PHPENV_ROOT}/plugins/${plugin}" &>/dev/null
77 | echo "Done." | indent_output
78 | echo
79 | }
80 |
81 | profile_by_shell() {
82 | local profile
83 | case "$shell" in
84 | bash )
85 | profile="~/.bash_profile"
86 | ;;
87 | zsh )
88 | profile="~/.zshrc"
89 | ;;
90 | ksh )
91 | profile="~/.profile"
92 | ;;
93 | fish )
94 | profile="~/.config/fish/config.fish"
95 | ;;
96 | * )
97 | profile="your profile"
98 | ;;
99 | esac
100 | echo $profile
101 | }
102 |
103 | test_deps() {
104 | if ! command -v git 1>/dev/null 2>&1; then
105 | echo "phpenv: Git is not installed, can't continue." >&2 | indent_output
106 | exit 1
107 | fi
108 |
109 | if ! command -v curl 1>/dev/null 2>&1; then
110 | echo "phpenv: Curl is not installed, can't continue." >&2 | indent_output
111 | exit 1
112 | fi
113 | }
114 |
115 | test_if_phpenv_is_in_path() {
116 | if ! command -v phpenv 1>/dev/null; then
117 |
118 | { echo "WARNING" | colorize_output
119 | echo "# Seems you still have not added 'phpenv' to the load path." | indent_output
120 | echo | indent_output
121 | } >&2
122 |
123 | { echo "# Load phpenv automatically by adding" | indent_output
124 | echo "# the following to $(profile_by_shell):" | indent_output
125 | echo
126 | case "$shell" in
127 | fish )
128 | echo "set -x PHPENV_ROOT \"${PHPENV_ROOT}\""
129 | echo "if test -d \"$PHPENV_ROOT\""
130 | echo " set -x PATH \"$PHPENV_ROOT/bin\" \$PATH"
131 | echo ' status --is-interactive; and . (phpenv init -|psub)'
132 | echo "end"
133 | ;;
134 | * )
135 | echo "export PHPENV_ROOT=\"${PHPENV_ROOT}\""
136 | echo "if [ -d \"\${PHPENV_ROOT}\" ]; then"
137 | echo " export PATH=\"\${PHPENV_ROOT}/bin:\${PATH}\""
138 | echo " eval \"\$(phpenv init -)\""
139 | echo "fi"
140 | ;;
141 | esac
142 | echo
143 | } >&2
144 |
145 | else
146 |
147 | { echo "Alright!" | colorize_output
148 | echo "Execute:" | indent_output
149 | echo "\`phpenv commands\` to see all you can do" | indent_output
150 | echo "\`phpenv help \` for information on a specific command" | indent_output
151 | echo
152 | } >&2
153 |
154 | fi
155 | }
156 |
157 | echo "INFO" | colorize_output
158 | echo "\$PHPENV_ROOT is defined as ${PHPENV_ROOT}" | indent_output
159 | echo
160 | test_write_permission_in_install_folder
161 | test_deps
162 | install_phpenv
163 | install_plugin "php-build/php-build"
164 | install_plugin "rogeriopradoj/phpenv-update"
165 | install_plugin "rogeriopradoj/phpenv-common-deps-install"
166 | test_if_phpenv_is_in_path
167 |
--------------------------------------------------------------------------------