check_for_upgrade.sh 861 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
27
  if [ $epoch_diff -gt 6 ]
  then
28
    if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
29
    then
30
31
32
33
34
35
36
37
38
      _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
      if [ "$line" = Y ] || [ "$line" = y ]
      then
        _upgrade_zsh
      fi
39
40
    fi
  fi
nebirhos's avatar
nebirhos committed
41
42
43
else
  # create the zsh file
  _update_zsh_update
44
fi
45