2
0
Эх сурвалжийг харах

[Update] added --force mode to update skript (#3453)

Alexander Holzapfel 5 жил өмнө
parent
commit
1b229412e3
1 өөрчлөгдсөн 20 нэмэгдсэн , 10 устгасан
  1. 20 10
      update.sh

+ 20 - 10
update.sh

@@ -88,18 +88,21 @@ docker_garbage() {
     echo
     echo
     echo "    docker rmi ${IMGS_TO_DELETE[*]}"
     echo "    docker rmi ${IMGS_TO_DELETE[*]}"
     echo
     echo
-    read -r -p "Do you want to delete old image tags right now? [y/N] " response
-    if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
-      docker rmi ${IMGS_TO_DELETE[*]}
+    if [ ! $FORCE ]; then
+      read -r -p "Do you want to delete old image tags right now? [y/N] " response
+      if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
+        docker rmi ${IMGS_TO_DELETE[*]}
+      else
+        echo "OK, skipped."
+      fi
     else
     else
-      echo "OK, skipped."
+      echo "Skipped image removal because of force mode."
     fi
     fi
   fi
   fi
   echo -e "\e[32mFurther cleanup...\e[0m"
   echo -e "\e[32mFurther cleanup...\e[0m"
   echo "If you want to cleanup further garbage collected by Docker, please make sure all containers are up and running before cleaning your system by executing \"docker system prune\""
   echo "If you want to cleanup further garbage collected by Docker, please make sure all containers are up and running before cleaning your system by executing \"docker system prune\""
 }
 }
 
 
-
 while (($#)); do
 while (($#)); do
   case "${1}" in
   case "${1}" in
     --check|-c)
     --check|-c)
@@ -133,6 +136,10 @@ while (($#)); do
       prefetch_images
       prefetch_images
       exit 0
       exit 0
     ;;
     ;;
+    -f|--force)
+      echo -e "\e[32mForcing Update...\e[0m"
+      FORCE=y
+    ;;
     --help|-h)
     --help|-h)
     echo './update.sh [-c|--check, --ours, --gc, --skip-start, -h|--help]
     echo './update.sh [-c|--check, --ours, --gc, --skip-start, -h|--help]
 
 
@@ -140,6 +147,7 @@ while (($#)); do
   --ours       -   Use merge strategy "ours" to solve conflicts in favor of non-mailcow code (local changes)
   --ours       -   Use merge strategy "ours" to solve conflicts in favor of non-mailcow code (local changes)
   --gc         -   Run garbage collector to delete old image tags
   --gc         -   Run garbage collector to delete old image tags
   --skip-start -   Do not start mailcow after update
   --skip-start -   Do not start mailcow after update
+  -f|--force   -   Force update, do not ask questions
 '
 '
     exit 1
     exit 1
   esac
   esac
@@ -356,7 +364,7 @@ SHA1_2=$(sha1sum update.sh)
 if [[ ${SHA1_1} != ${SHA1_2} ]]; then
 if [[ ${SHA1_1} != ${SHA1_2} ]]; then
   echo "update.sh changed, please run this script again, exiting."
   echo "update.sh changed, please run this script again, exiting."
   chmod +x update.sh
   chmod +x update.sh
-  exit 0
+  exit 2
 fi
 fi
 
 
 if [[ -f mailcow.conf ]]; then
 if [[ -f mailcow.conf ]]; then
@@ -366,10 +374,12 @@ else
   exit 1
   exit 1
 fi
 fi
 
 
-read -r -p "Are you sure you want to update mailcow: dockerized? All containers will be stopped. [y/N] " response
-if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
-  echo "OK, exiting."
-  exit 0
+if [ ! $FORCE ]; then
+  read -r -p "Are you sure you want to update mailcow: dockerized? All containers will be stopped. [y/N] " response
+  if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
+    echo "OK, exiting."
+    exit 0
+  fi
 fi
 fi
 
 
 echo -e "\e[32mValidating docker-compose stack configuration...\e[0m"
 echo -e "\e[32mValidating docker-compose stack configuration...\e[0m"