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