update-lxcs.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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]$ ]]; then
  40. skip=no
  41. else
  42. skip=yes
  43. fi
  44. for container in $containers; do
  45. status=$(pct status $container)
  46. if [ "$skip" == "no" ]; then
  47. if [ "$status" == "status: stopped" ]; then
  48. echo -e "${BL}[Info]${GN} Starting${BL} $container ${CL} \n"
  49. pct start $container
  50. echo -e "${BL}[Info]${GN} Waiting For${BL} $container${CL}${GN} To Start ${CL} \n"
  51. sleep 5
  52. update_container $container
  53. echo -e "${BL}[Info]${GN} Shutting down${BL} $container ${CL} \n"
  54. pct shutdown $container &
  55. elif [ "$status" == "status: running" ]; then
  56. update_container $container
  57. fi
  58. fi
  59. if [ "$skip" == "yes" ]; then
  60. if [ "$status" == "status: running" ]; then
  61. update_container $container
  62. fi
  63. fi
  64. done
  65. wait
  66. echo -e "${GN} Finished, All Containers Updated. ${CL} \n"