reboot_required 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/sh -e
  2. #
  3. # reboot_required: determine if a reboot is required
  4. #
  5. # Copyright (C) 2008 Canonical Ltd.
  6. # Copyright (C) 2011-2014 Dustin Kirkland
  7. #
  8. # Authors: Dustin Kirkland <kirkland@byobu.org>
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, version 3 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. REBOOT_FLAG="/var/run/reboot-required"
  22. RELOAD_FLAG="$BYOBU_RUN_DIR/reload-required"
  23. POWERNAP_FLAG="/var/run/powernap/powersave"
  24. UNATTENDED_UPGRADE_FLAG="/var/run/unattended-upgrades.pid"
  25. __reboot_required_detail() {
  26. [ -e "$REBOOT_FLAG" ] && ls -alF "$REBOOT_FLAG" 2>&1
  27. [ -e "$RELOAD_FLAG" ] && ls -alF "$RELOAD_FLAG" 2>&1
  28. [ -e "$POWERNAP_FLAG" ] && ls -alF "$POWERNAP_FLAG" 2>&1
  29. [ -e "$POWERNAP_FLAG" ] && cat "$POWERNAP_FLAG" 2>&1
  30. }
  31. __reboot_required() {
  32. local status="$BYOBU_RUN_DIR/status.$BYOBU_BACKEND/reboot_required"
  33. local livepatched=0
  34. if [ -e "$UNATTENDED_UPGRADE_FLAG" ]; then
  35. color b R W; printf "$ICON_UPGRADE "; color --;
  36. fi
  37. while read line; do
  38. set -- ${line}
  39. case "$line" in
  40. kpatch_livepatch_*)
  41. color k G; printf "$ICON_LIVEPATCHED"; color -;
  42. livepatched=1
  43. break
  44. ;;
  45. esac
  46. done < /proc/modules
  47. if [ -e "$REBOOT_FLAG" ]; then
  48. if [ "$livepatched" = "1" ]; then
  49. color k G; printf "$ICON_REBOOT"; color --;
  50. else
  51. color b k R; printf "$ICON_REBOOT"; color --;
  52. fi
  53. fi
  54. if [ -e "$RELOAD_FLAG" ]; then
  55. color b W; printf "<"; color -; color b b W; printf "F5"; color -; color b W; printf ">"; color -; printf " "
  56. elif [ -s "$status" ]; then
  57. rm -f "$status"
  58. fi
  59. if [ -e "$POWERNAP_FLAG" ]; then
  60. color b W; printf ".zZ"; color --
  61. elif [ -s "$status" ]; then
  62. rm -f "$status"
  63. fi
  64. }
  65. # vi: syntax=sh ts=4 noexpandtab