@wjwjq/release-helper 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/.release/release.conf.yaml +4 -1
  2. package/dist/deploy/pkg/nginx_binary/compile.sh +37 -0
  3. package/dist/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
  4. package/dist/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
  5. package/dist/deploy/pkg/nginx_binary/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
  6. package/dist/deploy/script/common.sh +30 -1
  7. package/dist/deploy/script/install.sh +0 -44
  8. package/dist/deploy/script/nginx.sh +87 -5
  9. package/dist/deploy/script/prompt.sh +13 -1
  10. package/dist/deploy/script/upgrade.sh +0 -43
  11. package/dist/pack.js +8 -1
  12. package/dist/prepare.js +7 -1
  13. package/package.json +2 -2
  14. package/src/.release/release.conf.yaml +4 -1
  15. package/src/deploy/pkg/nginx_binary/compile.sh +37 -0
  16. package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
  17. package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
  18. package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
  19. package/src/deploy/script/common.sh +30 -1
  20. package/src/deploy/script/install.sh +0 -44
  21. package/src/deploy/script/nginx.sh +87 -5
  22. package/src/deploy/script/prompt.sh +13 -1
  23. package/src/deploy/script/upgrade.sh +0 -43
  24. package/src/pack.ts +11 -2
  25. package/src/prepare.ts +12 -2
  26. package/dist/deploy/nginx/README.md +0 -1
  27. package/dist/deploy/nginx/pkg/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
  28. package/dist/deploy/nginx/pkg/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
  29. package/dist/deploy/nginx/pkg/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
  30. package/dist/deploy/nginx/script/common.sh +0 -178
  31. package/dist/deploy/nginx/script/compile.sh +0 -11
  32. package/dist/deploy/nginx/script/fix.sh +0 -24
  33. package/dist/deploy/nginx/script/https.sh +0 -79
  34. package/dist/deploy/nginx/script/install.sh +0 -95
  35. package/dist/deploy/nginx/script/prompt.sh +0 -10
  36. package/dist/deploy/nginx/script/upgrade.sh +0 -7
  37. package/src/deploy/nginx/README.md +0 -1
  38. package/src/deploy/nginx/pkg/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
  39. package/src/deploy/nginx/pkg/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
  40. package/src/deploy/nginx/pkg/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
  41. package/src/deploy/nginx/script/common.sh +0 -178
  42. package/src/deploy/nginx/script/compile.sh +0 -11
  43. package/src/deploy/nginx/script/fix.sh +0 -24
  44. package/src/deploy/nginx/script/https.sh +0 -79
  45. package/src/deploy/nginx/script/install.sh +0 -95
  46. package/src/deploy/nginx/script/prompt.sh +0 -10
  47. package/src/deploy/nginx/script/upgrade.sh +0 -7
  48. /package/dist/deploy/{nginx/pkg → pkg/nginx_binary}/nginx-arm-ssl1.1.1.tar.gz +0 -0
  49. /package/src/deploy/{nginx/pkg → pkg/nginx_binary}/nginx-arm-ssl1.1.1.tar.gz +0 -0
@@ -9,4 +9,7 @@ assetsDir: 'dist'
9
9
 
10
10
  # nginx和assets 所属用户和用户组
11
11
  user: root
