Repository navigation
Expand file tree
/
Copy pathfunction.inc.sh
More file actions
261 lines (213 loc) · 6.8 KB
/
Copy pathfunction.inc.sh
File metadata and controls
261 lines (213 loc) · 6.8 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
#!/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/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 CentOS 6/7. (CentOS 6/7 버전만 지원됩니다.)"
abort
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
echo " * PHP 5.3-7.3 + Nginx + Let's Encrypt + MariaDB installer"
echo
}
function options
{
printf " - Install ${GREEN}EPEL repo${NO_COLOR} / http://fedoraproject.org/wiki/EPEL\n"
if [ $PHP73 = "1" ]; then
printf " - Install ${GREEN}PHP 7.3${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
if [ $PHP72 = "1" ]; then
printf " - Install ${GREEN}PHP 7.2${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
if [ $PHP71 = "1" ]; then
printf " - Install ${GREEN}PHP 7.1${NO_COLOR} from Remi repo / http://rpms.famillecollet.com/\n"
fi
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
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
if [ $PHP55 = "1" ]; then
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
if [ $PHP54 = "1" ]; then
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
if [ $PHP53 = "1" ]; then
if [ ${OS} = "centos7" ]; then
printf " - Install ${GREEN}PHP 5.3${NO_COLOR} / Source compile\n"
else
printf " - Install ${GREEN}PHP 5.3${NO_COLOR} from Base repo\n"
fi
printf " ${YELLOW}PHP 5.3 have reached its \"End of Life\".${NO_COLOR} http://php.net/supported-versions.php\n"
fi
echo " - Set PHP CLI version ( /usr/bin/php ) : $PHP_BASE"
if [ $NGINX = "1" ]; then
printf " - Install ${GREEN}Nginx 1.*${NO_COLOR} from Nginx repo (stable) / http://nginx.org/en/linux_packages.html\n"
fi
if [ $LETSENCRYPT = "1" ]; then
printf " - Install ${GREEN}Let's Encrypt tools${NO_COLOR} (certbot-auto + configs) / https://certbot.eff.org/\n"
fi
if [ $MARIADB = "1" ]; then
printf " - Install ${GREEN}MariaDB 10.3${NO_COLOR} from MariaDB repo (stable) / https://mariadb.com/kb/en/mariadb/yum/\n"
if [ ! -z $MARIADB_RAM ]; then
printf " Use memory config : ${YELLOW}${MARIADB_RAM}${NO_COLOR}\n"
fi
fi
if [ $SMARTD = "1" ]; then
echo " - Install smartmontools (physical server only)"
fi
if [ $SENSORS = "1" ]; then
echo " - Install lm_sensors (physical server only)"
fi
if [ $DEV_TOOLS = "1" ]; then
echo " - Install developer tools (wget, rsync, nslookup, ...)"
fi
if [ ! -z $TIMEZONE ]; then
printf " - Change time zone ${YELLOW}${TIMEZONE}${NO_COLOR} for /etc/localtime, php.ini\n"
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
{
is_installed $@
if [ $FUNC_RESULT = "1" ]; then
#echo "Already installed. -> $@"
echo -n
else
yum -y install $@
fi
}
function is_installed
{
for i in "$@"
do
RESULT=`yum -C --noplugins -q list installed $i 2> /dev/null`
if [[ ! $RESULT == *"$i"* ]]; then
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
}