@wjwjq/release-helper 0.2.96 → 0.2.97

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.
@@ -1,15 +1,15 @@
1
1
  #!/bin/sh
2
2
 
3
- app_name=__APP_NAME__
3
+ APP_NAME=__APP_NAME__
4
4
  backup_dir=__DOCKER_BACKUP_DIR__
5
- install_path=__DOCKER_INSTALL_DIR__
5
+ INSTALL_PATH=__DOCKER_INSTALL_DIR__
6
6
 
7
7
  # 备份文件
8
8
  backup() {
9
- echo "---------- $install_path directory isExist,start backup"
9
+ echo "---------- $INSTALL_PATH directory isExist,start backup"
10
10
  filename=$(date +%Y%m%d)_$(date +%H%M%S)
11
11
  mkdir -p "${backup_dir}"-$filename
12
- mv "${install_path}"* "${backup_dir}"-$filename
12
+ mv "${INSTALL_PATH}"* "${backup_dir}"-$filename
13
13
  if [ $? -eq 0 ]; then
14
14
  echo "backup success"
15
15
  else
@@ -18,8 +18,8 @@ backup() {
18
18
  }
19
19
  # 复制文件
20
20
  copyFile() {
21
- echo "---------- cp ${app_name} to $install_path"
22
- cp -r ./../pkg/assets/* $install_path
21
+ echo "---------- cp ${APP_NAME} to $INSTALL_PATH"
22
+ cp -r ./../pkg/assets/* $INSTALL_PATH
23
23
  if [ $? -eq 0 ]; then
24
24
  echo "cp success"
25
25
  else
@@ -29,9 +29,9 @@ copyFile() {
29
29
 
30
30
  # 安装
31
31
  install() {
32
- mkdir -p $install_path
33
- if [ -z "$(ls -A $install_path)" ]; then
34
- echo "---------- $install_path directory isEmpty"
32
+ mkdir -p $INSTALL_PATH
33
+ if [ -z "$(ls -A $INSTALL_PATH)" ]; then
34
+ echo "---------- $INSTALL_PATH directory isEmpty"
35
35
  else
36
36
  backup
37
37
  fi
@@ -40,13 +40,13 @@ install() {
40
40
  }
41
41
  # 展示版本信息
42
42
  showVersion() {
43
- if [ -f "${install_path}version" ]; then
44
- echo "---------- old ${app_name} Version"
45
- cat "${install_path}"version
43
+ if [ -f "${INSTALL_PATH}version" ]; then
44
+ echo "---------- old ${APP_NAME} Version"
45
+ cat "${INSTALL_PATH}"version
46
46
  echo ""
47
47
  fi
48
48
 
49
- echo "---------- will install ${app_name} Version"
49
+ echo "---------- will install ${APP_NAME} Version"
50
50
  cat ./../pkg/version
51
51
  echo ""
52
52
  }
@@ -0,0 +1,159 @@
1
+ #!/bin/bash
2
+ # 自签名SSL证书生成脚本
3
+
4
+ set -e
5
+
6
+ # 颜色定义
7
+ RED='\033[0;31m'
8
+ GREEN='\033[0;32m'
9
+ YELLOW='\033[1;33m'
10
+ NC='\033[0m' # No Color
11
+
12
+ TARGET_DIR='.';
13
+
14
+ # 默认值
15
+ DOMAIN="${1:-example.com}"
16
+ DAYS="${2:-3650}"
17
+ KEY_SIZE="${3:-2048}"
18
+ ALT_DOMAINS="${4:-www.${DOMAIN}}"
19
+
20
+ # 函数:打印带颜色的消息
21
+ log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
22
+ log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
23
+ log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
24
+
25
+ # 检查参数
26
+ if [ $# -lt 1 ]; then
27
+ echo "用法: $0 <域名> [有效期天数] [密钥长度] [备用域名,逗号分隔]"
28
+ echo "示例: $0 example.com 365 2048 \"www.example.com,api.example.com\""
29
+ exit 1
30
+ fi
31
+
32
+ # 创建目录
33
+ log_info "创建目录结构..."
34
+ sudo mkdir -p "$TARGET_DIR"/{private,certs,ca}/"${DOMAIN}"
35
+ sudo chmod 700 "$TARGET_DIR"/private/"${DOMAIN}"
36
+ sudo chmod 755 "$TARGET_DIR"/certs/"${DOMAIN}" "$TARGET_DIR"/ca/"${DOMAIN}"
37
+
38
+ # 生成私钥
39
+ log_info "生成${KEY_SIZE}位RSA私钥..."
40
+ sudo openssl genrsa -out "$TARGET_DIR"/private/"${DOMAIN}"/"${DOMAIN}".key "${KEY_SIZE}"
41
+ sudo chmod 600 "$TARGET_DIR"/private/"${DOMAIN}"/"${DOMAIN}".key
42
+
43
+ # 创建CSR配置文件
44
+ log_info "创建CSR配置文件..."
45
+ sudo tee /tmp/"${DOMAIN}".csr.cnf > /dev/null << CSR_EOF
46
+ [req]
47
+ default_bits = ${KEY_SIZE}
48
+ prompt = no
49
+ default_md = sha256
50
+ distinguished_name = dn
51
+ req_extensions = req_ext
52
+
53
+ [dn]
54
+ C = CN
55
+ ST = Beijing
56
+ L = Beijing
57
+ O = ${DOMAIN} Corporation
58
+ OU = IT Department
59
+ CN = ${DOMAIN}
60
+ emailAddress = admin@${DOMAIN}
61
+
62
+ [req_ext]
63
+ subjectAltName = @alt_names
64
+
65
+ [alt_names]
66
+ DNS.1 = ${DOMAIN}
67
+ CSR_EOF
68
+
69
+ # 添加备用域名
70
+ IFS=',' read -ra ADDR <<< "${ALT_DOMAINS}"
71
+ i=2
72
+ for alt in "${ADDR[@]}"; do
73
+ echo "DNS.${i} = ${alt}" | sudo tee -a /tmp/"${DOMAIN}".csr.cnf > /dev/null
74
+ ((i++))
75
+ done
76
+
77
+ # 添加本地域名和IP
78
+ cat << LOCAL_EOF | sudo tee -a /tmp/"${DOMAIN}".csr.cnf > /dev/null
79
+ DNS.$i = localhost
80
+ DNS.$((i+1)) = localhost.localdomain
81
+ DNS.$((i+2)) = *.${DOMAIN}
82
+ IP.1 = 127.0.0.1
83
+ IP.2 = ::1
84
+ LOCAL_EOF
85
+
86
+ # 生成CSR
87
+ log_info "生成证书签名请求..."
88
+ sudo openssl req -new -sha256 \
89
+ -key "$TARGET_DIR"/private/"${DOMAIN}"/"${DOMAIN}".key \
90
+ -out "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}".csr \
91
+ -config /tmp/"${DOMAIN}".csr.cnf
92
+
93
+ # 创建证书扩展文件
94
+ log_info "创建证书扩展文件..."
95
+ sudo tee /tmp/"${DOMAIN}".ext.cnf > /dev/null << EXT_EOF
96
+ authorityKeyIdentifier = keyid,issuer:always
97
+ basicConstraints = CA:FALSE
98
+ keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
99
+ extendedKeyUsage = serverAuth, clientAuth
100
+ subjectAltName = @alt_names
101
+ subjectKeyIdentifier = hash
102
+ nsComment = "Generated by SSL Certificate Script"
103
+ EXT_EOF
104
+
105
+ # 复制SAN信息
106
+ grep -A 20 "\[alt_names\]" /tmp/"${DOMAIN}".csr.cnf | sudo tee -a /tmp/"${DOMAIN}".ext.cnf > /dev/null
107
+
108
+ # 生成自签名证书
109
+ log_info "生成自签名证书(有效期${DAYS}天)..."
110
+ sudo openssl x509 -req -sha256 -days "${DAYS}" \
111
+ -in "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}".csr \
112
+ -signkey "$TARGET_DIR"/private/"${DOMAIN}"/"${DOMAIN}".key \
113
+ -out "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}".crt \
114
+ -extfile /tmp/"${DOMAIN}".ext.cnf
115
+
116
+ # 设置权限
117
+ sudo chmod 644 "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}".crt
118
+
119
+ # 创建证书链文件
120
+ log_info "创建证书链文件..."
121
+ sudo cat "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}".crt > \
122
+ "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}"-chain.crt
123
+ sudo chmod 644 "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}"-chain.crt
124
+
125
+ # 验证证书
126
+ log_info "验证生成的证书..."
127
+ sudo openssl x509 -in "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}".crt \
128
+ -text -noout | grep -E "Subject:|Not After|Subject Alternative Name"
129
+
130
+ # 生成摘要
131
+ log_info "生成密钥摘要..."
132
+ KEY_MD5=$(sudo openssl rsa -noout -modulus -in "$TARGET_DIR"/private/"${DOMAIN}"/"${DOMAIN}".key | openssl md5 | awk '{print $2}')
133
+ CERT_MD5=$(sudo openssl x509 -noout -modulus -in "$TARGET_DIR"/certs/"${DOMAIN}"/"${DOMAIN}".crt | openssl md5 | awk '{print $2}')
134
+
135
+ if [ "$KEY_MD5" = "$CERT_MD5" ]; then
136
+ log_info "✓ 私钥和证书匹配"
137
+ else
138
+ log_error "✗ 私钥和证书不匹配"
139
+ fi
140
+
141
+ # 输出信息
142
+ echo -e "\n${GREEN}证书生成完成!${NC}"
143
+ echo "=========================================="
144
+ echo "域名: ${DOMAIN}"
145
+ echo "备用域名: ${ALT_DOMAINS}"
146
+ echo "有效期: ${DAYS} 天"
147
+ echo "密钥长度: ${KEY_SIZE} 位"
148
+ echo ""
149
+ echo "文件位置:"
150
+ echo "私钥: $TARGET_DIR/private/${DOMAIN}/${DOMAIN}.key"
151
+ echo "证书: $TARGET_DIR/certs/${DOMAIN}/${DOMAIN}.crt"
152
+ echo "证书链: $TARGET_DIR/certs/${DOMAIN}/${DOMAIN}-chain.crt"
153
+ echo "CSR: $TARGET_DIR/certs/${DOMAIN}/${DOMAIN}.csr"
154
+ echo "=========================================="
155
+
156
+ # 清理临时文件
157
+ rm -f /tmp/"${DOMAIN}".csr.cnf /tmp/"${DOMAIN}".ext.cnf
158
+
159
+ log_info "完成!"
@@ -1,51 +1,55 @@
1
1
  #!/bin/bash
2
2
 
3
3
  # 安装包所在路径
4
- pkg_path="${project_path}/pkg"
4
+ readonly PKG_DIR="${PROJECT_PATH}/pkg"
5
5
 
6
6
  #------------------------------------ nginx服务配置文件服务 start----------------------------------
7
7
  # 配置文件所在路径
8
- new_nginx_conf_path="${pkg_path}/nginx"
8
+ readonly NEW_NGINX_CONF_PATH="${PKG_DIR}/nginx"
9
9
 
10
10
  # 指定安装目录
11
- nginx_conf_install_path="$prefix/opt/${app_name}/nginx/"
11
+ readonly NGINX_CONF_INSTALL_PATH="$prefix/opt/${APP_NAME}/nginx/"
12
12
 
13
13
  # nginx服务配置文件路径
14
- nginx_conf_path="${nginx_conf_install_path}nginx.conf"
14
+ readonly NGINX_CONF_PATH="${NGINX_CONF_INSTALL_PATH}nginx.conf"
15
15
 
16
16
  # asset_path="$prefix/opt/posidon-frontend/"
17
- nginx_info_path="/var/log/${app_name}"
18
- nginx_log_file="nginx.log"
17
+ readonly NGINX_INFO_PATH="/var/log/${APP_NAME}"
18
+ readonly NGINX_LOG_FILE="nginx.log"
19
19
  #不放在var/run 是因为重启后 var/run/下面的文件及目录会被清除
20
- nginx_pid_file_path="$nginx_info_path/nginx.pid"
20
+ readonly NGINX_PID_FILE_PATH="$NGINX_INFO_PATH/nginx.pid"
21
21
 
22
- conf_version=$(awk '{print $1}' "${pkg_path}"/version)
22
+ readonly MIME_TYPE_PATH=" ${MIME_TYPE}/"
23
+
24
+
25
+ conf_version=$(awk '{print $1}' "${PKG_DIR}"/version)
23
26
  echo "$conf_version"
24
27
 
25
- copy_nginx_conf_and_write_verison() {
26
- mkdir -p "$nginx_conf_install_path"
28
+ copy_nginx_conf_and_write_version() {
29
+ mkdir -p "$NGINX_CONF_INSTALL_PATH"
27
30
  # 创建pid目录. 创建日志目录
28
- mkdir -p $nginx_info_path
29
- touch $nginx_info_path/$nginx_log_file
30
- chown -R $user:$usergroup $nginx_info_path
31
- chmod 744 -R $nginx_info_path
31
+ mkdir -p $NGINX_INFO_PATH
32
+ touch $NGINX_INFO_PATH/$NGINX_LOG_FILE
33
+ chown -R $user:$usergroup $NGINX_INFO_PATH
34
+ chmod 744 -R $NGINX_INFO_PATH
32
35
 
33
36
  access_log_super="access_log /dev/stdout main"
34
37
  error_log_super="error_log /dev/stderr warn"
35
- access_log="access_log $nginx_info_path/$nginx_log_file main"
36
- error_log="error_log $nginx_info_path/$nginx_log_file"
37
- pid_file="pid $nginx_pid_file_path"
38
+ access_log="access_log $NGINX_INFO_PATH/$NGINX_LOG_FILE main"
39
+ error_log="error_log $NGINX_INFO_PATH/$NGINX_LOG_FILE"
40
+ pid_file="pid $NGINX_PID_FILE_PATH"
41
+ mime_type="include $INSTALL_PATH/mime.types;"
38
42
 
39
43
  exec=$(get_exec_path)
40
44
 
41
- # if [ -f "$nginx_conf_path" ]; then
42
- # old_version=$(sed -n '1p' "$nginx_conf_path" | sed 's/# version: //' | sed "s/\s\+//g")
45
+ # if [ -f "$NGINX_CONF_PATH" ]; then
46
+ # old_version=$(sed -n '1p' "$NGINX_CONF_PATH" | sed 's/# version: //' | sed "s/\s\+//g")
43
47
 
44
48
  # if [[ -n "${old_version}" ]]; then
45
49
  # now=$(date "+%Y-%m-%d_%H:%M:%S")
46
50
 
47
51
  # # echo "nginx_"$old_version"_"$now".conf"
48
- # mv "$nginx_conf_path" "${nginx_conf_install_path}"/"$app_name".nginx_"$old_version"_"$now".conf
52
+ # mv "$NGINX_CONF_PATH" "${NGINX_CONF_INSTALL_PATH}"/"$APP_NAME".nginx_"$old_version"_"$now".conf
49
53
  # fi
50
54
  # fi
51
55
 
@@ -53,7 +57,7 @@ copy_nginx_conf_and_write_verison() {
53
57
  nginx_version=$($exec -v 2>&1)
54
58
 
55
59
  tmp_file='./nginx/nginx.conf'
56
- cp -rf "$new_nginx_conf_path" ./
60
+ cp -rf "$NEW_NGINX_CONF_PATH" ./
57
61
 
58
62
  sed -i "1i\# ${nginx_version}" $tmp_file
59
63
  sed -i "1i\# version: ${conf_version}" $tmp_file
@@ -89,7 +93,7 @@ copy_nginx_conf_and_write_verison() {
89
93
  # fi
90
94
  fi
91
95
 
92
- n=$(grep -wn "#PID_FILE_PALCEHOLDER" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
96
+ n=$(grep -wn "#PID_FILE_PLACEHOLDER" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
93
97
  if [[ -n "${n}" ]]; then
94
98
  sed -i "${n}c ${pid_file};" $tmp_file
95
99
  # 非supervisorctl
@@ -107,23 +111,23 @@ copy_nginx_conf_and_write_verison() {
107
111
  fi
108
112
 
109
113
  # 拷贝整个nginx目录
110
- mv -fb ./nginx/* "$nginx_conf_install_path"
114
+ mv -fb ./nginx/* "$NGINX_CONF_INSTALL_PATH"
111
115
 
112
116
  mkdir -p /data/command/
113
117
  log "nginx start command: $(get_exec_cmd)"
114
- echo "$exec -c $nginx_conf_path" >/data/command/nginx
118
+ echo "$exec -c $NGINX_CONF_PATH" >/data/command/nginx
115
119
 
116
120
  if [[ $? == 0 ]]; then
117
- log_success "$conf_version $nginx_conf_path replaced successfully!"
121
+ log_success "$conf_version $NGINX_CONF_PATH replaced successfully!"
118
122
  else
119
- log_error "$conf_version $nginx_conf_path replaced failed!"
123
+ log_error "$conf_version $NGINX_CONF_PATH replaced failed!"
120
124
  fi
121
125
  }
122
126
 
123
127
  get_exec_path() {
124
128
  cmd=''
125
129
  if [[ -n "${prefix}" ]]; then
126
- cmd="${nginx_conf_install_path}/sbin/nginx"
130
+ cmd="${NGINX_CONF_INSTALL_PATH}/sbin/nginx"
127
131
  else
128
132
  cmd="/usr/sbin/nginx"
129
133
  fi
@@ -134,63 +138,60 @@ get_exec_path() {
134
138
  get_exec_cmd() {
135
139
  exec=$(get_exec_path)
136
140
 
137
- echo "$exec -c $nginx_conf_path"
141
+ echo "$exec -c $NGINX_CONF_PATH"
138
142
  }
139
143
 
140
144
  add_nginx_service() {
141
145
  #添加到服务
142
- exec_cmd="$(get_exec_cmd) -e $nginx_info_path/$nginx_log_file"
143
- cp "$pkg_path"/nginx/nginx.service.tpl ./nginx.service
146
+ exec_cmd="$(get_exec_cmd) -e $NGINX_INFO_PATH/$NGINX_LOG_FILE"
147
+ cp "$PKG_DIR"/nginx/nginx.service.tpl ./nginx.service
144
148
 
145
- check_cmd="$exec -t -c $nginx_conf_path -e $nginx_info_path/$nginx_log_file"
149
+ check_cmd="$exec -t -c $NGINX_CONF_PATH -e $NGINX_INFO_PATH/$NGINX_LOG_FILE"
146
150
  version=$(echo "$conf_version" | grep -oP '\d+\.\d+\.\d+')
147
151
 
148
152
  sed -i "s#_user_group_#$usergroup#g" ./nginx.service
149
153
  sed -i "s#_user_#$user#g" ./nginx.service
150
154
  sed -i "s#_exec_cmd_#$exec_cmd #g" ./nginx.service
151
- sed -i "s#_log_path_#$nginx_info_path#g" ./nginx.service
152
- sed -i "s#_log_file_#$nginx_log_file#g" ./nginx.service
153
- sed -i "s#_conf_path_#$nginx_conf_path#g" ./nginx.service
155
+ sed -i "s#_log_path_#$NGINX_INFO_PATH#g" ./nginx.service
156
+ sed -i "s#_log_file_#$NGINX_LOG_FILE#g" ./nginx.service
157
+ sed -i "s#_conf_path_#$NGINX_CONF_PATH#g" ./nginx.service
154
158
  sed -i "s#_version_#$version#g" ./nginx.service
155
- sed -i "s#_pid_file_#$nginx_pid_file_path#g" ./nginx.service
159
+ sed -i "s#_pid_file_#$NGINX_PID_FILE_PATH#g" ./nginx.service
156
160
  #sed -i "s#_start_check_#$check_cmd#g" ./nginx.service
157
161
 
158
162
  if ((mode == 2)); then
159
163
  # systemctl enable nginx
160
- cp ./nginx.service /usr/lib/systemd/system/"$app_name".nginx.service
164
+ cp ./nginx.service /usr/lib/systemd/system/"$APP_NAME".nginx.service
161
165
  systemctl daemon-reload
162
166
 
163
- log_success "add ${app_name}.nginx.service to /usr/lib/systemd/system/"
167
+ log_success "add ${APP_NAME}.nginx.service to /usr/lib/systemd/system/"
164
168
  else
165
- rm -rf /usr/lib/systemd/system/"$app_name".nginx.service
169
+ rm -rf /usr/lib/systemd/system/"$APP_NAME".nginx.service
166
170
  fi
167
171
  }
168
172
 
169
173
  add_log_rotate(){
170
174
  mkdir -p /etc/logrotate.d
171
175
 
172
- rm -rf /etc/logrotate.d/${app_name}.nginx
176
+ rm -rf /etc/logrotate.d/${APP_NAME}.nginx
173
177
  #添加日志翻转
174
- cp "$pkg_path"/nginx/nginx.logrotate.tpl ./nginx.logrotate
178
+ cp "$PKG_DIR"/nginx/nginx.logrotate.tpl ./nginx.logrotate
175
179
 
176
180
  sed -i "s#__usergroup__#$usergroup#g" ./nginx.logrotate
177
181
  sed -i "s#__user__#$user#g" ./nginx.logrotate
178
- sed -i "s#__app_name__#$app_name#g" ./nginx.logrotate
179
- sed -i "s#__pid_file__#$nginx_pid_file_path#g" ./nginx.logrotate
182
+ sed -i "s#__APP_NAME__#$APP_NAME#g" ./nginx.logrotate
183
+ sed -i "s#__pid_file__#$NGINX_PID_FILE_PATH#g" ./nginx.logrotate
180
184
 
181
- cp -f ./nginx.logrotate /etc/logrotate.d/${app_name}.nginx
185
+ cp -f ./nginx.logrotate /etc/logrotate.d/${APP_NAME}.nginx
182
186
  }
183
187
  #------------------------------------ nginx服务配置文件服务 end----------------------------------
184
188
 
185
189
 
186
190
  #------------------------------------ nginx 可执行程序相关 start----------------------------------
187
- # 指定安装目录
188
- nginx_binary_install_path="/etc/nginx/"
189
-
190
- mkdir -p "$nginx_binary_install_path"
191
-
192
191
  # 安装包所在路径
193
- nginx_binary_pkg_path="${pkg_path}/nginx_binary"
192
+ readonly NGINX_BINARY_PKG_PATH="${PKG_DIR}/nginx_binary"
193
+
194
+ readonly NGINX_BINARY_INSTALL_PATH="/etc/nginx/"
194
195
 
195
196
  open_port_80() {
196
197
  # 查看防火墙是否开启
@@ -207,74 +208,57 @@ open_port_80() {
207
208
  # 重启防火墙(关键步骤二)
208
209
  firewall-cmd --reload
209
210
  }
210
-
211
- function check_dependency(){
212
- if [[ -z $(rpm -qa | grep ^gcc | grep -v grep) ]];
213
- then
214
- cd ${nginx_binary_pkg_path}/gcc && rpm -Uvh *.rpm --nodeps --force
215
- fi
216
- if [[ -z $(rpm -qa | grep ^gcc-c++ | grep -v grep) ]];
217
- then
218
- cd ${nginx_binary_pkg_path}/g++ && rpm -Uvh *.rpm --nodeps --force
219
- fi
220
- if [[ -z $(rpm -qa | grep ^zlib-devel | grep -v grep) ]];
221
- then
222
- cd ${nginx_binary_pkg_path}/zlib && rpm -Uvh *.rpm --nodeps --force
223
- fi
224
- if [[ -z $(rpm -qa | grep ^openssl-devel | grep -v grep) ]];
225
- then
226
- cd ${nginx_binary_pkg_path}/openssl && rpm -Uvh *.rpm --nodeps --force
227
- fi
228
- if [[ -z $(rpm -qa | grep ^pcre-devel | grep -v grep) ]];
229
- then
230
- cd ${nginx_binary_pkg_path}/pcre && rpm -Uvh *.rpm --nodeps --force
231
- fi
232
-
233
- cd $project_path/script
234
- }
235
-
236
-
237
211
 
238
212
  install_nginx_from_binary(){
239
213
  log "start to install nginx binary"
240
214
 
241
215
  arch=$(uname -m)
242
- ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
216
+ system_name=$(uname -r | awk -F'.' '{print $(NF-1)}')
217
+ ssl_full_version=$(openssl version | awk '{print $2}')
218
+ ssl_fuzzy_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
219
+ system_name_with_arch=$system_name"."$arch
243
220
 
244
- if [[ -z "${arch}" ]]; then
245
- arch="x86_64"
246
- fi
221
+ # 若存在完整的系统名称.架构.ssl版本的包则优先使用该包安装
222
+ pkg="$NGINX_BINARY_PKG_PATH"/binary/nginx-"$system_name_with_arch"-ssl"$ssl_full_version".tar.gz
247
223
 
248
- if [[ $arch == arm* ]] || [[ $arch = aarch64 ]]; then
249
- arch="arm"
250
- fi
224
+ if [ -f "$pkg" ]; then
225
+ log "current arch: $system_name_with_arch, current ssl_version: $ssl_full_version"
226
+ else
227
+ if [[ -z "${arch}" ]]; then
228
+ arch="x86_64"
229
+ fi
251
230
 
252
- if [[ "${ssl_version}" == "1.0" ]]; then
253
- ssl_version="1.0.2"
254
- fi
231
+ if [[ $arch == arm* ]] || [[ $arch = aarch64 ]]; then
232
+ arch="arm"
233
+ fi
255
234
 
256
- if [[ "${ssl_version}" == "1.1" ]]; then
257
- ssl_version="1.1.1"
258
- fi
235
+ if [[ "${ssl_fuzzy_version}" == "1.0" ]]; then
236
+ ssl_fuzzy_version="1.0.2"
237
+ fi
259
238
 
260
- if [[ "${ssl_version}" == "3.0" ]]; then
261
- ssl_version="3.0.7"
262
- fi
239
+ if [[ "${ssl_fuzzy_version}" == "1.1" ]]; then
240
+ ssl_fuzzy_version="1.1.1"
241
+ fi
263
242
 
264
- if [[ -z "${ssl_version}" ]]; then
265
- ssl_version="1.0.2"
266
- fi
243
+ if [[ "${ssl_fuzzy_version}" == "3.0" ]]; then
244
+ ssl_fuzzy_version="3.0.7"
245
+ fi
267
246
 
268
- pkg="$nginx_binary_pkg_path"/binary/nginx-"$arch"-ssl"$ssl_version".tar.gz
247
+ if [[ -z "${ssl_fuzzy_version}" ]]; then
248
+ ssl_fuzzy_version="1.0.2"
249
+ fi
269
250
 
270
- if [ ! -f "$pkg" ]; then
271
- log_error "Fatal error: nginx-$arch-ssl$ssl_version.tar.gz not matched! contact developer!"
272
- exit 1
273
- fi
251
+ pkg="$NGINX_BINARY_PKG_PATH"/binary/nginx-"$arch"-ssl"$ssl_fuzzy_version".tar.gz
252
+
253
+ if [ ! -f "$pkg" ]; then
254
+ log_error "Fatal error: nginx-$arch-ssl$ssl_fuzzy_version.tar.gz not matched! contact developer!"
255
+ exit 1
256
+ fi
274
257
 
275
- log "current arch: $arch, current ssl_version: $ssl_version"
258
+ log "current arch: $arch, current ssl_version: $ssl_fuzzy_version"
259
+ fi
276
260
 
277
- tar -zxvhf "$pkg" -C "$nginx_binary_install_path" --strip-components 1
261
+ tar -zxvhf "$pkg" -C "$NGINX_BINARY_INSTALL_PATH" --strip-components 1
278
262
 
279
263
  # 检测是否安装成功
280
264
  if [[ $? == 0 ]]; then
@@ -288,7 +272,7 @@ install_nginx_from_binary(){
288
272
 
289
273
  install_nginx_from_source(){
290
274
  log "start to complie and install nginx"
291
- pkg="$nginx_binary_pkg_path"/source/
275
+ pkg="$NGINX_BINARY_PKG_PATH"/source/
292
276
  tar_name=$(ls ${pkg}|grep nginx-.*.tar.gz)
293
277
  tar_dir=${tar_name%.tar.gz*}
294
278
  tar -zxvf "${pkg}"/"${tar_name}"
@@ -300,7 +284,7 @@ install_nginx_from_source(){
300
284
  --with-http_gzip_static_module \
301
285
  --with-http_stub_status_module \
302
286
  --with-stream \
303
- --prefix=${nginx_binary_install_path}
287
+ --prefix=${NGINX_BINARY_INSTALL_PATH}
304
288
 
305
289
  make && make install
306
290
  # 检测是否安装成功
@@ -310,13 +294,13 @@ install_nginx_from_source(){
310
294
  log_error "nginx installation failed!"
311
295
  fi
312
296
 
313
- cp $nginx_binary_install_path/conf/mime.types $nginx_binary_install_path
297
+ cp $NGINX_BINARY_INSTALL_PATH/conf/mime.types $NGINX_BINARY_INSTALL_PATH
314
298
  cd ..
315
299
  }
316
300
 
317
301
  # 安装nginx可执行程序
318
302
  install_nginx_binary() {
319
- log "install nginx to path: ${nginx_binary_install_path}"
303
+ log "install nginx to path: ${NGINX_BINARY_INSTALL_PATH}"
320
304
 
321
305
  if [[ "${nginx_install_mode}" == "source" ]]; then
322
306
  install_nginx_from_source
@@ -326,6 +310,6 @@ install_nginx_binary() {
326
310
 
327
311
  mkdir -p /usr/local/bin
328
312
  mkdir -p /var/log/nginx
329
- ln -sf "$nginx_binary_install_path"sbin/nginx /usr/sbin/nginx
313
+ ln -sf "$NGINX_BINARY_INSTALL_PATH"sbin/nginx /usr/sbin/nginx
330
314
  }
331
315
  #------------------------------------ nginx 可执行程序相关 end ----------------------------------
package/dist/prepare.js CHANGED
@@ -39,6 +39,8 @@ const releaseConf = Object.assign({
39
39
  userGroup: "root",
40
40
  installMode: "all",
41
41
  installDir: "/opt",
42
+ nginxBinaryDir: "/etc/nginx",
43
+ nginxConfDir: "/etc/nginx",
42
44
  nginxInstallMode: "binary",
43
45
  dockerInstallDir: "",
44
46
  dockerBackupDir: ""
@@ -79,10 +81,7 @@ async function checkEnvInfo() {
79
81
  process.exit(1);
80
82
  }
81
83
  for (let [field, value] of Object.entries(releaseConf)) {
82
- if (!value) {
83
- logger.error(`The field: [${field}] is required in .release/release.conf.yaml!`);
84
- process.exit(1);
85
- }
84
+ validateField(field);
86
85
  if (field === "installMode" && !installMode.includes(value)) {
87
86
  logger.error(`The field: [${field}]'s value should be one of ${installMode.join(" | ")}`);
88
87
  process.exit(1);
@@ -97,5 +96,16 @@ async function checkEnvInfo() {
97
96
  }
98
97
  }
99
98
  }
99
+ function validateFields(fields) {
100
+ for (let field of fields) {
101
+ validateField(field);
102
+ }
103
+ }
104
+ function validateField(field) {
105
+ if (!releaseConf[field]) {
106
+ logger.error(`The field: [${field}] is required in .release/release.conf.yaml!`);
107
+ process.exit(1);
108
+ }
109
+ }
100
110
 
101
- export { __dirname, __releaseConfPath, __releaseDir, __work_dir, checkEnvInfo, prepare, releaseConf, releaseConfFileName };
111
+ export { __dirname, __releaseConfPath, __releaseDir, __work_dir, checkEnvInfo, prepare, releaseConf, releaseConfFileName, validateField, validateFields };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wjwjq/release-helper",
3
- "version": "0.2.96",
3
+ "version": "0.2.97",
4
4
  "description": "generate deployment package for frontend, include nginx...",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",