12
- userGroup: root
12
+ userGroup: root
13
+
14
+ # 指定安装模式 standalone(supervisor) 、 cluster(agent\systemd) 、 both
15
+ installMode: both
@@ -0,0 +1,37 @@
1
+ #!/bin/bash
2
+ # current nginx source code version 1.22.1
3
+
4
+ ./configure \
5
+ --prefix=/etc/nginx \
6
+ --conf-path=/etc/nginx/nginx.conf \
7
+ --error-log-path=/var/log/nginx/error.log \
8
+ --http-log-path=/var/log/nginx/access.log \
9
+ --pid-path=/var/run/nginx/nginx.pid \
10
+ --lock-path=/var/run/nginx/nginx.lock \
11
+ --with-http_ssl_module \
12
+ --with-http_v2_module \
13
+ --with-http_gzip_static_module \
14
+ --with-http_stub_status_module \
15
+ --with-stream \
16
+ --with-pcre
17
+
18
+ make
19
+
20
+ make install
21
+
22
+ echo '------------------compile and install done----------------------------'
23
+
24
+ arch=$(uname -m)
25
+ ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
26
+
27
+ if [[ -z "${arch}" ]]; then
28
+ arch="x86_64"
29
+ fi
30
+
31
+ if [[ -z "${ssl_version}" ]]; then
32
+ ssl_version="1.0.2"
33
+ fi
34
+
35
+ tar -zcvf nginx-"$arch"-ssl"$ssl_version".tar.gz /etc/nginx/ -C /root
36
+
37
+ echo "-----------pack at: /root nginx-"$arch"-ssl"$ssl_version".tar.gz--------------"
@@ -133,7 +133,36 @@ install_assets() {
133
133
  }
134
134
 
135
135
  start() {
136
- log "-----------execute ${app_name} script-------------"
136
+ # 未安装
137
+ if ((has_nginx_installed == 0)); then
138
+ install_nginx_binary
139
+
140
+ if [[ $? != 0 ]]; then
141
+ echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
142
+ exit 1
143
+ fi
144
+ fi
145
+
146
+ # 已安装 询问是否更新nginx
147
+ if ((has_nginx_installed == 1)); then
148
+ while true; do
149
+ read -r -p "Nginx has been installed, re-install it?[Y/N]" yn
150
+ case $yn in
151
+ [Yy]*)
152
+ install_nginx_binary
153
+
154
+ if [[ $? != 0 ]]; then
155
+ echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
156
+ exit 1
157
+ fi
158
+ break
159
+ ;;
160
+ [Nn]*) break ;;
161
+ *) echo "Please answer yes or no." ;;
162
+ esac
163
+ done
164
+ fi
165
+
137
166
  # 创建用户
138
167
  create_user_csri
139
168
 
@@ -4,48 +4,4 @@ basepath=$(dirname "$(realpath "${BASH_SOURCE[-1]}")")
4
4
 
5
5
  source "$basepath"/common.sh
6
6
 
7
- # 未安装
8
- if ((has_nginx_installed == 0)); then
9
- # while true; do
10
- # read -r -p "Nginx not found, install it?[Y/N]" yn
11
- # case $yn in
12
- # [Yy]*)
13
- # chmod +x "$basepath"/../nginx/script/install.sh
14
- # sh "$basepath"/../nginx/script/install.sh
15
- # break
16
- # ;;
17
- # [Nn]*) exit ;;
18
- # *) echo "Please answer yes or no." ;;
19
- # esac
20
- # done
21
- chmod +x "$basepath"/../nginx/script/install.sh
22
- sh "$basepath"/../nginx/script/install.sh
23
-
24
- if [[ $? != 0 ]]; then
25
- echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
26
- exit 1
27
- fi
28
- fi
29
-
30
- # 已安装 询问是否更新nginx
31
- if ((has_nginx_installed == 1)); then
32
- while true; do
33
- read -r -p "Nginx has been installed, re-install it?[Y/N]" yn
34
- case $yn in
35
- [Yy]*)
36
- chmod +x "$basepath"/../nginx/script/install.sh
37
- sh "$basepath"/../nginx/script/install.sh "${@}"
38
-
39
- if [[ $? != 0 ]]; then
40
- echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
41
- exit 1
42
- fi
43
- break
44
- ;;
45
- [Nn]*) break ;;
46
- *) echo "Please answer yes or no." ;;
47
- esac
48
- done
49
- fi
50
-
51
7
  start
@@ -1,14 +1,15 @@
1
1
  #!/bin/bash
2
- # 指定安装目录
3
- # nginx_conf_install_path="$prefix/etc/nginx_instances/${app_name}/"
4
- nginx_conf_install_path="$prefix/opt/${app_name}/nginx/"
5
2
 
