check_for_upgrade.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. function _current_epoch() {
  3. echo $(($(date +%s) / 60 / 60 / 24))
  4. }
  5. function _update_zsh_update() {
  6. echo "LAST_EPOCH=$(_current_epoch)" > ~/.zsh-update
  7. }
  8. function _upgrade_zsh() {
  9. /usr/bin/env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
  10. # update the zsh file
  11. _update_zsh_update
  12. }
  13. epoch_target=$UPDATE_ZSH_DAYS
  14. if [[ -z "$epoch_target" ]]; then
  15. # Default to old behavior
  16. epoch_target=13
  17. fi
  18. [ -f ~/.profile ] && source ~/.profile
  19. if [ -f ~/.zsh-update ]
  20. then
  21. . ~/.zsh-update
  22. if [[ -z "$LAST_EPOCH" ]]; then
  23. _update_zsh_update && return 0;
  24. fi
  25. epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
  26. if [ $epoch_diff -gt $epoch_target ]
  27. then
  28. if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
  29. then
  30. _upgrade_zsh
  31. else
  32. echo "[Oh My Zsh] Would you like to check for updates?"
  33. echo "Type Y to update oh-my-zsh: \c"
  34. read line
  35. if [ "$line" = Y ] || [ "$line" = y ]; then
  36. _upgrade_zsh
  37. else
  38. _update_zsh_update
  39. fi
  40. fi
  41. fi
  42. else
  43. # create the zsh file
  44. _update_zsh_update
  45. fi