Repository navigation
Expand file tree
/
Copy pathfunction.inc.sh
More file actions
392 lines (335 loc) · 11.4 KB
/
Copy pathfunction.inc.sh
File metadata and controls
392 lines (335 loc) · 11.4 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/usr/bin/env bash
# Copyright:: Copyright (c) 2016 Been Kyung-yoon (http://www.php79.com/)
# License:: The MIT License (MIT)
STACK_VERSION=$(cat "${STACK_ROOT}/.app_version")
source "${STACK_ROOT}/includes/message.inc.sh"
### Config
source "${STACK_ROOT}/stack.defaults.conf"
if [ ! -f "${STACK_ROOT}/stack.conf" ]; then
notice "Check stack.conf (설치 옵션은 stack.conf 파일을 열어 수정하시면 됩니다.)"
echo -n " copy: "
cp -av "${STACK_ROOT}/stack.defaults.conf" "${STACK_ROOT}/stack.conf"
echo
fi
source "${STACK_ROOT}/stack.conf"
### OS detect
OS=
if [ -f /etc/rocky-release ]; then
RELEASE_VERSION=`grep -o 'release [0-9]\+' /etc/rocky-release`
if [ "$RELEASE_VERSION" = "release 8" ]; then
OS=rocky8
else
echo "Only Rocky Linux 8. (Rocky Linux 8 버전만 지원됩니다.)"
echo -n "Current version: " && cat /etc/rocky-release
abort
fi
elif [ -f /etc/centos-release ]; then
RELEASE_VERSION=`grep -o 'release [0-9]\+' /etc/centos-release`
if [ "$RELEASE_VERSION" = "release 7" ]; then
OS=centos7
elif [ "$RELEASE_VERSION" = "release 6" ]; then
OS=centos6
else
echo "Only CentOS 6/7. (CentOS 6/7 버전만 지원됩니다.)"
echo -n "Current version: " && cat /etc/centos-release
abort
fi
else
echo "Only Rocky Linux 8, CentOS 6/7. (Rocky Linux 8, CentOS 6/7 버전만 지원됩니다.)"
abort
fi
### systemctl detect
SYSTEMCTL=0
if [ -f /usr/bin/systemctl ]; then
SYSTEMCTL=1
fi
### Functions
FUNC_RESULT=
# 실행시 에러가 존재할 경우 중단
CMD_EXIT_CODE=
function cmd
{
#printf "${GREEN}run# ${1}${NO_COLOR}\n"
eval ${1}
CMD_EXIT_CODE=${?}
if [ ${CMD_EXIT_CODE} != "0" ]; then
outputError "다음 명령이 실패하여, 설치가 중단되었습니다. (exit code: ${CMD_EXIT_CODE})"
printf "\n"
outputError "# ${1}"
printf "\n"
exit 1
fi
}
# 명령을 파일로 남길 수 있도록 특수 문자 제거
function escape_path()
{
printf '%s' "${1}" | sed -e 's/[ \\\/^*+$]/\_/g'
}
# 성공한 경우 1회만 실행하여, 중복 실행 방지
function cmd_once
{
LOCK="locks/$(escape_path "${1}")"
if [ ! -f "${LOCK}" ]; then
cmd "${1}"
if [ ${CMD_EXIT_CODE} = "0" ]; then
touch "${LOCK}"
fi
fi
}
function welcome_short
{
echo
outputInfo "php79 stack"
printf " version "
outputComment "${STACK_VERSION}\n"
}
function welcome
{
welcome_short
if [ "$OS" = "rocky8" ]; then
echo " * PHP 5.6 ~ 8.4 + Nginx + Let's Encrypt + MariaDB installer"
else
echo " * PHP 5.3 ~ 8.3 + Nginx + Let's Encrypt + MariaDB installer"
fi
echo
}
function options
{
if [ ! -f "locks/scripts_init.sh" ]; then
printf " - Install ${GREEN}EPEL repo${NO_COLOR} / http://fedoraproject.org/wiki/EPEL\n"
fi
if [ ! -f "locks/scripts_php8-remi-install.sh_84" ]; then
if [ $PHP84 = "1" ]; then
if [ "$OS" = "rocky8" ]; then
printf " - Install ${GREEN}PHP 8.4${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
else
printf " - CentOS 7 에서는 ${GREEN}PHP 8.4${NO_COLOR} 를 지원하지 않습니다.\n"
fi
fi
fi
if [ ! -f "locks/scripts_php8-remi-install.sh_83" ]; then
if [ $PHP83 = "1" ]; then
printf " - Install ${GREEN}PHP 8.3${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
fi
if [ ! -f "locks/scripts_php8-remi-install.sh_82" ]; then
if [ $PHP82 = "1" ]; then
printf " - Install ${GREEN}PHP 8.2${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
fi
if [ ! -f "locks/scripts_php8-remi-install.sh_81" ]; then
if [ $PHP81 = "1" ]; then
printf " - Install ${GREEN}PHP 8.1${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
fi
if [ ! -f "locks/scripts_php8-remi-install.sh_80" ]; then
if [ $PHP80 = "1" ]; then
printf " - Install ${GREEN}PHP 8.0${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
fi
if [ ! -f "locks/scripts_php7-remi-install.sh_74" ]; then
if [ $PHP74 = "1" ]; then
printf " - Install ${GREEN}PHP 7.4${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
fi
if [ ! -f "locks/scripts_php7-remi-install.sh_73" ]; then
if [ $PHP73 = "1" ]; then
printf " - Install ${GREEN}PHP 7.3${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
fi
if [ ! -f "locks/scripts_php7-remi-install.sh_72" ]; then
if [ $PHP72 = "1" ]; then
printf " - Install ${GREEN}PHP 7.2${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
fi
if [ ! -f "locks/scripts_php7-remi-install.sh_71" ]; then
if [ $PHP71 = "1" ]; then
printf " - Install ${GREEN}PHP 7.1${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
fi
if [ ! -f "locks/scripts_php7-remi-install.sh_70" ]; then
if [ $PHP70 = "1" ]; then
printf " - Install ${GREEN}PHP 7.0${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
printf " ${YELLOW}PHP 7.0 have reached its \"End of Life\".${NO_COLOR} http://php.net/supported-versions.php\n"
fi
fi
if [ ! -f "locks/scripts_php5-remi-install.sh_56" ]; then
if [ $PHP56 = "1" ]; then
printf " - Install ${GREEN}PHP 5.6${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
printf " ${YELLOW}PHP 5.6 have reached its \"End of Life\".${NO_COLOR} http://php.net/supported-versions.php\n"
fi
fi
if [ ! -f "locks/scripts_php5-remi-install.sh_55" ]; then
if [ $PHP55 = "1" ]; then
if [ "$OS" = "rocky8" ]; then
printf " - Rocky Linux 8 에서는 ${GREEN}PHP 5.5${NO_COLOR} 를 지원하지 않습니다.\n"
else
printf " - Install ${GREEN}PHP 5.5${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
printf " ${YELLOW}PHP 5.5 have reached its \"End of Life\".${NO_COLOR} http://php.net/supported-versions.php\n"
fi
fi
fi
if [ ! -f "locks/scripts_php5-remi-install.sh_54" ]; then
if [ $PHP54 = "1" ]; then
if [ "$OS" = "rocky8" ]; then
printf " - Rocky Linux 8 에서는 ${GREEN}PHP 5.4${NO_COLOR} 를 지원하지 않습니다.\n"
else
printf " - Install ${GREEN}PHP 5.4${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
printf " ${YELLOW}PHP 5.4 have reached its \"End of Life\".${NO_COLOR} http://php.net/supported-versions.php\n"
fi
fi
fi
if [[ ! -f "locks/scripts_centos7-php53-install.sh" && ! -f "locks/scripts_centos6-php53-install.sh" ]]; then
if [ $PHP53 = "1" ]; then
if [ "$OS" = "rocky8" ]; then
printf " - Rocky Linux 8 에서는 ${GREEN}PHP 5.3${NO_COLOR} 을 지원하지 않습니다.\n"
else
if [ ${OS} = "centos7" ]; then
if [ ! -f "locks/scripts_centos7-php53-install.sh" ]; then
printf " - Install ${GREEN}PHP 5.3${NO_COLOR} / Source compile\n"
fi
else
if [ ! -f "locks/scripts_centos6-php53-install.sh" ]; then
printf " - Install ${GREEN}PHP 5.3${NO_COLOR} from Base repo\n"
fi
fi
printf " ${YELLOW}PHP 5.3 have reached its \"End of Life\".${NO_COLOR} http://php.net/supported-versions.php\n"
fi
fi
fi
if [ ! -z "$PHP_BASE" ]; then
if [ -f /usr/bin/php ]; then
USR_BIN_PHP_VERSION=`/usr/bin/php -r 'echo PHP_MAJOR_VERSION . PHP_MINOR_VERSION;'`
else
USR_BIN_PHP_VERSION=""
fi
if [ "${USR_BIN_PHP_VERSION}" != "${PHP_BASE}" ]; then
echo " - Set PHP CLI version ( /usr/bin/php ) : $PHP_BASE"
fi
fi
if [ ! -f "locks/scripts_nginx-install.sh" ]; then
if [ $NGINX = "1" ]; then
printf " - Install ${GREEN}Nginx 1.*${NO_COLOR} from Nginx repo (stable) / http://nginx.org/en/linux_packages.html\n"
fi
fi
if [ ! -f "locks/scripts_letsencrypt-install.sh" ]; then
if [ $LETSENCRYPT = "1" ]; then
printf " - Install ${GREEN}Let's Encrypt tools${NO_COLOR} (certbot-auto + configs) / https://certbot.eff.org/\n"
fi
fi
if [[ ! -f "locks/scripts_mariadb-repo-install.sh" && ! -f "locks/scripts_mariadb-install.sh_" ]]; then
if [ $MARIADB = "1" ]; then
if [[ "$OS" = "centos7" || "$OS" = "rocky8" ]]; then
printf " - Install ${GREEN}MariaDB ${MARIADB_VERSION}${NO_COLOR} from MariaDB repo (stable) / https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/\n"
else
printf " - Install ${GREEN}MariaDB 10.6${NO_COLOR} from MariaDB repo (stable) / https://mariadb.com/kb/en/mariadb/yum/\n"
fi
if [ ! -z $MARIADB_RAM ]; then
printf " Use memory config : ${YELLOW}${MARIADB_RAM}${NO_COLOR}\n"
fi
fi
fi
if [ ! -f "locks/scripts_smartd-install.sh" ]; then
if [ $SMARTD = "1" ]; then
echo " - Install smartmontools (physical server only)"
fi
fi
if [ ! -f "locks/scripts_lm-sensors-install.sh" ]; then
if [ $SENSORS = "1" ]; then
echo " - Install lm_sensors (physical server only)"
fi
fi
if [ ! -f "locks/scripts_dev-tools-install.sh" ]; then
if [ $DEV_TOOLS = "1" ]; then
echo " - Install developer tools (wget, rsync, nslookup, ...)"
fi
fi
if [ ! -f "locks/scripts_timezone.sh_Asia_Seoul" ]; then
if [ ! -z $TIMEZONE ]; then
printf " - Change time zone ${YELLOW}${TIMEZONE}${NO_COLOR} for /etc/localtime, php.ini\n"
fi
fi
if [ $INTERACTIVE = "1" ]; then
echo " - Interactive mode"
fi
}
function usage
{
welcome
echo "Select options from stack.conf:"
options
echo
echo "See http://www.php79.com for documents, updates."
}
function yum_install
{
PACKAGES=$@
is_installed ${PACKAGES}
if [ $FUNC_RESULT = "1" ]; then
echo "Already installed. -> $@"
echo -n
else
if [ ${YUM_INSTALL_QUIET} = "1" ]; then
yum -y -q install ${PACKAGES}
else
yum -y install ${PACKAGES}
fi
if [ ${?} != "0" ]; then
abort "yum 패키지 설치가 실패하였습니다.\n yum -y install ${PACKAGES}"
fi
fi
}
function is_installed
{
for i in "$@"
do
RESULT=`yum -C --noplugins -q list installed $i 2> /dev/null`
if [ ${?} != "0" ]; then
# notice "Not installed. -> ${i}"
FUNC_RESULT=0
return
fi
done
FUNC_RESULT=1
}
# 특수 문자(/)를 sed 사용을 위해 (//)로 치환. 단 echo 반환하면 안되므로 전역 변수로 고정
STRING_QUOTE=
function string_quote
{
QUOTE=\\\\
STRING_QUOTE=`echo ${@} | sed "s/\//"${QUOTE}"\//g"`
}
# mysql 비밀번호 입력을 일단 생략하고, 자동 설치후 변경 권장
MARIADB_SET_ROOT_PASSWORD=
function mariadb_set_root_password
{
if [[ `/usr/bin/mysqladmin ping` = "mysqld is alive" ]]; then
echo
stty -echo
status=1
while [ $status -eq 1 ]; do
outputQuestion "Set MariaDB root password! (MariaDB root 비밀번호를 지정하세요!) :"
read -p " " -r
if [ "${REPLY}" = "" ]; then
echo
echo
outputError "Warning) You can't use an empty password here. (빈 비밀번호는 사용할 수 없습니다.)"
echo
echo
elif [ ! ${#REPLY} -gt 8 ]; then
echo
echo
outputError "Warning) BAD PASSWORD: it is WAY too short. (비밀번호는 8자리 이상으로 입력해주세요)"
echo
echo
else
/usr/bin/mysqladmin password '$REPLY'
status=0
fi
done
stty echo
else
abort "MariaDB 가 실행되지 않아, root 비밀번호를 지정할 수 없습니다."
fi
MARIADB_SET_ROOT_PASSWORD=1
}