6
3
  # 安装包所在路径
7
4
  pkg_path="${project_path}/pkg"
8
5
 
6
+ #------------------------------------ nginx服务配置文件服务 start----------------------------------
9
7
  # 配置文件所在路径
10
8
  new_nginx_conf_path="${pkg_path}/nginx"
11
9
 
10
+ # 指定安装目录
11
+ nginx_conf_install_path="$prefix/opt/${app_name}/nginx/"
12
+
12
13
  # nginx服务配置文件路径
13
14
  nginx_conf_path="${nginx_conf_install_path}nginx.conf"
14
15
 
@@ -21,8 +22,6 @@ nginx_pid_file_path="$nginx_pid_dir${app_name}.nginx.pid"
21
22
  conf_version=$(awk '{print $1}' "${pkg_path}"/version)
22
23
  echo "$conf_version"
23
24
 
24
-
25
-
26
25
  copy_nginx_conf_and_write_verison() {
27
26
  mkdir -p "$nginx_conf_install_path"
28
27
  # 创建pid目录
@@ -171,3 +170,86 @@ add_nginx_service() {
171
170
  rm -rf /usr/lib/systemd/system/"$app_name".nginx.service
172
171
  fi
173
172
  }
173
+ #------------------------------------ nginx服务配置文件服务 end----------------------------------
174
+
175
+
176
+ #------------------------------------ nginx 可执行程序相关 start----------------------------------
177
+ # 指定安装目录
178
+ nginx_binary_install_path="/etc/nginx/"
179
+
180
+ mkdir -p "$nginx_binary_install_path"
181
+
182
+ # 安装包所在路径
183
+ nginx_binary_pkg_path="${pkg_path}/nginx_binary"
184
+
185
+ open_port_80() {
186
+ # 查看防火墙是否开启
187
+ systemctl status firewalld
188
+ # 若未开启则开启
189
+ systemctl start firewalld
190
+
191
+ # 查看所有开启的端口
192
+ #firewall-cmd --list-ports
193
+
194
+ # 开启nginx默认80端口(关键步骤一)
195
+ firewall-cmd --zone=public --add-port=80/tcp --permanent
196
+
197
+ # 重启防火墙(关键步骤二)
198
+ firewall-cmd --reload
199
+ }
200
+
201
+ # 安装nginx可执行程序
202
+ install_nginx_binary() {
203
+ log "install nginx to path: ${nginx_binary_install_path}"
204
+
205
+ arch=$(uname -m)
206
+ ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
207
+
208
+ if [[ -z "${arch}" ]]; then
209
+ arch="x86_64"
210
+ fi
211
+
212
+ if [[ $arch == arm* ]] || [[ $arch = aarch64 ]]; then
213
+ arch="arm"
214
+ fi
215
+
216
+ if [[ "${ssl_version}" == "1.0" ]]; then
217
+ ssl_version="1.0.2"
218
+ fi
219
+
220
+ if [[ "${ssl_version}" == "1.1" ]]; then
221
+ ssl_version="1.1.1"
222
+ fi
223
+
224
+ if [[ "${ssl_version}" == "3.0" ]]; then
225
+ ssl_version="3.0.7"
226
+ fi
227
+
228
+ if [[ -z "${ssl_version}" ]]; then
229
+ ssl_version="1.0.2"
230
+ fi
231
+
232
+ pkg="$nginx_binary_pkg_path"/nginx-"$arch"-ssl"$ssl_version".tar.gz
233
+
234
+ if [ ! -f "$pkg" ]; then
235
+ log_error "Fatal error: nginx-$arch-ssl$ssl_version.tar.gz not matched! contact developer!"
236
+ exit 1
237
+ fi
238
+
239
+ log "current arch: $arch, current ssl_version: $ssl_version"
240
+
241
+ tar -zxvhf "$pkg" -C "$nginx_binary_install_path" --strip-components 1
242
+ # 检测是否安装成功
243
+ if [[ $? == 0 ]]; then
244
+ log_success "nginx installation successfully!"
245
+ else
246
+ log_error "nginx installation failed!"
247
+ fi
248
+
249
+ cp "$nginx_binary_install_path"sbin/nginx /usr/sbin/
250
+
251
+ # 修改/etc/nginx 用户(组)
252
+ chown -R $user:$usergroup "$nginx_binary_install_path"
253
+ chmod 744 -R "$nginx_binary_install_path"
254
+ }
255
+ #------------------------------------ nginx 可执行程序相关 end ----------------------------------
@@ -6,7 +6,18 @@ log "-----------receive parameter: $@------------"
6
6
  # exit 1
7
7
  # fi
8
8
 
9
- mode=""
9
+ mode="__INSTALL_MODE__"
10
+
11
+ if [[ "${mode}" == "standalone" ]]; then
12
+ mode=1
13
+ elif [[ "${mode}" == "cluster" ]]; then
14
+ mode=2
15
+ else
16
+ mode=''
17
+ fi
18
+
19
+
20
+ if [[ -z "${mode}" ]]; then
10
21
  while [ $# -gt 0 ]; do
11
22
  case "$1" in
12
23
  -S | -standalone)
@@ -58,6 +69,7 @@ while [ $# -gt 0 ]; do
58
69
  ;;
59
70
  esac
60
71
  done
72
+ fi
61
73
 
62
74
  if [[ -z "${mode}" ]]; then
63
75
  log_error "Fatal error: parameter -standalone or -cluster is required!"
@@ -4,47 +4,4 @@ basepath=$(dirname "$(realpath "${BASH_SOURCE[-1]}")")
4
4
 
5
5
  source "$basepath"/common.sh
6
6
 
7
- # 未安装
8
- if ((has_nginx_installed == 0)); then
9
- # while true; do
10
- # read -r -p "Nginx not found, install it?[Y/N]" yn
11
- # case $yn in
12
- # [Yy]*)
13
- # chmod +x "$basepath"/../nginx/script/install.sh
14
- # sh "$basepath"/../nginx/script/install.sh
15
- # break
16
- # ;;
17
- # [Nn]*) exit ;;
18
- # *) echo "Please answer yes or no." ;;
19
- # esac
20
- # done
21
- chmod +x "$basepath"/../nginx/script/install.sh
22
- sh "$basepath"/../nginx/script/install.sh "${@}"
23
-
24
- if [[ $? != 0 ]]; then
25
- echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
26
- exit 1
27
- fi
28
- fi
29
-
30
- # 已安装 询问是否更新nginx
31
- if ((has_nginx_installed == 1)); then
32
- while true; do
33
- read -r -p "Nginx has been installed, re-install it?[Y/N]" yn
34
- case $yn in
35
- [Yy]*)
36
- chmod +x "$basepath"/../nginx/script/install.sh
37
- sh "$basepath"/../nginx/script/install.sh "${@}"
38
- if [[ $? != 0 ]]; then
39
- echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
40
- exit 1
41
- fi
42
- break
43
- ;;
44
- [Nn]*) break ;;
45
- *) echo "Please answer yes or no." ;;
46
- esac
47
- done
48
- fi
49
-
50
7
  start
