apt.cron.daily 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if [ $delta -ge $interval ]; then
  19. return 0
  20. fi
  21. return 1
  22. }
  23. update_stamp()
  24. {
  25. stamp="$1"
  26. touch $stamp
  27. }
  28. UpdateInterval=0
  29. DownloadUpgradeableInterval=0
  30. eval $(apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists DownloadUpgradeableInterval APT::Periodic::Download-Upgradeable-Packages)
  31. AutocleanInterval=$DownloadUpgradeableInterval
  32. eval $(apt-config shell AutocleanInterval APT::Periodic::Autoclean)
  33. # laptop check, on_ac_power returns:
  34. # 0 (true) System is on mains power
  35. # 1 (false) System is not on mains power
  36. # 255 (false) Power status could not be determined
  37. # Desktop systems always return 255 it seems
  38. if which on_ac_power >/dev/null; then
  39. on_ac_power
  40. if [ $? -eq 1 ]; then
  41. exit 0
  42. fi
  43. fi
  44. UPDATE_STAMP=/var/lib/apt/periodic/update-stamp
  45. if check_stamp $UPDATE_STAMP $UpdateInterval; then
  46. if apt-get -qq update 2>/dev/null; then
  47. if which dbus-send >/dev/null; then
  48. dbus-send --system / app.apt.dbus.updated boolean:true
  49. fi
  50. update_stamp $UPDATE_STAMP
  51. fi
  52. fi
  53. DOWNLOAD_UPGRADEABLE_STAMP=/var/lib/apt/periodic/download-upgradeable-stamp
  54. if check_stamp $DOWNLOAD_UPGRADEABLE_STAMP $DownloadUpgradeableInterval; then
  55. apt-get -qq -d dist-upgrade 2>/dev/null
  56. update_stamp $DOWNLOAD_UPGRADEABLE_STAMP
  57. fi
  58. AUTOCLEAN_STAMP=/var/lib/apt/periodic/autoclean-stamp
  59. if check_stamp $AUTOCLEAN_STAMP $AutocleanInterval; then
  60. apt-get -qq autoclean
  61. update_stamp $AUTOCLEAN_STAMP
  62. fi