update-motd-updates-available 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh -e
  2. #
  3. # helper for update-motd
  4. # poor mans force
  5. if [ "$1" = "--force" ]; then
  6. NEED_UPDATE_CHECK=yes
  7. else
  8. NEED_UPDATE_CHECK=no
  9. fi
  10. # check time when we did the last update check
  11. stamp="/var/lib/update-notifier/updates-available"
  12. # get list dir
  13. StateDir="/var/lib/apt/"
  14. ListDir="lists/"
  15. eval "$(apt-config shell StateDir Dir::State)"
  16. eval "$(apt-config shell ListDir Dir::State::Lists)"
  17. # get dpkg status file
  18. DpkgStatus="/var/lib/dpkg/status"
  19. eval "$(apt-config shell DpkgStatus Dir::State::status)"
  20. # get sources.list file
  21. EtcDir="etc/apt/"
  22. SourceList="sources.list"
  23. eval "$(apt-config shell EtcDir Dir::Etc)"
  24. eval "$(apt-config shell SourceList Dir::Etc::sourcelist)"
  25. # let the actual update be asynchronous to avoid stalling apt-get
  26. cleanup() { rm -f "$tmpfile"; }
  27. # check if we have a list file or sources.list that needs checking
  28. if [ -e "$stamp" ]; then
  29. if [ "$(find "/$StateDir/$ListDir" "/$EtcDir/$SourceList" "/$DpkgStatus" -type f -newer "$stamp" -print -quit)" ]; then
  30. NEED_UPDATE_CHECK=yes
  31. fi
  32. else
  33. if [ "$(find "/$StateDir/$ListDir" "/$EtcDir/$SourceList" -type f -print -quit)" ]; then
  34. NEED_UPDATE_CHECK=yes
  35. fi
  36. fi
  37. tmpfile=""
  38. trap cleanup EXIT
  39. tmpfile=$(mktemp -p $(dirname "$stamp"))
  40. # output something for update-motd
  41. if [ "$NEED_UPDATE_CHECK" = "yes" ]; then
  42. {
  43. echo ""
  44. /usr/lib/update-notifier/apt-check --human-readable
  45. echo ""
  46. } > "$tmpfile"
  47. mv "$tmpfile" "$stamp"
  48. chmod +r "$stamp"
  49. fi