package/dist/pack.js CHANGED
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import * as inquirer from '@inquirer/prompts';
4
4
  import pc from 'picocolors';
5
5
  import * as tar from 'tar';
6
- import { __work_dir, __releaseDir, __dirname, releaseConf } from './prepare.js';
6
+ import { checkEnvInfo, __work_dir, __releaseDir, __dirname, releaseConf } from './prepare.js';
7
7
  import { logger } from './logger.js';
8
8
  import 'yaml';
9
9
  import 'execa';
@@ -11,6 +11,7 @@ import 'node:url';
11
11
 
12
12
  async function pack(version) {
13
13
  try {
14
+ await checkEnvInfo();
14
15
  if (version === void 0) {
15
16
  version = await inquirer.input(
16
17
  {
@@ -50,6 +51,12 @@ async function pack(version) {
50
51
  ["__USER_GROUP__", releaseConf.userGroup]
51
52
  ]
52
53
  });
54
+ replaceFileContent({
55
+ filePath: path.resolve(projectDir, "script", "prompt.sh"),
56
+ replaced: [
57
+ ["__INSTALL_MODE__", releaseConf.installMode]
58
+ ]
59
+ });
53
60
  logger.info(pc.green(`start to replace version: ${version} in index.html`));
54
61
  replaceFileContent({
55
62
  filePath: path.resolve(assetsDir, "index.html"),
package/dist/prepare.js CHANGED
@@ -7,6 +7,7 @@ import { fileURLToPath } from 'node:url';
7
7
  import { logger } from './logger.js';
8
8
  import 'picocolors';
9
9
 
10
+ const installMode = ["standalone", "cluster", "both"];
10
11
  const __work_dir = process.env.INIT_CWD || process.cwd();
11
12
  const __releaseDir = path.resolve(__work_dir, ".release");
12
13
  const __filename = fileURLToPath(import.meta.url);
@@ -29,7 +30,8 @@ const releaseConf = Object.assign({
29
30
  /** 打包后资源 相对工作区所在路径 默认dist/*/
30
31
  assetsDir: "dist",
31
32
  user: "root",
32
- userGroup: "root"
33
+ userGroup: "root",
34
+ installMode: "both"
33
35
  }, parseConf(__releaseConfPath));
34
36
  const $ = execa({ encoding: "utf8" });
35
37
  async function prepare() {
@@ -72,6 +74,10 @@ async function checkEnvInfo() {
72
74
  logger.error(`The field: [${field}] is required in .release/release.conf.yaml!`);
73
75
  process.exit(1);
74
76
  }
77
+ if (field === "installMode" && !installMode.includes(value)) {
78
+ logger.error(`The field: [${field}]'s value should be one of ${installMode.join(" | ")}`);
79
+ process.exit(1);
80
+ }
75
81
  }
76
82
  }
77
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wjwjq/release-helper",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "generate deployment package for frontend, include nginx...",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -65,7 +65,7 @@
65
65
  "scripts": {
66
66
  "localpack": "pnpm link --global",
67
67
  "postinstall": "node dist/start_prepare.js",
68
- "build": "rollup -c",
68
+ "build": "rm -rf dist && rollup -c",
69
69
  "prepublish": "pnpm build"
70
70
  }
71
71
  }
@@ -9,4 +9,7 @@ assetsDir: 'dist'
9
9
 
10
10
  # nginx和assets 所属用户和用户组
11
11
  user: root
12
- userGroup: root
12
+ userGroup: root
13
+
14
+ # 指定安装模式 standalone(supervisor) 、 cluster(agent\systemd) 、 both
15
+ installMode: both
@@ -0,0 +1,37 @@
1
+ #!/bin/bash
2
+ # current nginx source code version 1.22.1
3
+
4
+ ./configure \
5
+ --prefix=/etc/nginx \
6
+ --conf-path=/etc/nginx/nginx.conf \
7
+ --error-log-path=/var/log/nginx/error.log \
8
+ --http-log-path=/var/log/nginx/access.log \
9
+ --pid-path=/var/run/nginx/nginx.pid \
10
+ --lock-path=/var/run/nginx/nginx.lock \
11
+ --with-http_ssl_module \
12
+ --with-http_v2_module \
13
+ --with-http_gzip_static_module \
14
+ --with-http_stub_status_module \
15
+ --with-stream \
16
+ --with-pcre
17
+
18
+ make
19
+
20
+ make install
21
+
22
+ echo '------------------compile and install done----------------------------'
23
+
24
+ arch=$(uname -m)
25
+ ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
26
+
27
+ if [[ -z "${arch}" ]]; then
28
+ arch="x86_64"
29
+ fi
30
+
31
+ if [[ -z "${ssl_version}" ]]; then
32
+ ssl_version="1.0.2"
33
+ fi
34
+
35
+ tar -zcvf nginx-"$arch"-ssl"$ssl_version".tar.gz /etc/nginx/ -C /root
36
+
37
+ echo "-----------pack at: /root nginx-"$arch"-ssl"$ssl_version".tar.gz--------------"
@@ -133,7 +133,36 @@ install_assets() {
133
133
  }
134
134
 
135
135
  start() {
136
- log "-----------execute ${app_name} script-------------"
136
+ # 未安装
137
+ if ((has_nginx_installed == 0)); then
138
+ install_nginx_binary
139
+
140
+ if [[ $? != 0 ]]; then
141
+ echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
142
+ exit 1
143
+ fi
144
+ fi
145
+
146
+ # 已安装 询问是否更新nginx
147
+ if ((has_nginx_installed == 1)); then
148
+ while true; do
149
+ read -r -p "Nginx has been installed, re-install it?[Y/N]" yn
150
+ case $yn in
151
+ [Yy]*)
152
+ install_nginx_binary
153
+
154
+ if [[ $? != 0 ]]; then
155
+ echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
156
+ exit 1
157
+ fi
158
+ break
159
+ ;;
160
+ [Nn]*) break ;;
161
+ *) echo "Please answer yes or no." ;;
162
+ esac
163
+ done
164
+ fi
165
+
137
166
  # 创建用户
138
167
  create_user_csri
139
168
 
@@ -4,48 +4,4 @@ basepath=$(dirname "$(realpath "${BASH_SOURCE[-1]}")")
4
4
 
5
5
  source "$basepath"/common.sh
6
6
 
7
- # 未安装
8
- if ((has_nginx_installed == 0)); then
9
- # while true; do
10
- # read -r -p "Nginx not found, install it?[Y/N]" yn
11
- # case $yn in
12
- # [Yy]*)
13
- # chmod +x "$basepath"/../nginx/script/install.sh
14
- # sh "$basepath"/../nginx/script/install.sh
15
- # break
16
- # ;;
17
- # [Nn]*) exit ;;
18
- # *) echo "Please answer yes or no." ;;
19
- # esac
20
- # done
21
- chmod +x "$basepath"/../nginx/script/install.sh
22
- sh "$basepath"/../nginx/script/install.sh
23
-
24
- if [[ $? != 0 ]]; then
25
- echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
26
- exit 1
27
- fi
28
- fi
29
-
30
- # 已安装 询问是否更新nginx
31
- if ((has_nginx_installed == 1)); then
32
- while true; do
33
- read -r -p "Nginx has been installed, re-install it?[Y/N]" yn
34
- case $yn in
35
- [Yy]*)
36
- chmod +x "$basepath"/../nginx/script/install.sh
37
- sh "$basepath"/../nginx/script/install.sh "${@}"
38
-
39
- if [[ $? != 0 ]]; then
40
- echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
41
- exit 1
42
- fi
43
- break
44
- ;;
45
- [Nn]*) break ;;
46
- *) echo "Please answer yes or no." ;;
47
- esac
48
- done
49
- fi
50
-
51
7
  start
