update-lxcs.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. set -e
  3. YW=`echo "\033[33m"`
  4. BL=`echo "\033[36m"`
  5. RD=`echo "\033[01;31m"`
  6. CM='\xE2\x9C\x94\033'
  7. GN=`echo "\033[1;92m"`
  8. CL=`echo "\033[m"`
  9. while true; do
  10. read -p "This Will Update All LXC Containers. Proceed(y/n)?" yn
  11. case $yn in
  12. [Yy]* ) break;;
  13. [Nn]* ) exit;;
  14. * ) echo "Please answer yes or no.";;
  15. esac
  16. done
  17. clear
  18. function header_info {
  19. echo -e "${BL}
  20. _ _ _____ _____ _______ ______
  21. | | | | __ \| __ \ /\|__ __| ____|
  22. | | | | |__) | | | | / \ | | | |__
  23. | | | | ___/| | | |/ /\ \ | | | __|
  24. | |__| | | | |__| / ____ \| | | |____
  25. \____/|_| |_____/_/ \_\_| |______|
  26. ${CL}"
  27. }
  28. header_info
  29. containers=$(pct list | tail -n +2 | cut -f1 -d' ')
  30. function update_container() {
  31. container=$1
  32. echo -e "${BL}[Info]${GN} Updating${BL} $container... ${CL}"
  33. # to chain commands within one exec we will need to wrap them in bash
  34. pct exec $container -- bash -c "apt update && apt upgrade -y && apt autoremove -y"
  35. }
  36. for container in $containers
  37. do
  38. status=`pct status $container`
  39. if [ "$status" == "status: stopped" ]; then
  40. echo -e "${BL}[Info]${GN} Starting${BL} $container... ${CL}"
  41. pct start $container
  42. echo -e "${BL}[Info]${GN} Waiting For${BL} $container To Start... ${CL}"
  43. sleep 5
  44. update_container $container
  45. echo -e "${BL}[Info]${GN} Shutting down${BL} $container ${CL}"
  46. pct shutdown $container &
  47. elif [ "$status" == "status: running" ]; then
  48. update_container $container
  49. fi
  50. done; wait