Browse Source

create task process 20.01.25:2.09

root 2 months ago
parent
commit
984a49767c
2 changed files with 51 additions and 31 deletions
  1. 2 3
      avto4certbot.dev/avto4certbot.conf
  2. 49 28
      avto4certbot.dev/avto4certbot.sh

+ 2 - 3
avto4certbot.dev/avto4certbot.conf

@@ -1,13 +1,12 @@
1
 ## config file
1
 ## config file
2
 ## domains - follow the format! domains email port...
2
 ## domains - follow the format! domains email port...
3
 domains=( 
3
 domains=( 
4
- "mydomen.ru admin@mydomen.ru 80"
5
- "mydomen2.ru admin@mydomen.ru 80"
4
+ "mydomains.ru admin@mydomains.ru 8080"
6
  );
5
  );
7
 
6
 
8
 ## if update - restart this services
7
 ## if update - restart this services
9
 services=(
8
 services=(
10
-    "apache2"
9
+    "nginx"
11
  );
10
  );
12
 
11
 
13
 ## - nginx sites
12
 ## - nginx sites

+ 49 - 28
avto4certbot.dev/avto4certbot.sh

@@ -1,4 +1,4 @@
1
-#!/bin/bash
1
+#!/bin/bash -x
2
 #
2
 #
3
 # author: Koshuba V.O.
3
 # author: Koshuba V.O.
4
 # license: GPL 2.0
4
 # license: GPL 2.0
@@ -23,6 +23,9 @@ event_key="1";
23
 # message from errors
23
 # message from errors
24
 reports=();
24
 reports=();
25
 
25
 
26
+# work_sites
27
+active_sites=();
28
+
26
 ##--@S static values
29
 ##--@S static values
27
 # depends
30
 # depends
28
 pkgdep=("curl" "certbot" "letsencrypt") # packages
31
 pkgdep=("curl" "certbot" "letsencrypt") # packages
@@ -122,36 +125,42 @@ function checkDep() {
122
 }
125
 }
123
 
126
 
