update-lxcs.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. clear
  33. header_info
  34. echo -e "${BL}[Info]${GN} Updating${BL} $container ${CL} \n"
  35. pct exec $container -- bash -c "apt update && apt upgrade -y && apt autoremove -y"
  36. }
  37. read -p "Skip stopped containers? " -n 1 -r
  38. echo
  39. if [[ ! $REPLY =~ ^[Yy]$ ]]
  40. then
  41. skip=no
  42. else
  43. skip=yes
  44. fi
  45. for container in $containers
  46. do
  47. status=`pct status $container`
  48. if [ "$skip" == "no" ]; then
  49. if [ "$status" == "status: stopped" ]; then
  50. echo -e "${BL}[Info]${GN} Starting${BL} $container ${CL} \n"
  51. pct start $container
  52. echo -e "${BL}[Info]${GN} Waiting For${BL} $container${CL}${GN} To Start ${CL} \n"
  53. sleep 5
  54. update_container $container
  55. echo -e "${BL}[Info]${GN} Shutting down${BL} $container ${CL} \n"
  56. pct shutdown $container &
  57. elif [ "$status" == "status: running" ]; then
  58. update_container $container
  59. fi
  60. fi
  61. if [ "$skip" == "yes" ]; then
  62. if [ "$status" == "status: running" ]; then
  63. update_container $container
  64. fi
  65. fi
  66. done; wait
  67. echo -e "${GN} Finished, All Containers Updated. ${CL} \n"