apt.cron.daily 1.5 KB

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