@wjwjq/release-helper 0.0.1

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 (71) hide show
  1. package/.prettierignore +13 -0
  2. package/.prettierrc.json +19 -0
  3. package/README.md +29 -0
  4. package/bin/index.js +7 -0
  5. package/dist/cli.js +56 -0
  6. package/dist/deploy/nginx/README.md +1 -0
  7. package/dist/deploy/nginx/pkg/nginx-arm-ssl1.1.1.tar.gz +0 -0
  8. package/dist/deploy/nginx/pkg/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
  9. package/dist/deploy/nginx/pkg/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
  10. package/dist/deploy/nginx/pkg/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
  11. package/dist/deploy/nginx/script/common.sh +178 -0
  12. package/dist/deploy/nginx/script/compile.sh +11 -0
  13. package/dist/deploy/nginx/script/fix.sh +24 -0
  14. package/dist/deploy/nginx/script/https.sh +79 -0
  15. package/dist/deploy/nginx/script/install.sh +99 -0
  16. package/dist/deploy/nginx/script/prompt.sh +10 -0
  17. package/dist/deploy/nginx/script/upgrade.sh +7 -0
  18. package/dist/deploy/pkg/nginx/nginx.service.tpl +33 -0
  19. package/dist/deploy/script/common.sh +183 -0
  20. package/dist/deploy/script/install.sh +51 -0
  21. package/dist/deploy/script/nginx.sh +156 -0
  22. package/dist/deploy/script/prompt.sh +98 -0
  23. package/dist/deploy/script/readme.md +10 -0
  24. package/dist/deploy/script/upgrade.sh +50 -0
  25. package/dist/logger.js +20 -0
  26. package/dist/pack.js +111 -0
  27. package/dist/prepare.js +75 -0
  28. package/dist/publish.js +238 -0
  29. package/dist/release.js +200 -0
  30. package/package.json +71 -0
  31. package/rollup.config.js +78 -0
  32. package/src/.release/README.md +23 -0
  33. package/src/.release/doc//351/203/250/347/275/262/346/211/213/345/206/214.md +426 -0
  34. package/src/.release/nginx/ca/ca.crt +32 -0
  35. package/src/.release/nginx/ca/ca.key +54 -0
  36. package/src/.release/nginx/ca/client.crt +100 -0
  37. package/src/.release/nginx/ca/client.csr +16 -0
  38. package/src/.release/nginx/ca/client.p12 +0 -0
  39. package/src/.release/nginx/ca/client.pem +30 -0
  40. package/src/.release/nginx/ca/server.crt +101 -0
  41. package/src/.release/nginx/ca/server.csr +17 -0
  42. package/src/.release/nginx/ca/server.key +27 -0
  43. package/src/.release/nginx/ca/server.pem +30 -0
  44. package/src/.release/nginx/nginx.conf +179 -0
  45. package/src/.release/release.conf.yaml +9 -0
  46. package/src/cli.ts +99 -0
  47. package/src/deploy/nginx/README.md +1 -0
  48. package/src/deploy/nginx/pkg/nginx-arm-ssl1.1.1.tar.gz +0 -0
  49. package/src/deploy/nginx/pkg/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
  50. package/src/deploy/nginx/pkg/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
  51. package/src/deploy/nginx/pkg/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
  52. package/src/deploy/nginx/script/common.sh +178 -0
  53. package/src/deploy/nginx/script/compile.sh +11 -0
  54. package/src/deploy/nginx/script/fix.sh +24 -0
  55. package/src/deploy/nginx/script/https.sh +79 -0
  56. package/src/deploy/nginx/script/install.sh +99 -0
  57. package/src/deploy/nginx/script/prompt.sh +10 -0
  58. package/src/deploy/nginx/script/upgrade.sh +7 -0
  59. package/src/deploy/pkg/nginx/nginx.service.tpl +33 -0
  60. package/src/deploy/script/common.sh +183 -0
  61. package/src/deploy/script/install.sh +51 -0
  62. package/src/deploy/script/nginx.sh +156 -0
  63. package/src/deploy/script/prompt.sh +98 -0
  64. package/src/deploy/script/readme.md +10 -0
  65. package/src/deploy/script/upgrade.sh +50 -0
  66. package/src/logger.ts +18 -0
  67. package/src/pack.ts +141 -0
  68. package/src/prepare.ts +105 -0
  69. package/src/publish.ts +308 -0
  70. package/src/release.ts +292 -0
  71. package/tsconfig.json +14 -0
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+ # 获取脚本所在的目录
3
+ basepath=$(dirname "$(realpath "${BASH_SOURCE[-1]}")")
4
+
5
+
6
+ source $basepath/common.sh
7
+
8
+ tar -zxvhf "$pkg_path"/nginx-binary*.tar.gz -C $install_path --strip-components 1
9
+
10
+ if [[ -z "${prefix}" ]]; then
11
+ cp "$install_path"/sbin/nginx /usr/sbin/
12
+ fi
13
+
14
+ # 检测是否安装成功
15
+ if [[ $? == 0 ]]; then
16
+ echo "$(tput setaf 2)"nginx fixed"$(tput sgr0)"
17
+
18
+
19
+ "$install_path"nginx -v
20
+
21
+ else
22
+
23
+ echo "$(tput setaf 1)"nginx installation failed!"$(tput sgr0)"
24
+ fi
@@ -0,0 +1,79 @@
1
+ #!/bin/bash
2
+
3
+ COUNTRY="CN"
4
+ PROVINCE="SC"
5
+ CITY="CD"
6
+ ORG="HX"
7
+ OU="HXWX"
8
+ emailAddress="hxwxgroup@qq.com"
9
+
10
+ get_subj () {
11
+ echo "/C=$COUNTRY/ST=$PROVINCE/L=$CITY/O=$ORG/OU=$OU/CN=$1/emailAddress=$emailAddress"
12
+ }
13
+
14
+ if [ ! -f "/etc/pki/CA/index.txt" ]; then
15
+ touch /etc/pki/CA/index.txt
16
+ fi
17
+
18
+ if [ ! -f "/etc/pki/CA/serial" ]; then
19
+ echo 01 >/etc/pki/CA/serial
20
+ fi
21
+
22
+ # ca
23
+ echo "---------------------generate ca------------------"
24
+ openssl genrsa -des3 -out ca.key 4096
25
+
26
+ read -rep "Please input ca DOMAIN: " -i "HXWXGROUP" CA_GRPUP_DOMAIN
27
+
28
+
29
+ subj=$(get_subj $CA_GRPUP_DOMAIN)
30
+
31
+ openssl req -new -x509 -days 3650 -key ca.key -out ca.crt -subj $subj
32
+
33
+ if [[ $? == 0 ]]; then
34
+ echo "$(tput setaf 2)"---------------------generate ca done------------------!"$(tput sgr0)"
35
+ else
36
+ echo "$(tput setaf 1)"---------------------generate ca failed------------------"$(tput sgr0)"
37
+ exit 1
38
+ fi
39
+
40
+ # 服务端
41
+ echo "---------------------generate server ca------------------"
42
+ openssl genrsa -des3 -out server.pem 2048
43
+
44
+ openssl rsa -in server.pem -out server.key
45
+
46
+ read -rep "Please input server DOMAIN: " -i "www.cdsp.com" SERVER_DOMAIN
47
+
48
+ subj=$(get_subj $SERVER_DOMAIN)
49
+ # echo $subj #"/C=CN/ST=SC/L=CD/O=HX/OU=HXWX/CN=www.cdsp.com/emailAddress=''"
50
+ openssl req -new -key server.pem -out server.csr -subj $subj
51
+
52
+ if [[ $? == 0 ]]; then
53
+ openssl ca -policy policy_anything -days 3650 -cert ca.crt -keyfile ca.key -in server.csr -out server.crt
54
+ echo "$(tput setaf 2)"---------------------generate server ca done------------------!"$(tput sgr0)"
55
+ else
56
+ echo "$(tput setaf 1)"---------------------generate server ca failed------------------"$(tput sgr0)"
57
+ exit 1
58
+ fi
59
+
60
+ # 客户端
61
+ echo "---------------------generate client ca------------------"
62
+ openssl genrsa -des3 -out client.pem 2048
63
+
64
+ read -rep "Please input client DOMAIN: " -i "HXWXcdspCLIENT" CLIENT_DOMAIN
65
+
66
+ subj=$(get_subj $CLIENT_DOMAIN)
67
+
68
+ openssl req -new -key client.pem -out client.csr -subj $subj
69
+
70
+ if [[ $? == 0 ]]; then
71
+ openssl ca -policy policy_anything -days 3650 -cert ca.crt -keyfile ca.key -in client.csr -out client.crt
72
+
73
+ openssl pkcs12 -export -clcerts -in client.crt -inkey client.pem -out client.p12
74
+
75
+ echo "$(tput setaf 2)"---------------------generate client ca done------------------!"$(tput sgr0)"
76
+ else
77
+ echo "$(tput setaf 1)"---------------------generate client ca failed------------------"$(tput sgr0)"
78
+ exit 1
79
+ fi
@@ -0,0 +1,99 @@
1
+ #!/bin/bash
2
+ # 获取脚本所在的目录
3
+ basepath=$(dirname "$(realpath "${BASH_SOURCE[-1]}")")
4
+
5
+ source "$basepath"/common.sh
6
+
7
+ open_port_80() {
8
+ # 查看防火墙是否开启
9
+ systemctl status firewalld
10
+ # 若未开启则开启
11
+ systemctl start firewalld
12
+
13
+ # 查看所有开启的端口
14
+ #firewall-cmd --list-ports
15
+
16
+ # 开启nginx默认80端口(关键步骤一)
17
+ firewall-cmd --zone=public --add-port=80/tcp --permanent
18
+
19
+ # 重启防火墙(关键步骤二)
20
+ firewall-cmd --reload
21
+ }
22
+
23
+ rpm_install() {
24
+ installed=$(rpm -qa | grep -i nginx)
25
+
26
+ if [[ -n "${installed}" ]]; then
27
+ rpm -e "$installed"
28
+ fi
29
+
30
+ rpm -Uivh "$pkg_path"/nginx*.rpm
31
+ }
32
+
33
+ install_from_sourcecode() {
34
+ tar -zxvhf "$pkg_path/nginx-1.20.2.tar.gz"
35
+ (
36
+ cd ./nginx-1.20.2 || exit
37
+ sudo ./configure --prefix="$install_path" --with-http_ssl_module --with-http_v2_module
38
+ make && make install
39
+ )
40
+ }
41
+
42
+ # 安装
43
+ install() {
44
+ log "install nginx to path: ${install_path}"
45
+
46
+ arch=$(uname -m)
47
+ ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
48
+
49
+ if [[ -z "${arch}" ]]; then
50
+ arch="x86_64"
51
+ fi
52
+
53
+ if [[ $arch == arm* ]] || [[ $arch = aarch64 ]]; then
54
+ arch="arm"
55
+ fi
56
+
57
+ if [[ "${ssl_version}" == "1.0" ]]; then
58
+ ssl_version="1.0.2"
59
+ fi
60
+
61
+ if [[ "${ssl_version}" == "1.1" ]]; then
62
+ ssl_version="1.1.1"
63
+ fi
64
+
65
+ if [[ "${ssl_version}" == "3.0" ]]; then
66
+ ssl_version="3.0.7"
67
+ fi
68
+
69
+ if [[ -z "${ssl_version}" ]]; then
70
+ ssl_version="1.0.2"
71
+ fi
72
+
73
+ pkg="$pkg_path"/nginx-"$arch"-ssl"$ssl_version".tar.gz
74
+
75
+ if [ ! -f "$pkg" ]; then
76
+ log_error "Fatal error: nginx-$arch-ssl$ssl_version.tar.gz not matched! contact developer!"
77
+ exit 1
78
+ fi
79
+
80
+ log "current arch: $arch, current ssl_version: $ssl_version"
81
+
82
+ tar -zxvhf "$pkg" -C "$install_path" --strip-components 1
83
+
84
+ mkdir -p /var/log/nginx
85
+
86
+ if [[ -z "${prefix}" ]]; then
87
+ cp "$install_path"/sbin/nginx /usr/sbin/
88
+ fi
89
+
90
+ # 检测是否安装成功
91
+ if [[ $? == 0 ]]; then
92
+ log_success "nginx installation successfully!"
93
+ else
94
+ log_error "nginx installation failed!"
95
+ fi
96
+ }
97
+
98
+ install
99
+ log '------------- done ------------------------'
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ prefix=""
3
+
4
+ # if [[ -z "${prefix}" ]]; then
5
+
6
+ # read -r -p "Input installation or upgrade path: (default: /etc/nginx/)" prefix
7
+ # prefix=${prefix:-''}
8
+ # fi
9
+
10
+ # echo "install/upgrade prefix: $prefix"
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ # 获取脚本所在的目录
3
+ basepath=$(dirname "$(realpath "${BASH_SOURCE[-1]}")")
4
+
5
+ source "$basepath"/common.sh
6
+
7
+ log '------------- done ------------------------'
@@ -0,0 +1,33 @@
1
+ [Unit]
2
+ Description=nginx.service
3
+ After=syslog.target network-online.target remote-fs.target nss-lookup.target
4
+ Wants=network-online.target
5
+
6
+ [Service]
7
+ # 应用启动使用的用户及用户组,需各组件手动修改
8
+ User=root
9
+ Group=root
10
+
11
+ Environment="LOGPATH=_log_path_" "LOGFILE=_log_file_" "LOGROTATEDELAY=2592000000" "CONFS=_conf_path_" "VERSION=_version_"
12
+
13
+ # Disable service start and stop timeout logic of systemd for mysqld service.
14
+ TimeoutSec=0
15
+
16
+ # Execute pre and post scripts as root
17
+ PermissionsStartOnly=true
18
+
19
+ # 应用安装目录,需手动修改
20
+ WorkingDirectory=/etc/nginx
21
+
22
+ [Service]
23
+ Type=forking
24
+ PIDFile=_pid_file_
25
+ ExecStartPre=_start_check_
26
+ ExecStart=_exec_cmd_
27
+ ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
28
+ ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"
29
+
30
+ PrivateTmp=true
31
+
32
+ [Install]
33
+ WantedBy=multi-user.target
@@ -0,0 +1,183 @@
1
+ #!/bin/bash
2
+ # 获取脚本的父目录
3
+ project_path=$(echo "$basepath" | sed -e "s/\/script//")
4
+
5
+ # 请勿修改此处, 此处将在打包时自动替换
6
+ app_name=__APP_NAME__
7
+
8
+ # 静态资源存放目录 eg: /opt/posidon-frontend/
9
+ install_path=__INSTALL_PATH__
10
+
11
+ execute_log_path="/var/log/${app_name}_script_execute_logs"
12
+
13
+ log() {
14
+ now=$(date "+%Y-%m-%d %H:%M:%S")
15
+ echo "$now: $1"
16
+ echo "$now: [info] $1" >>"$execute_log_path"
17
+ }
18
+
19
+ log_success() {
20
+ now=$(date "+%Y-%m-%d %H:%M:%S")
21
+ echo "$(tput setaf 2)""$now": "$1""$(tput sgr0)"
22
+ echo "$now: [success] $1" >>"$execute_log_path"
23
+ }
24
+
25
+ log_error() {
26
+ now=$(date "+%Y-%m-%d %H:%M:%S")
27
+ echo "$(tput setaf 1)""$now": "$1" "$(tput sgr0)"
28
+ echo "$now: [error] $1" >>"$execute_log_path"
29
+ }
30
+
31
+ log "-----------execute ${app_name} script-------------"
32
+
33
+ source "$basepath"/prompt.sh
34
+
35
+ if [[ $(whoami) != "root" ]]; then
36
+ echo "user:root is required!"
37
+ exit 1
38
+ fi
39
+
40
+ if [[ -z "${install_path}" ]]; then
41
+ echo "install path not found"
42
+ exit 1
43
+ fi
44
+
45
+ echo "install_path: ${install_path}"
46
+
47
+ source "$basepath"/nginx.sh
48
+
49
+ # 创建用户
50
+ create_user_csri() {
51
+ user="csri"
52
+ group="csri"
53
+
54
+ #create group if not exists
55
+ grep "^$group" /etc/group >&/dev/null
56
+ if [ $? -ne 0 ]; then
57
+ groupadd $group
58
+ fi
59
+
60
+ #create user if not exists
61
+ grep "^$user" /etc/passwd >&/dev/null
62
+ if [ $? -ne 0 ]; then
63
+ useradd -g $group $user
64
+ fi
65
+ }
66
+
67
+ find_nginx_pos() {
68
+ confpath=''
69
+ find / -name "nginx" -print0 >tmpfile
70
+ while IFS= read -r -d $'\0'; do
71
+ if [ -d "$REPLY/conf" ]; then # $prefix/etc/nginx
72
+ confpath="$REPLY/conf.d/"
73
+ break
74
+ elif [ -d "$REPLY/conf.d" ]; then # /etc/nginx
75
+ confpath="$REPLY/conf.d/"
76
+ break
77
+ fi
78
+ done <tmpfile
79
+ rm -f tmpfile
80
+
81
+ echo "$confpath"
82
+ }
83
+
84
+ has_nginx_installed=1
85
+
86
+ # 检查 nginx 是否已安装
87
+ if command -v nginx >/dev/null 2>&1; then
88
+ # echo "Nginx is installed."
89
+ has_nginx_installed=1
90
+ # # 检查 nginx 服务是否正在运行
91
+ # if pgrep nginx >/dev/null 2>&1; then
92
+ # echo "Nginx is running."
93
+ # else
94
+ # echo "Nginx is installed but not running."
95
+ # fi
96
+ else
97
+ # echo "Nginx is not installed."
98
+ has_nginx_installed=0
99
+ fi
100
+
101
+ get_old_version() {
102
+ if [ -f "$install_path""version" ]; then
103
+ old_version=$(sed -n '1p' "$install_path""version")
104
+
105
+ echo "$old_version"
106
+ fi
107
+ }
108
+
109
+ install_assets() {
110
+
111
+ # 拷贝静态资源
112
+ cp -rf "${project_path}"/pkg/version "$install_path"
113
+
114
+ mkdir -p "$install_path"assets
115
+
116
+ cp -rf "${project_path}"/pkg/assets/* "$install_path"assets
117
+
118
+ # # 对比行数并合并
119
+ # if [ -f "${backup_path}/settings" ]; then
120
+ # cat $backup_path/settings | sed '/^$/d' >>./settings
121
+ # cat $install_path/settings | sed '/^$/d' >>./settings_new
122
+
123
+ # diffLines=$(diff ./settings ./settings_new | awk 'END{print NR}')
124
+
125
+ # if ((diffLines > 0)); then
126
+ # echo '-------合并前:old--------'
127
+ # cat ./settings
128
+ # old_total_line=$(awk 'END{print NR}' ./settings)
129
+ # start=$(($old_total_line + 1))
130
+
131
+ # echo '-------合并前: new--------'
132
+ # cat ./settings_new
133
+ # total_line=$(awk 'END{print NR}' ./settings_new)
134
+
135
+ # sed -n "${start},${total_line}p" ./settings_new >>./settings
136
+ # echo '---------- 合并后 ----------'
137
+ # cat ./settings
138
+
139
+ # mv -f ./settings $install_path
140
+ # rm -rf ./settings_new
141
+
142
+ # echo "$(tput setaf 2)"settings 已合并,注意检查"$(tput sgr0)"
143
+ # fi
144
+ # fi
145
+
146
+ log_success "$install_path"assets/settings 已覆盖,请注意对比差异
147
+
148
+ # 修改所属用户
149
+ if [[ "$i(stat -c '%U' ${install_path})" != 'csri' ]]; then
150
+ chown -R csri:csri "$install_path"
151
+ fi
152
+
153
+ (chmod 644 -R "$install_path")
154
+
155
+ if [[ $? == 0 ]]; then
156
+ log_success "posidon-frontend deployed successfully"
157
+ else
158
+ log_error "posidon-frontend deployment failed"
159
+ fi
160
+ }
161
+
162
+ start() {
163
+ log "-----------execute ${app_name} script-------------"
164
+ # 创建用户
165
+ create_user_csri
166
+
167
+ now=$(date "+%Y-%m-%d_%H:%M:%S")
168
+ old_version=$(get_old_version)
169
+
170
+ #备份整个服务 eg: /opt/posidon-frontend
171
+ if [[ -n "${old_version}" ]]; then
172
+ parent_store_path=$(echo "$install_path" | sed -e "s/\/${app_name}//")
173
+ backup_path=$parent_store_path""$app_name"_"$old_version"_"$now
174
+ echo "${app_name} assets backup at: $backup_path"
175
+ mv "$install_path" "$backup_path"
176
+ fi
177
+
178
+ mkdir -p "$install_path"
179
+
180
+ copy_nginx_conf_and_write_verison
181
+ add_nginx_service
182
+ install_assets
183
+ }
@@ -0,0 +1,51 @@
1
+ #!/bin/bash
2
+ # 获取脚本所在的目录
3
+ basepath=$(dirname "$(realpath "${BASH_SOURCE[-1]}")")
4
+
5
+ source "$basepath"/common.sh
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
+ start
@@ -0,0 +1,156 @@
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
+
6
+ # 安装包所在路径
7
+ pkg_path="${project_path}/pkg"
8
+
9
+ # 配置文件所在路径
10
+ new_nginx_conf_path="${pkg_path}/nginx/nginx.conf"
11
+
12
+ # nginx服务配置文件路径
13
+ nginx_conf_path="${nginx_conf_install_path}nginx.conf"
14
+
15
+ # asset_path="$prefix/opt/posidon-frontend/"
16
+ nginx_log_path="/var/log/nginx"
17
+ nginx_log_file="${app_name}.nginx.log"
18
+ nginx_pid_path="/var/run/${app_name}.nginx.pid"
19
+
20
+ conf_version=$(awk '{print $1}' "${pkg_path}"/version)
21
+ echo "$conf_version"
22
+
23
+ copy_nginx_conf_and_write_verison() {
24
+ mkdir -p "$nginx_conf_install_path"
25
+
26
+ access_log_super="access_log /dev/stdout main"
27
+ error_log_super="error_log /dev/stderr warn"
28
+ access_log="access_log $nginx_log_path/$nginx_log_file main"
29
+ error_log="error_log $nginx_log_path/$nginx_log_file"
30
+
31
+ pid_file="pid $nginx_pid_path"
32
+
33
+ exec=$(get_exec_path)
34
+
35
+ # if [ -f "$nginx_conf_path" ]; then
36
+ # old_version=$(sed -n '1p' "$nginx_conf_path" | sed 's/# version: //' | sed "s/\s\+//g")
37
+
38
+ # if [[ -n "${old_version}" ]]; then
39
+ # now=$(date "+%Y-%m-%d_%H:%M:%S")
40
+
41
+ # # echo "nginx_"$old_version"_"$now".conf"
42
+ # mv "$nginx_conf_path" "${nginx_conf_install_path}"/"$app_name".nginx_"$old_version"_"$now".conf
43
+ # fi
44
+ # fi
45
+
46
+ #nginx -v nginx代码内部使用的stderr输出, 此处需要转换为stdout
47
+ nginx_version=$($exec -v 2>&1)
48
+
49
+ cp "$new_nginx_conf_path" ./nginx.conf
50
+
51
+ sed -i "1i\# ${nginx_version}" ./nginx.conf
52
+ sed -i "1i\# version: ${conf_version}" ./nginx.conf
53
+
54
+ if [[ -n "${prefix}" ]]; then
55
+ n=$(grep -wn "mime.types" ./nginx.conf | awk -F: '{print $1}' | sed -n 1p)
56
+ sed -i "${n}c include conf/mime.types;" ./nginx.conf
57
+ fi
58
+
59
+ # n=$(grep -wn "__root__" ./nginx.conf | awk -F: '{print $1}' | sed -n 1p)
60
+ # if [[ -n "${n}" ]]; then
61
+ # sed -i "${n}c root ${asset_path};" ./nginx.conf
62
+ # fi
63
+
64
+ # 替换日志输出路径方式
65
+ n=$(grep -wn "#ERROR_LOG_PLACEHOLDER" ./nginx.conf | awk -F: '{print $1}' | sed -n 1p)
66
+ if [[ -n "${n}" ]]; then
67
+ if ((mode == 2)); then
68
+ sed -i "${n}c ${error_log};" ./nginx.conf
69
+ else
70
+ sed -i "${n}c ${error_log_super};" ./nginx.conf
71
+ fi
72
+ fi
73
+
74
+ n=$(grep -wn "#ACCESS_LOG_PLACEHOLDER" ./nginx.conf | awk -F: '{print $1}' | sed -n 1p)
75
+ if [[ -n "${n}" ]]; then
76
+ if ((mode == 2)); then
77
+ sed -i "${n}c ${access_log};" ./nginx.conf
78
+ else
79
+ sed -i "${n}c ${access_log_super};" ./nginx.conf
80
+ fi
81
+ fi
82
+
83
+ n=$(grep -wn "#PID_FILE_PALCEHOLDER" ./nginx.conf | awk -F: '{print $1}' | sed -n 1p)
84
+ if [[ -n "${n}" ]]; then
85
+ # 非supervisorctl
86
+ if ((mode == 2)); then
87
+ sed -i "${n}c ${pid_file};" ./nginx.conf
88
+ fi
89
+ fi
90
+
91
+ n=$(grep -wn "daemon off;" ./nginx.conf | awk -F: '{print $1}' | sed -n 1p)
92
+ if [[ -n "${n}" ]]; then
93
+ # 非supervisorctl
94
+ if ((mode == 2)); then
95
+ sed -i "${n}c daemon on;" ./nginx.conf
96
+ fi
97
+ fi
98
+
99
+ mv -fb "./nginx.conf" "$nginx_conf_install_path"
100
+
101
+ cp -fR "$pkg_path"/nginx/ca "$nginx_conf_install_path"
102
+
103
+ mkdir -p /data/command/
104
+ log "nginx start command: $(get_exec_cmd)"
105
+ echo "$exec -c $nginx_conf_path" >/data/command/nginx
106
+
107
+ if [[ $? == 0 ]]; then
108
+ log_success "$conf_version $nginx_conf_path replaced successfully!"
109
+ else
110
+ log_error "$conf_version $nginx_conf_path replaced failed!"
111
+ fi
112
+ }
113
+
114
+ get_exec_path() {
115
+ cmd=''
116
+ if [[ -n "${prefix}" ]]; then
117
+ cmd="${nginx_conf_install_path}/sbin/nginx"
118
+ else
119
+ cmd="/usr/sbin/nginx"
120
+ fi
121
+
122
+ echo "$cmd"
123
+ }
124
+
125
+ get_exec_cmd() {
126
+ exec=$(get_exec_path)
127
+
128
+ echo "$exec -c $nginx_conf_path"
129
+ }
130
+
131
+ add_nginx_service() {
132
+ #添加到服务
133
+ exec_cmd=$(get_exec_cmd)
134
+ cp "$pkg_path"/nginx/nginx.service.tpl ./nginx.service
135
+
136
+ check_cmd="$exec -t -c $nginx_conf_path"
137
+ version=$(echo "$conf_version" | grep -oP '\d+\.\d+\.\d+')
138
+
139
+ sed -i "s#_exec_cmd_#$exec_cmd #g" ./nginx.service
140
+ sed -i "s#_log_path_#$nginx_log_path#g" ./nginx.service
141
+ sed -i "s#_log_file_#$nginx_log_file#g" ./nginx.service
142
+ sed -i "s#_conf_path_#$nginx_conf_path#g" ./nginx.service
143
+ sed -i "s#_version_#$version#g" ./nginx.service
144
+ sed -i "s#_pid_file_#$nginx_pid_path#g" ./nginx.service
145
+ sed -i "s#_start_check_#$check_cmd#g" ./nginx.service
146
+
147
+ if ((mode == 2)); then
148
+ # systemctl enable nginx
149
+ cp ./nginx.service /usr/lib/systemd/system/"$app_name".nginx.service
150
+ systemctl daemon-reload
151
+
152
+ log_success "add ${app_name}.nginx.service to /usr/lib/systemd/system/"
153
+ else
154
+ rm -rf /usr/lib/systemd/system/"$app_name".nginx.service
155
+ fi
156
+ }