-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphing.sh
executable file
·172 lines (144 loc) · 4.41 KB
/
phing.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env sh
# configuration
phing=vendor/bin/phing
temporaryPhing=phing.phar
repositoryUrl=https://bitbucket.org/maxime-pasquier/phing-launcher
configurationDirectory=phing
phingLauncher=phing.sh
# phing parameters
debug=false
quiet=false
phingParameters=$(echo " $@ " | sed -e "s/ / /g" -e "s/ -\(q\(uiet\)\?\|S\|silent\) /#quiet#/g" -e "s/ -\(debug\|verbose\) /#debug#/g")
if echo $phingParameters | grep "#quiet#" > /dev/null
then
quiet=true
fi
if echo $phingParameters | grep "#debug#" > /dev/null
then
debug=true
fi
# functions
showMessage() {
message=$1
level=$2
if [ -z "$level" ]
then
level=" info"
fi
if $quiet
then
if [ "$level" != "error" ]
then
return
fi
fi
if [ "$level" = "debug" ]
then
if ! $debug
then
return
fi
fi
printf "$level > $message\n"
}
showTheHelpAndExit() {
showMessage "enjoy Phing! See the help below:\n"
exec $phing
}
if ! php -v > /dev/null 2>&1
then
showMessage "Unable to find PHP." "error"
showMessage "Try: apt-get install php"
exit 1
fi
if ! php -m | grep xmlreader > /dev/null
then
showMessage "Unable to find the XML module for PHP." "error"
showMessage "Try: apt-get install php-xml"
exit 1
fi
# read the "bin-dir" configuration setting in composer.json
composerBinDirectory=$(cat composer.json 2> /dev/null | sed 's/[" ]//g' | grep "config:" -A2 | grep "bin-dir:" | cut -d":" -f2)
if [ ! -z "$composerBinDirectory" ]
then
showMessage "reading the "bin-dir" configuration setting in composer.json: $composerBinDirectory" "debug"
fi
# read the COMPOSER_BIN_DIR environment variable
if [ ! -z "$COMPOSER_BIN_DIR" ]
then
composerBinDirectory=$COMPOSER_BIN_DIR
showMessage "reading the COMPOSER_BIN_DIR environment variable: $composerBinDirectory" "debug"
fi
if [ -d "$composerBinDirectory" ]
then
showMessage "using composer bin directory: $composerBinDirectory instead of $(dirname $phing)"
phing=$composerBinDirectory/$(basename $phing)
fi
# if file does not exists or file has not a size greater than zero.
if [ ! -s $phing ]
then
if [ -e $phing ]
then
showMessage "removing invalid file $phing (size equals zero)"
rm $phing
fi
if [ -s $temporaryPhing ]
then
if ! php $temporaryPhing > /dev/null
then
showMessage "removing invalid file $temporaryPhing (broken PHP phar)"
rm $temporaryPhing
elif ! head -1 $temporaryPhing | grep php > /dev/null
then
showMessage "removing invalid file $temporaryPhing (not a PHP phar)"
rm $temporaryPhing
fi
fi
if [ ! -s $temporaryPhing ]
then
showMessage "downloading $temporaryPhing from origin"
curl -L -sS -o $temporaryPhing http://www.phing.info/get/phing-latest.phar
if [ ! -s $temporaryPhing ]
then
showMessage "Unable to download the file." "error"
exit 1
fi
fi
showMessage "using $temporaryPhing instead of $phing"
phing="php $temporaryPhing"
else
if [ ! -x $phing ]
then
showMessage "adding executable mode to $phing"
chmod +x $phing
fi
if [ -f $temporaryPhing ]
then
showMessage "removing $temporaryPhing, phing already exists in $phing"
rm $temporaryPhing
fi
fi
if [ "$1" = "get-the-classics" -o "$1" = "gtc" ]
then
showMessage "getting the classics of Phing Launcher from the repository $repositoryUrl"
if [ ! -d $configurationDirectory ]
then
mkdir $configurationDirectory
fi
curl -sS -O $repositoryUrl/raw/master/build.xml \
&& cd $configurationDirectory \
&& curl -sS -O $repositoryUrl/raw/master/$configurationDirectory/composer.xml \
&& curl -sS -O $repositoryUrl/raw/master/$configurationDirectory/deptrac.xml \
&& curl -sS -O $repositoryUrl/raw/master/$configurationDirectory/phing.xml \
&& curl -sS -O $repositoryUrl/raw/master/$configurationDirectory/phpunit.xml \
&& curl -sS -O $repositoryUrl/raw/master/$configurationDirectory/symfony.xml \
&& cd - > /dev/null
showTheHelpAndExit
fi
if [ "$1" = "self-update" -o "$1" = "selfupdate" -o "$1" = "su" ]
then
showMessage "updating the Phing Launcher script from the repository $repositoryUrl"
curl -sS -O $repositoryUrl/raw/master/$phingLauncher
showTheHelpAndExit
fi
exec $phing "$@"