apt.cron.daily 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. #
  3. #set -e
  4. check_stamp()
  5. {
  6. stamp="$1"
  7. interval="$2"
  8. if [ $interval -eq 0 ]; then
  9. return 1
  10. fi
  11. if [ ! -f $stamp ]; then
  12. return 0
  13. fi
  14. # compare midnight today to midnight the day the stamp was updated
  15. stamp=$(date --date=$(date -r $stamp --iso-8601) +%s)
  16. now=$(date --date=$(date --iso-8601) +%s)
  17. delta=$(($now-$stamp))
  18. echo "stamp=$stamp, now=$now, delta=$delta"
  19. if [ $delta -ge $interval ]; then
  20. return 0
  21. fi
  22. return 1
  23. }
  24. update_stamp()
  25. {
  26. stamp="$1"
  27. touch $stamp
  28. }
  29. UpdateInterval=0
  30. DownloadUpgradeableInterval=0
  31. eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages)
  32. AutocleanInterval=$DownloadUpgradeableInterval
  33. eval $(apt-config shell AutocleanInterval APT::Periodic::Autoclean)
  34. # laptop check, on_ac_power returns:
  35. # 0 (true) System is on mains power
  36. # 1 (false) System is not on mains power
  37. # 255 (false) Power status could not be determined
  38. # Desktop systems always return 255 it seems
  39. if which on_ac_power >/dev/null; then
  40. on_ac_power
  41. if [ $? -eq 1 ]; then
  42. exit 0
  43. fi
  44. fi
  45. UPDATE_STAMP=/var/lib/apt/periodic/update-stamp
  46. if check_stamp $UPDATE_STAMP $UpdateInterval; then
  47. if apt-get -qq update 2>/dev/null; then
  48. if which dbus-send >/dev/null; then
  49. dbus-send --system / app.apt.dbus.updated boolean:true
  50. fi
  51. update_stamp $UPDATE_STAMP
  52. fi
  53. fi
  54. DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp
  55. if check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
  56. apt-get -qq -d dist-upgrade 2>/dev/null
  57. update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
  58. fi
  59. AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp
  60. if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then
  61. apt-get -qq autoclean
  62. update_stamp $AUTOCLEAN_STAMP
  63. fi