This repository was archived by the owner on Jun 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate
executable file
·302 lines (263 loc) · 12.3 KB
/
update
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
# DevA - Web Development Environment
# Created by Miguel Nunes
# https://github.com/mignz/DevA
# ------------------------------------------------------------------------------
# Text colors
function red {
echo -e "\\033[91m$1\\033[39m"
}
function green {
echo -e "\\033[92m$1\\033[39m"
}
# ------------------------------------------------------------------------------
# Detect OS
case "$(uname -s)" in
Linux*) os=linux;;
Darwin*) os=macos;;
*) red "Invalid operating system! Only macOS and Ubuntu supported."; exit 1;;
esac
# ------------------------------------------------------------------------------
# Paths & OS specific configuration
if [ "$os" == "macos" ]; then
path_nginx=/usr/local/etc/nginx
path_php=/usr/local/etc/php/7.2
else
path_nginx=/etc/nginx
path_php=/etc/php/7.2/fpm
fi
# ------------------------------------------------------------------------------
# Preflight Checks
if [ ! "$EUID" -ne 0 ]; then
red "Plese do NOT run as admin!"
exit 1
fi
if [ ! -f /usr/local/etc/nginx/deva/deva.conf ] && [ ! -f /etc/nginx/deva/deva.conf ]; then
red "DevA not installed!"
exit 1
fi
# ------------------------------------------------------------------------------
# Helpers
function currentVersion {
grep "this_update=" /usr/local/DevA/deva | cut -d "=" -f 2
}
function get {
data=$(curl -SsL "https://raw.githubusercontent.com/mignz/DevA/master/$1")
if [ $# -eq 1 ]; then
echo "$data"
else
echo "Fetching $1 from Git repository ..."
echo "$data" | sudo tee "$2"
fi
}
function perms {
if [ "$os" == "macos" ]; then
sudo chown -R "$(whoami)":admin /usr/local/DevA
sudo chown -R "$(whoami)":admin /usr/local/etc/nginx
else
sudo chown -R "$(whoami)":"$(whoami)" /usr/local/DevA
sudo chown -R root:root /etc/nginx
fi
}
function replace {
if [ $os == "macos" ]; then
sudo sed -i '' "s@$1@$2@g" "$3"
else
sudo sed -i "s@$1@$2@g" "$3"
fi
}
profile_newline=0
function profile {
path_profile=~/.bash_profile
[ $os == "linux" ] && path_profile=~/.profile
if ! grep -q "$1" $path_profile; then
if [[ -s $path_profile ]] && [ $profile_newline -eq 0 ]; then
echo "" >> $path_profile
fi
echo -e "$2" >> $path_profile
profile_newline=1
fi
}
# ------------------------------------------------------------------------------
# Updates
function __9 {
get "deva/deva" "/usr/local/DevA/deva"
get "deva/scripts/backup" "/usr/local/DevA/scripts/backup"
get "deva/scripts/changelog" "/usr/local/DevA/scripts/changelog"
get "deva/scripts/doctor" "/usr/local/DevA/scripts/doctor"
get "deva/scripts/hosts" "/usr/local/DevA/scripts/hosts"
get "deva/scripts/hosts_add" "/usr/local/DevA/scripts/hosts_add"
get "deva/scripts/hosts_default" "/usr/local/DevA/scripts/hosts_default"
get "deva/scripts/hosts_edit" "/usr/local/DevA/scripts/hosts_edit"
get "deva/scripts/hosts_remove" "/usr/local/DevA/scripts/hosts_remove"
get "deva/scripts/permissions" "/usr/local/DevA/scripts/permissions"
get "deva/scripts/phpinfo" "/usr/local/DevA/scripts/phpinfo"
get "deva/scripts/restore" "/usr/local/DevA/scripts/restore"
get "deva/scripts/services" "/usr/local/DevA/scripts/services"
get "deva/scripts/updates" "/usr/local/DevA/scripts/updates"
}
function __10 {
get "deva/deva" "/usr/local/DevA/deva"
if [ $os == "macos" ]; then
brew unlink php71
brew services stop php71
brew remove php71-gmp php71-opcache php71-phalcon php71-pspell php71-redis php71-tidy php71-xdebug php71-memcached php71-mcrypt php71-imagick php71-igbinary
brew remove php71
rm -rf /usr/local/etc/php/7.1
brew install \
php72 \
php72-gmp \
php72-opcache \
php72-phalcon \
php72-pspell \
php72-redis \
php72-tidy \
php72-xdebug
echo "include=$path_php/deva_php-fpm.conf" | tee "$path_php/php-fpm.conf"
get "conf/php/fpm-macos.conf" "$path_php/deva_php-fpm.conf"
replace ';cgi.fix_pathinfo=1' 'cgi.fix_pathinfo=0' $path_php/php.ini
replace ';opcache.enable=1' 'opcache.enable=0' $path_php/php.ini
replace 'allow_url_fopen = On' 'allow_url_fopen = Off' $path_php/php.ini
replace 'display_errors = Off' 'display_errors = On' $path_php/php.ini
replace 'display_startup_errors = Off' 'display_startup_errors = On' $path_php/php.ini
replace 'log_errors = On' 'log_errors = Off' $path_php/php.ini
replace ';date.timezone =' 'date.timezone = "Atlantic\/Azores"' $path_php/php.ini
replace 'error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT' 'error_reporting = E_ALL' $path_php/php.ini
replace 'upload_max_filesize = 2M' 'upload_max_filesize = 1G' $path_php/php.ini
replace 'post_max_size = 8M' 'post_max_size = 1G' $path_php/php.ini
replace ';session.save_path = "/tmp"' 'session.save_path = "/usr/local/var/tmp"' $path_php/php.ini
replace 'disable_functions =' 'disable_functions = exec,pcntl_exec,system,proc_nice,popen,pclose,curl_multi_exec,parse_ini_file,ini_get_all,ini_restore,show_source,eval,assert,dl,apache_note,apache_setenv,closelog,debugger_off,debugger_on,define_syslog_variables,openlog,syslog,url_exec,inject_code,phpAds_remoteInfo,phpAds_XmlRpc,phpAds_xmlrpcDecode,phpAds_xmlrpcEncode,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,posix_uname,xmlrpc_entity_decode,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_getpriority,pcntl_setpriority,opcache_get_status' $path_php/php.ini
echo -e "\\n; Xdebug configuration for DevA\\nxdebug.var_display_max_depth = -1\\nxdebug.var_display_max_children = -1\\nxdebug.var_display_max_data = -1" | tee -a $path_php/php.ini
profile "/usr/local/opt/php71/bin" "export PATH=\"/usr/local/opt/php71/bin:\$PATH\""
replace 'php71' 'php72' ~/.bash_profile
brew services restart php72
brew cleanup
else
sudo service php7.1-fpm stop
sudo apt-get purge php7.1.*
rm -rf /etc/php/7.1
sudo apt-get install -y \
php7.2 \
php7.2-bcmath \
php7.2-bz2 \
php7.2-cgi \
php7.2-cli \
php7.2-curl \
php7.2-dev \
php7.2-dba \
php7.2-enchant \
php7.2-fpm \
php7.2-gd \
php7.2-gmp \
php7.2-imap \
php7.2-intl \
php7.2-json \
php7.2-mbstring \
php7.2-mysql \
php7.2-opcache \
php7.2-phalcon \
php7.2-pspell \
php7.2-readline \
php7.2-sqlite3 \
php7.2-tidy \
php7.2-xml \
php7.2-xmlrpc \
php7.2-zip \
php-imagick \
php-xdebug
echo "include=$path_php/deva_php-fpm.conf" | sudo tee "$path_php/php-fpm.conf"
get "conf/php/fpm-linux.conf" "$path_php/deva_php-fpm.conf" --sudo
replace ';cgi.fix_pathinfo=1' 'cgi.fix_pathinfo=0' $path_php/php.ini
replace ';opcache.enable=0' 'opcache.enable=0' $path_php/php.ini
replace ';opcache.enable=1' 'opcache.enable=0' $path_php/php.ini
replace 'allow_url_fopen = On' 'allow_url_fopen = Off' $path_php/php.ini
replace 'display_errors = Off' 'display_errors = On' $path_php/php.ini
replace 'display_startup_errors = Off' 'display_startup_errors = On' $path_php/php.ini
replace 'log_errors = On' 'log_errors = Off' $path_php/php.ini
replace ';date.timezone =' 'date.timezone = "Atlantic\/Azores"' $path_php/php.ini
replace 'error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT' 'error_reporting = E_ALL' $path_php/php.ini
replace 'upload_max_filesize = 2M' 'upload_max_filesize = 1G' $path_php/php.ini
replace 'post_max_size = 8M' 'post_max_size = 1G' $path_php/php.ini
replace ';session.save_path = "/tmp"' 'session.save_path = "/usr/local/var/tmp"' $path_php/php.ini
replace 'disable_functions =' 'disable_functions = exec,pcntl_exec,system,proc_nice,popen,pclose,curl_multi_exec,parse_ini_file,ini_get_all,ini_restore,show_source,eval,assert,dl,apache_note,apache_setenv,closelog,debugger_off,debugger_on,define_syslog_variables,openlog,syslog,url_exec,inject_code,phpAds_remoteInfo,phpAds_XmlRpc,phpAds_xmlrpcDecode,phpAds_xmlrpcEncode,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,posix_uname,xmlrpc_entity_decode,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_getpriority,pcntl_setpriority,opcache_get_status' $path_php/php.ini
echo -e "\\n; Xdebug configuration for DevA\\nxdebug.var_display_max_depth = -1\\nxdebug.var_display_max_children = -1\\nxdebug.var_display_max_data = -1" | sudo tee -a $path_php/php.ini
sudo service php7.2-fpm restart
sudo apt-get clean
sudo apt-get -y autoremove
fi
}
function __11 {
get "deva/deva" "/usr/local/DevA/deva"
if [ $os == "macos" ]; then
sed -i '' 's/disable_functions = .*/disable_functions = apache_child_terminate,apache_get_modules,apache_note,apache_setenv,dl,define_syslog_variables,eval,ftp_connect,ini_get_all,passthru,phpAds_remoteInfo,phpAds_XmlRpc,phpAds_xmlrpcDecode,phpAds_xmlrpcEncode,popen,proc_open,proc_close,xmlrpc_entity_decode,curl_multi_exec,parse_ini_file,show_source,pcntl_exec,php_uname/g' $path_php/php.ini
brew uninstall --ignore-dependencies php72
brew install php72 --with-argon2
brew install php72-imagick
brew services restart php72
else
sed -i 's/disable_functions = .*/disable_functions = apache_child_terminate,apache_get_modules,apache_note,apache_setenv,dl,define_syslog_variables,eval,ftp_connect,ini_get_all,passthru,phpAds_remoteInfo,phpAds_XmlRpc,phpAds_xmlrpcDecode,phpAds_xmlrpcEncode,popen,proc_open,proc_close,xmlrpc_entity_decode,curl_multi_exec,parse_ini_file,show_source,pcntl_exec,php_unam/g' $path_php/php.ini
sudo service php7.2-fpm restart
fi
}
function __12 {
get "deva/deva" "/usr/local/DevA/deva"
get "deva/scripts/hosts_add" "/usr/local/DevA/scripts/hosts_add"
get "deva/scripts/hosts_edit" "/usr/local/DevA/scripts/hosts_edit"
for f in $path_nginx/deva/vhosts/*.dev.conf
do
host="$(basename "$f" .dev.conf)"
replace "server_name $host.dev;" "server_name $host.localhost;" "$f"
sudo mv "$f" "$path_nginx/deva/vhosts/$host.localhost.conf"
done
replace ".dev" ".localhost" /etc/hosts
if [ $os == "macos" ]; then
sudo brew services restart nginx
else
sudo service nginx restart
fi
}
function __13 {
get "deva/deva" "/usr/local/DevA/deva"
get "deva/scripts/hosts_add" "/usr/local/DevA/scripts/hosts_add"
get "deva/scripts/hosts_edit" "/usr/local/DevA/scripts/hosts_edit"
get "deva/scripts/restore" "/usr/local/DevA/scripts/restore"
for f in $path_nginx/deva/vhosts/*.localhost.conf
do
host="$(basename "$f" .localhost.conf)"
replace "server_name $host.localhost;" "server_name $host.test;" "$f"
sudo mv "$f" "$path_nginx/deva/vhosts/$host.test.conf"
done
replace ".localhost" ".test" /etc/hosts
if [ $os == "macos" ]; then
sudo brew services restart nginx
else
sudo service nginx restart
fi
}
# ------------------------------------------------------------------------------
# Run Updater
lv=$(get "update.txt")
cv=$(currentVersion)
if [ "$cv" -lt 9 ]; then
green "You cannot upgrade from this version, 9+ required!"
rm -f "$0"
exit 0
fi
if [ "$cv" -eq "$lv" ]; then
green "You already have the latest version!"
rm -f "$0"
exit 0
fi
clear
echo -e "This will update DevA from Update $cv to Update $lv.\\n\\nPress ENTER to continue ..."
read -r
for ((i=cv+1; i < lv + 1; i++))
do
echo "Running Update $i ..."
__${i}
perms
done
clear
green "Update complete!"
rm -f "$0"
exit 0