|
1 | | -#!/usr/bin/env bash |
2 | | -# |
3 | | -# This file is part of the Phalcon Framework. |
4 | | -# |
5 | | -# (c) Phalcon Team <team@phalcon.io> |
6 | | -# |
7 | | -# For the full copyright and license information, please view the |
8 | | -# LICENSE.txt file that was distributed with this source code. |
9 | | - |
10 | | -PURPLE="\033[0;35m" |
11 | | -GREEN="\033[0;32m" |
12 | | -YELLOW="\033[1;33m" |
13 | | -NC="\033[0m" |
14 | | -DIR= |
15 | | -IS_BASH=0 |
16 | | -SOURCE_FILE= |
17 | | - |
18 | | -init(){ |
19 | | - source=`echo $0 | grep "bash"` |
20 | | - |
21 | | - if [ "$source" == "bash" ]; then |
22 | | - DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
23 | | - IS_BASH=1 |
24 | | - else |
25 | | - DIR=$( cd -P -- "$( dirname -- "$0" )" && pwd -P ) |
26 | | - fi |
27 | | - |
28 | | - DIR=${DIR%/} |
29 | | -} |
30 | | - |
31 | | -alter_profile(){ |
32 | | - export PTOOLSPATH="$DIR/" |
33 | | - export PATH="$PATH:$DIR" |
34 | | - |
35 | | - PTOOLSVAR="export PTOOLSPATH=${DIR}/" |
36 | | - PATHVAR="export PATH=\$PATH:$DIR" |
37 | | - |
38 | | - if [ -e $HOME/.bash_profile ]; then |
39 | | - echo "$PTOOLSVAR" >> $HOME/.bash_profile |
40 | | - echo "$PATHVAR" >> $HOME/.bash_profile |
41 | | - SOURCE_FILE=$HOME/.bash_profile |
42 | | - |
43 | | - source ${SOURCE_FILE} |
44 | | - elif [ -e $HOME/.bashrc ]; then |
45 | | - echo "$PTOOLSVAR" >> $HOME/.bashrc |
46 | | - echo "$PATHVAR" >> $HOME/.bashrc |
47 | | - SOURCE_FILE=$HOME/.bashrc |
48 | | - |
49 | | - source ${SOURCE_FILE} |
50 | | - elif [ -e $HOME/.profile ]; then |
51 | | - echo "$PTOOLSVAR" >> $HOME/.profile |
52 | | - echo "$PATHVAR" >> $HOME/.profile |
53 | | - SOURCE_FILE=$HOME/.profile |
54 | | - |
55 | | - source ${SOURCE_FILE} |
56 | | - elif [ -e $HOME/.zshrc ]; then |
57 | | - echo "$PTOOLSVAR" >> $HOME/.zshrc |
58 | | - echo "$PATHVAR" >> $HOME/.zshrc |
59 | | - SOURCE_FILE=$HOME/.bashrc |
60 | | - |
61 | | - source ${SOURCE_FILE} |
62 | | - elif [ -e $HOME/.cshrc ]; then |
63 | | - echo "setenv PTOOLSPATH ${DIR}/" >> $HOME/.cshrc |
64 | | - echo "setenv PATH \${PATH}:$DIR" >> $HOME/.cshrc |
65 | | - SOURCE_FILE=$HOME/.cshrc |
66 | | - |
67 | | - source ${SOURCE_FILE} |
68 | | - else |
69 | | - printf "\n${PURPLE}No bash profile detected. Environment vars might disappear on console restart!${NC}\n" |
70 | | - return 0 |
71 | | - fi |
72 | | -} |
73 | | - |
74 | | -check_bash(){ |
75 | | - if [ "$IS_BASH" == 0 ] && [ ! -z "$SOURCE_FILE" ]; then |
76 | | - printf "\nTo start using Phalcon Developer Tools you need to run 'source ${SOURCE_FILE}'" |
77 | | - printf "\n" |
78 | | - fi |
79 | | - |
80 | | - printf "\n" |
81 | | -} |
82 | | - |
83 | | -check_install(){ |
84 | | - if [ -z "$PTOOLSPATH" ]; then |
85 | | - printf "\n${YELLOW}Phalcon Developer Tools Installer${NC}" |
86 | | - printf "\n" |
87 | | - printf "\n${PURPLE}Make sure phalcon.sh is in the same dir as phalcon file${NC}" |
88 | | - printf "\n${PURPLE}and that you are running this with sudo or as root.${NC}" |
89 | | - printf "\n" |
90 | | - printf "\nInstalling Devtools..." |
91 | | - printf "\nWorking dir is: ${DIR}" |
92 | | - |
93 | | - devtools="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
94 | | - |
95 | | - if [ -f ${devtools}/phalcon ]; then |
96 | | - printf "\nFailed to create symbolic link ${devtools}/phalcon: File exists" |
97 | | - printf "\nExit.\n\n" |
98 | | - return 1 |
99 | | - fi |
100 | | - |
101 | | - alter_profile |
102 | | - |
103 | | - if [ ! -L ${devtools}/phalcon ]; then |
104 | | - printf "\nGenerating symlink..." |
105 | | - ln -s ${devtools}/phalcon.sh ${devtools}/phalcon |
106 | | - chmod +x ${devtools}/phalcon |
107 | | - printf "\n\nDone. Phalcon Developer Tools installed!" |
108 | | - printf "\nThank you for using Phalcon Developer Tools!" |
109 | | - printf "\nWe hope that Phalcon Developer Tools helps to make your life easier." |
110 | | - printf "\n" |
111 | | - printf "\nIn case of problems: " |
112 | | - printf "${YELLOW}https://github.com/phalcon/phalcon-devtools/issues${NC} " |
113 | | - printf "\n and: ${YELLOW}https://forum.phalcon.io${NC}" |
114 | | - printf "\n" |
115 | | - |
116 | | - check_bash |
117 | | - |
118 | | - return 0 |
119 | | - fi |
120 | | - return 1 |
121 | | - else |
122 | | - devtools=${PTOOLSPATH%/} |
123 | | - if [ "${devtools}" != "${DIR}" ]; then |
124 | | - printf "\n${PURPLE}Your environment variable \$PTOOLSPATH is outdated!${NC}" |
125 | | - printf "\n${PURPLE}Current value: $devtools${NC}" |
126 | | - printf "\n${PURPLE}New value: $DIR${NC}" |
127 | | - printf "\nExit.\n\n" |
128 | | - return 1 |
129 | | - fi |
130 | | - fi |
131 | | - return 0 |
132 | | -} |
133 | | - |
134 | | -init |
135 | | - |
136 | | -if check_install; then |
137 | | - devtools=${PTOOLSPATH%/} |
138 | | - php "$devtools/phalcon" $* |
139 | | -fi |
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# This file is part of the Phalcon Framework. |
| 4 | +# |
| 5 | +# (c) Phalcon Team <team@phalcon.io> |
| 6 | +# |
| 7 | +# For the full copyright and license information, please view the |
| 8 | +# LICENSE.txt file that was distributed with this source code. |
| 9 | + |
| 10 | +PURPLE="\033[0;35m" |
| 11 | +GREEN="\033[0;32m" |
| 12 | +YELLOW="\033[1;33m" |
| 13 | +NC="\033[0m" |
| 14 | +DIR= |
| 15 | +IS_BASH=0 |
| 16 | +SOURCE_FILE= |
| 17 | + |
| 18 | +init(){ |
| 19 | + source=`echo $0 | grep "bash"` |
| 20 | + |
| 21 | + if [ "$source" == "bash" ]; then |
| 22 | + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 23 | + IS_BASH=1 |
| 24 | + else |
| 25 | + DIR=$( cd -P -- "$( dirname -- "$0" )" && pwd -P ) |
| 26 | + fi |
| 27 | + |
| 28 | + DIR=${DIR%/} |
| 29 | +} |
| 30 | + |
| 31 | +alter_profile(){ |
| 32 | + export PTOOLSPATH="$DIR/" |
| 33 | + export PATH="$PATH:$DIR" |
| 34 | + |
| 35 | + PTOOLSVAR="export PTOOLSPATH=${DIR}/" |
| 36 | + PATHVAR="export PATH=\$PATH:$DIR" |
| 37 | + |
| 38 | + if [ -e $HOME/.bash_profile ]; then |
| 39 | + echo "$PTOOLSVAR" >> $HOME/.bash_profile |
| 40 | + echo "$PATHVAR" >> $HOME/.bash_profile |
| 41 | + SOURCE_FILE=$HOME/.bash_profile |
| 42 | + |
| 43 | + source ${SOURCE_FILE} |
| 44 | + elif [ -e $HOME/.bashrc ]; then |
| 45 | + echo "$PTOOLSVAR" >> $HOME/.bashrc |
| 46 | + echo "$PATHVAR" >> $HOME/.bashrc |
| 47 | + SOURCE_FILE=$HOME/.bashrc |
| 48 | + |
| 49 | + source ${SOURCE_FILE} |
| 50 | + elif [ -e $HOME/.profile ]; then |
| 51 | + echo "$PTOOLSVAR" >> $HOME/.profile |
| 52 | + echo "$PATHVAR" >> $HOME/.profile |
| 53 | + SOURCE_FILE=$HOME/.profile |
| 54 | + |
| 55 | + source ${SOURCE_FILE} |
| 56 | + elif [ -e $HOME/.zshrc ]; then |
| 57 | + echo "$PTOOLSVAR" >> $HOME/.zshrc |
| 58 | + echo "$PATHVAR" >> $HOME/.zshrc |
| 59 | + SOURCE_FILE=$HOME/.bashrc |
| 60 | + |
| 61 | + source ${SOURCE_FILE} |
| 62 | + elif [ -e $HOME/.cshrc ]; then |
| 63 | + echo "setenv PTOOLSPATH ${DIR}/" >> $HOME/.cshrc |
| 64 | + echo "setenv PATH \${PATH}:$DIR" >> $HOME/.cshrc |
| 65 | + SOURCE_FILE=$HOME/.cshrc |
| 66 | + |
| 67 | + source ${SOURCE_FILE} |
| 68 | + else |
| 69 | + printf "\n${PURPLE}No bash profile detected. Environment vars might disappear on console restart!${NC}\n" |
| 70 | + return 0 |
| 71 | + fi |
| 72 | +} |
| 73 | + |
| 74 | +check_bash(){ |
| 75 | + if [ "$IS_BASH" == 0 ] && [ ! -z "$SOURCE_FILE" ]; then |
| 76 | + printf "\nTo start using Phalcon Developer Tools you need to run 'source ${SOURCE_FILE}'" |
| 77 | + printf "\n" |
| 78 | + fi |
| 79 | + |
| 80 | + printf "\n" |
| 81 | +} |
| 82 | + |
| 83 | +check_install(){ |
| 84 | + if [ -z "$PTOOLSPATH" ]; then |
| 85 | + printf "\n${YELLOW}Phalcon Developer Tools Installer${NC}" |
| 86 | + printf "\n" |
| 87 | + printf "\n${PURPLE}Make sure phalcon.sh is in the same dir as phalcon file${NC}" |
| 88 | + printf "\n${PURPLE}and that you are running this with sudo or as root.${NC}" |
| 89 | + printf "\n" |
| 90 | + printf "\nInstalling Devtools..." |
| 91 | + printf "\nWorking dir is: ${DIR}" |
| 92 | + |
| 93 | + devtools="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 94 | + |
| 95 | + if [ -f ${devtools}/phalcon ]; then |
| 96 | + printf "\nFailed to create symbolic link ${devtools}/phalcon: File exists" |
| 97 | + printf "\nExit.\n\n" |
| 98 | + return 1 |
| 99 | + fi |
| 100 | + |
| 101 | + alter_profile |
| 102 | + |
| 103 | + if [ ! -L ${devtools}/phalcon ]; then |
| 104 | + printf "\nGenerating symlink..." |
| 105 | + ln -s ${devtools}/phalcon.sh ${devtools}/phalcon |
| 106 | + chmod +x ${devtools}/phalcon |
| 107 | + printf "\n\nDone. Phalcon Developer Tools installed!" |
| 108 | + printf "\nThank you for using Phalcon Developer Tools!" |
| 109 | + printf "\nWe hope that Phalcon Developer Tools helps to make your life easier." |
| 110 | + printf "\n" |
| 111 | + printf "\nIn case of problems: " |
| 112 | + printf "${YELLOW}https://github.com/phalcon/phalcon-devtools/issues${NC} " |
| 113 | + printf "\n and: ${YELLOW}https://forum.phalcon.io${NC}" |
| 114 | + printf "\n" |
| 115 | + |
| 116 | + check_bash |
| 117 | + |
| 118 | + return 0 |
| 119 | + fi |
| 120 | + return 1 |
| 121 | + else |
| 122 | + devtools=${PTOOLSPATH%/} |
| 123 | + if [ "${devtools}" != "${DIR}" ]; then |
| 124 | + printf "\n${PURPLE}Your environment variable \$PTOOLSPATH is outdated!${NC}" |
| 125 | + printf "\n${PURPLE}Current value: $devtools${NC}" |
| 126 | + printf "\n${PURPLE}New value: $DIR${NC}" |
| 127 | + printf "\nExit.\n\n" |
| 128 | + return 1 |
| 129 | + fi |
| 130 | + fi |
| 131 | + return 0 |
| 132 | +} |
| 133 | + |
| 134 | +init |
| 135 | + |
| 136 | +if check_install; then |
| 137 | + devtools=${PTOOLSPATH%/} |
| 138 | + php "$devtools/phalcon" $* |
| 139 | +fi |
0 commit comments