check_for_upgrade.sh 895 Bytes
Newer Older
1
2
#!/bin/sh

3
4
5
6
7
8
9
function _current_epoch() {
  echo $(($(date +%s) / 60 / 60 / 24))
}

function _update_zsh_update() {
  echo "LAST_EPOCH=$(_current_epoch)" > ~/.zsh-update
}
10

11
12
13
14
15
16
function _upgrade_zsh() {
  /usr/bin/env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
  # update the zsh file
  _update_zsh_update
}

17
18
if [ -f ~/.zsh-update ]
then
Gerhard Lazu's avatar
Gerhard Lazu committed
19
  . ~/.zsh-update
20
21
22
23
24

  if [[ -z "$LAST_EPOCH" ]]; then
    _update_zsh_update && return 0;
  fi

Christopher Chow's avatar
Christopher Chow committed
25
  epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
26
  if [ $epoch_diff -gt 13 ]
27
  then
28
    if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
29
    then
30
31
32
33
34
      _upgrade_zsh
    else
      echo "[Oh My Zsh] Would you like to check for updates?"
      echo "Type Y to update oh-my-zsh: \c"
      read line
35
      if [ "$line" = Y ] || [ "$line" = y ]; then
36
        _upgrade_zsh
37
38
      else
        _update_zsh_update
39
      fi
40
41
    fi
  fi
nebirhos's avatar
nebirhos committed
42
43
44
else
  # create the zsh file
  _update_zsh_update
45
fi
46