update-motd-hwe-eol 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/sh -e
  2. #
  3. # helper for update-motd
  4. # poor mans force
  5. if [ "$1" = "--force" ]; then
  6. NEED_EOL_CHECK=yes
  7. else
  8. if type systemd-detect-virt > /dev/null 2>&1 && systemd-detect-virt -q -c; then
  9. exit
  10. fi
  11. NEED_EOL_CHECK=no
  12. fi
  13. # check time when we did the last update check
  14. stamp="/var/lib/update-notifier/hwe-eol"
  15. # get list dir
  16. StateDir="/var/lib/apt/"
  17. ListDir="lists/"
  18. eval "$(apt-config shell StateDir Dir::State)"
  19. eval "$(apt-config shell ListDir Dir::State::Lists)"
  20. # get dpkg status file
  21. DpkgStatus="/var/lib/dpkg/status"
  22. eval "$(apt-config shell DpkgStatus Dir::State::status)"
  23. # get sources.list file
  24. EtcDir="etc/apt/"
  25. SourceList="sources.list"
  26. eval "$(apt-config shell EtcDir Dir::Etc)"
  27. eval "$(apt-config shell SourceList Dir::Etc::sourcelist)"
  28. # let the actual update be asynchronous to avoid stalling apt-get
  29. cleanup() { rm -f "$tmpfile"; }
  30. # check if we have a list file or sources.list that needs checking
  31. if [ -e "$stamp" ]; then
  32. if [ "$(find "/$StateDir/$ListDir" "/$EtcDir/$SourceList" "/$DpkgStatus" -type f -newer "$stamp" -print -quit 2> /dev/null)" ]; then
  33. NEED_EOL_CHECK=yes
  34. fi
  35. else
  36. if [ "$(find "/$StateDir/$ListDir" "/$EtcDir/$SourceList" -type f -print -quit 2> /dev/null)" ]; then
  37. NEED_EOL_CHECK=yes
  38. fi
  39. fi
  40. # only print status when running this script as a regular user
  41. if [ "$(id -u)" != 0 ] ; then
  42. [ "$NEED_EOL_CHECK" = "no" ] || /usr/bin/hwe-support-status || true
  43. exit
  44. fi
  45. tmpfile=""
  46. trap cleanup EXIT
  47. tmpfile=$(mktemp -p $(dirname "$stamp"))
  48. # output something for update-motd
  49. if [ "$NEED_EOL_CHECK" = "yes" ]; then
  50. {
  51. # the script may exit with status 10 when a HWE update is needed
  52. /usr/bin/hwe-support-status || true
  53. } > "$tmpfile"
  54. mv "$tmpfile" "$stamp"
  55. fi
  56. # output what we have (either cached or newly generated)
  57. cat "$stamp"