@@ -1,14 +1,15 @@
1
1
  #!/bin/bash
2
- # 指定安装目录
3
- # nginx_conf_install_path="$prefix/etc/nginx_instances/${app_name}/"
4
- nginx_conf_install_path="$prefix/opt/${app_name}/nginx/"
5
2
 
6
3
  # 安装包所在路径
7
4
  pkg_path="${project_path}/pkg"
8
5
 
6
+ #------------------------------------ nginx服务配置文件服务 start----------------------------------
9
7
  # 配置文件所在路径
10
8
  new_nginx_conf_path="${pkg_path}/nginx"
11
9
 
10
+ # 指定安装目录
11
+ nginx_conf_install_path="$prefix/opt/${app_name}/nginx/"
12
+
12
13
  # nginx服务配置文件路径
13
14
  nginx_conf_path="${nginx_conf_install_path}nginx.conf"
14
15
 
@@ -21,8 +22,6 @@ nginx_pid_file_path="$nginx_pid_dir${app_name}.nginx.pid"
21
22
  conf_version=$(awk '{print $1}' "${pkg_path}"/version)
22
23
  echo "$conf_version"
23
24
 
24
-
25
-
26
25
  copy_nginx_conf_and_write_verison() {
27
26
  mkdir -p "$nginx_conf_install_path"
28
27
  # 创建pid目录
@@ -171,3 +170,86 @@ add_nginx_service() {
171
170
  rm -rf /usr/lib/systemd/system/"$app_name".nginx.service
172
171
  fi
173
172
  }
173
+ #------------------------------------ nginx服务配置文件服务 end----------------------------------
174
+
175
+
176
+ #------------------------------------ nginx 可执行程序相关 start----------------------------------
177
+ # 指定安装目录
178
+ nginx_binary_install_path="/etc/nginx/"
179
+
180
+ mkdir -p "$nginx_binary_install_path"
181
+
182
+ # 安装包所在路径
183
+ nginx_binary_pkg_path="${pkg_path}/nginx_binary"
184
+
185
+ open_port_80() {
186
+ # 查看防火墙是否开启
187
+ systemctl status firewalld
188
+ # 若未开启则开启
189
+ systemctl start firewalld
190
+
191
+ # 查看所有开启的端口
192
+ #firewall-cmd --list-ports
193
+
194
+ # 开启nginx默认80端口(关键步骤一)
195
+ firewall-cmd --zone=public --add-port=80/tcp --permanent
196
+
197
+ # 重启防火墙(关键步骤二)
198
+ firewall-cmd --reload
199
+ }
200
+
201
+ # 安装nginx可执行程序
202
+ install_nginx_binary() {
203
+ log "install nginx to path: ${nginx_binary_install_path}"
204
+
205
+ arch=$(uname -m)
206
+ ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
207
+
208
+ if [[ -z "${arch}" ]]; then
209
+ arch="x86_64"
210
+ fi
211
+
212
+ if [[ $arch == arm* ]] || [[ $arch = aarch64 ]]; then
213
+ arch="arm"
214
+ fi
215
+
216
+ if [[ "${ssl_version}" == "1.0" ]]; then
217
+ ssl_version="1.0.2"
218
+ fi
219
+
220
+ if [[ "${ssl_version}" == "1.1" ]]; then
221
+ ssl_version="1.1.1"
222
+ fi
223
+
224
+ if [[ "${ssl_version}" == "3.0" ]]; then
225
+ ssl_version="3.0.7"
226
+ fi
227
+
228
+ if [[ -z "${ssl_version}" ]]; then
229
+ ssl_version="1.0.2"
230
+ fi
231
+
232
+ pkg="$nginx_binary_pkg_path"/nginx-"$arch"-ssl"$ssl_version".tar.gz
233
+
234
+ if [ ! -f "$pkg" ]; then
235
+ log_error "Fatal error: nginx-$arch-ssl$ssl_version.tar.gz not matched! contact developer!"
236
+ exit 1
237
+ fi
238
+
239
+ log "current arch: $arch, current ssl_version: $ssl_version"
240
+
241
+ tar -zxvhf "$pkg" -C "$nginx_binary_install_path" --strip-components 1
242
+ # 检测是否安装成功
243
+ if [[ $? == 0 ]]; then
244
+ log_success "nginx installation successfully!"
245
+ else
246
+ log_error "nginx installation failed!"
247
+ fi
248
+
249
+ cp "$nginx_binary_install_path"sbin/nginx /usr/sbin/
250
+
251
+ # 修改/etc/nginx 用户(组)
252
+ chown -R $user:$usergroup "$nginx_binary_install_path"
253
+ chmod 744 -R "$nginx_binary_install_path"
254
+ }
255
+ #------------------------------------ nginx 可执行程序相关 end ----------------------------------