check_for_upgrade.sh 1.3 KB

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