update 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh
  2. die()
  3. {
  4. echo "$*" >&2
  5. exit 1
  6. }
  7. info()
  8. {
  9. echo "--- $*"
  10. }
  11. usage()
  12. {
  13. echo "update [OPTIONS]"
  14. echo
  15. echo "Options:"
  16. echo " -f|--full Full upgrade"
  17. echo " -d|--download-only Download only"
  18. }
  19. full=0
  20. download_only=0
  21. while [ $# -ge 1 ]; do
  22. case "$1" in
  23. -f|--full)
  24. full=1
  25. ;;
  26. -d|--download-only)
  27. download_only=1
  28. ;;
  29. -h|--help)
  30. usage
  31. exit 0
  32. ;;
  33. *)
  34. die "Unknown parameter: $1"
  35. ;;
  36. esac
  37. shift
  38. done
  39. # Be nice
  40. nice=19
  41. renice $nice $$ >/dev/null || echo "Failed to renice to $nice" >&2
  42. if [ $full -eq 0 ]; then
  43. upgrade_mode="upgrade"
  44. else
  45. upgrade_mode="full-upgrade"
  46. fi
  47. info "Updating package list"
  48. apt update || die "Update failed"
  49. # Do the download and upgrade.
  50. info "Performing '$upgrade_mode'"
  51. dl_flags=
  52. [ $download_only -ne 0 ] && dl_flags="--download-only"
  53. apt $dl_flags --show-upgraded --verbose-versions "$upgrade_mode" ||\
  54. die "Upgrade failed"
  55. # Exit here, if download only.
  56. [ $download_only -ne 0 ] && exit 0
  57. # Purge packages, if full upgrade.
  58. if [ $full -ne 0 ]; then
  59. info "Purging old packages"
  60. apt-get autoremove --purge || die "Autoremove failed"
  61. fi
  62. info "Cleaning"
  63. apt-get clean || die "Clean failed"
  64. if command -v flatpak >/dev/null 2>&1; then
  65. info "Updating flatpaks"
  66. flatpak update || die "flatpak update failed"
  67. fi
  68. if command -v rpi-eeprom-update >/dev/null 2>&1; then
  69. info "Updating Raspberry Pi EEPROMs"
  70. rpi-eeprom-update -a || die "Raspberry Pi EEPROM update failed"
  71. fi
  72. exit 0