124
 function swSites(){
127
 function swSites(){
125
-## clear job link
128
+## clear active sites
126
 if [ "$event_key" = "1" ]; then
129
 if [ "$event_key" = "1" ]; then
127
-  for ((xd=0; xd != ${#domains[@]}; xd++)); do
128
-    local site_data=( $(echo -e ${domains[$xd]}|sed 's/ /\n /g') );
129
-    site_name="${site_data[0]}";
130
-    if [[ $opt != "nginx" ]] || [[ "$opt" == "apache" ]]; then
131
-      if [ -f $sites_apache/$site_name.conf ]; then
132
-        rm $sites_apache/$site_name.conf
130
+active_sites=( $(cat $tmp_dir/active_sites.inf) );
131
+  for ((xd=0; xd != ${#active_sites[@]}; xd++)); do
132
+    if [[ $opt != "nginx" ]] || [[ "$opt" == "apache" ]] && [[ "$opt" != "" ]]; then
133
+      if [ -f $sites_apache/${active_sites[$xd]} ]; then
134
+        rm $sites_apache/${active_sites[$xd]}
133
       fi
135
       fi
134
     fi
136
     fi
135
-    if [[ $opt != "apache" ]] || [[ "$opt" == "nginx" ]]; then
136
-      if [ -f $sites_nginx/$site_name.conf ]; then
137
-        rm $sites_nginx/$site_name.conf
137
+    if [[ $opt != "apache" ]] || [[ "$opt" == "nginx" ]] && [[ "$opt" != "" ]]; then
138
+      if [ -f $sites_nginx/${active_sites[$xd]} ]; then
139
+        rm $sites_nginx/${active_sites[$xd]}
138
       fi
140
       fi
139
     fi
141
     fi
140
   done
142
   done
141
 fi
143
 fi
142
-## restore job link
144
+## restore active sites
143
 if [ "$event_key" = "0" ]; then
145
 if [ "$event_key" = "0" ]; then
144
-  for ((xd=0; xd != ${#domains[@]}; xd++)); do
145
-    local site_data=( $(echo -e ${domains[$xd]}|sed 's/ /\n /g') );
146
-    site_name="${site_data[0]}";
147
-    if [[ $opt != "nginx" ]] || [[ "$opt" == "apache" ]]; then
148
-      if [ ! -f $sites_apache/$site_name.conf ]; then
149
-        ln -s $available_apache/$site_name.conf $sites_apache/$site_name.conf
146
+  # clear tmp configs
147
+  if [[ $opt != "nginx" ]] || [[ "$opt" == "apache" ]] && [[ "$opt" != "" ]]; then
148
+    rm $available_apache/*.conf
149
+  fi
150
+  if [[ $opt != "apache" ]] || [[ "$opt" == "nginx" ]] && [[ "$opt" != "" ]]; then
151
+    rm $available_nginx/*.conf
152
+  fi
153
+  # restore active links
154
+  active_sites=( $(cat $tmp_dir/active_sites.inf) );
155
+  for ((xd=0; xd != ${#active_sites[@]}; xd++)); do
156
+    if [[ $opt != "nginx" ]] || [[ "$opt" == "apache" ]] && [[ "$opt" != "" ]]; then
157
+      if [ ! -f $sites_apache/${active_sites[$xd]} ]; then
158
+        ln -s $available_apache/${active_sites[$xd]} $sites_apache/${active_sites[$xd]}
150
       fi
159
       fi
151
     fi
160
     fi
152
-    if [[ $opt != "apache" ]] || [[ "$opt" == "nginx" ]]; then
153
-      if [ ! -f $sites_nginx/$site_name.conf ]; then
154
-        ln -s $available_nginx/$site_name.conf $sites_apache/$site_name.conf
161
+    if [[ $opt != "apache" ]] || [[ "$opt" == "nginx" ]] && [[ "$opt" != "" ]]; then
162
+      if [ ! -f $sites_nginx/${active_sites[$xd]} ]; then
163
+        ln -s $available_nginx/${active_sites[$xd]} $sites_apache/${active_sites[$xd]}
155
       fi
164
       fi
156
     fi
165
     fi
157
   done
166
   done
@@ -228,7 +237,7 @@ for ((xd=0; xd != ${#domains[@]}; xd++)); do
228
   site_owner="${site_data[1]}";
237
   site_owner="${site_data[1]}";
229
   site_port="${site_data[2]}";
238
   site_port="${site_data[2]}";
230
   ## apache2 config
239
   ## apache2 config
231
-  if [[ $opt != "nginx" ]] || [[ "$opt" == "apache" ]]; then
240
+  if [[ $opt != "nginx" ]] || [[ "$opt" == "apache" ]] && [[ "$opt" != "" ]] ; then
232
     echo >$conf_dir/$site_name.conf;
241
     echo >$conf_dir/$site_name.conf;
233
     echo -e '<VirtualHost *:'"$site_port"'>' >>$conf_dir/$site_name.conf;
242
     echo -e '<VirtualHost *:'"$site_port"'>' >>$conf_dir/$site_name.conf;
234
     echo -e '  ServerName '"$site_name"'' >>$conf_dir/$site_name.conf;
243
     echo -e '  ServerName '"$site_name"'' >>$conf_dir/$site_name.conf;
@@ -251,7 +260,7 @@ for ((xd=0; xd != ${#domains[@]}; xd++)); do
251
   fi
260
   fi
252
 
261
 
253
   ## nginx config
262
   ## nginx config
254
-  if [[ $opt != "apache" ]] || [[ "$opt" == "nginx" ]]; then
263
+  if [[ $opt != "apache" ]] || [[ "$opt" == "nginx" ]] && [[ "$opt" != "" ]]; then
255
     echo >$conf_dir/$site_name.conf;
264
     echo >$conf_dir/$site_name.conf;
256
     echo -e 'server { listen 0.0.0.0:'"$site_port"';' >>$conf_dir/$site_name.conf;
265
     echo -e 'server { listen 0.0.0.0:'"$site_port"';' >>$conf_dir/$site_name.conf;
257
     echo -e '  server_name '"$site_name"';' >>$conf_dir/$site_name.conf;
266
     echo -e '  server_name '"$site_name"';' >>$conf_dir/$site_name.conf;
@@ -293,6 +302,7 @@ echo "  avtocertbot.sh --update nginx"
293
 case "$cmd" in
302
 case "$cmd" in
294
   ## create cert
303
   ## create cert
295
   "--create" | "--create" )
304
   "--create" | "--create" )
305
+if [ "$opt" != "" ]; then
296
     getInfo;
306
     getInfo;
297
     checkDep;
307
     checkDep;
298
     event_key="1";
308
     event_key="1";
@@ -300,16 +310,20 @@ case "$cmd" in
300
     swSites;
310
     swSites;
301
     createConf;
311
     createConf;
302
     systemctl start $service;
312
     systemctl start $service;
303
-    createCert;
304
-    scanSSL;
313
+    #createCert;
314
+    #scanSSL;
305
     event_key="0";
315
     event_key="0";
306
     systemctl stop $service;
316
     systemctl stop $service;
307
     swSites;
317
     swSites;
308
     systemctl start $service;
318
     systemctl start $service;
319
+else
320
+    pHelp;
321
+fi
309
   ;;
322
   ;;
310
 
323
 
311
-  ## create cert
324
+  ## update cert
312
   "--update" | "--update" )
325
   "--update" | "--update" )
326
+if [ "$opt" != "" ]; then
313
    getInfo;
327
    getInfo;
314
    checkDep;
328
    checkDep;
315
    event_key="1";
329
    event_key="1";
@@ -317,19 +331,26 @@ case "$cmd" in
317
    swSites;
331
    swSites;
318
    createConf;
332
    createConf;
319
    systemctl start $service;
333
    systemctl start $service;
320
-   certbot -n renew;
321
-   scanSSL;
334
+   #certbot -n renew;
335
+   #scanSSL;
322
    event_key="0";
336
    event_key="0";
323
    systemctl stop $service;
337
    systemctl stop $service;
324
    swSites;
338
    swSites;
325
    systemctl start $service;
339
    systemctl start $service;
340
+else
341
+    pHelp;
342
+fi
326
   ;;
343
   ;;
327
 
344
 
328
   ## create cert
345
   ## create cert
329
   "--flist" | "--flist" )
346
   "--flist" | "--flist" )
347
+if [ "$opt" != "" ]; then
330
     getInfo;
348
     getInfo;
331
     checkDep;
349
     checkDep;
332
     scanSSL;
350
     scanSSL;
351
+else
352
+    pHelp;
353
+fi
333
   ;;
354
   ;;
334
 
355
 
335
   ## start defaults
356
   ## start defaults