check_for_upgrade.sh 1.04 KB
Newer Older
1
2
#!/bin/sh

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

function _update_zsh_update() {
8
  echo "LAST_EPOCH=$(_current_epoch)" >! ~/.zsh-update
9
}
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
}

Eric Danielson's avatar
Eric Danielson committed
17
18
19
20
21
22
epoch_target=$UPDATE_ZSH_DAYS
if [[ -z "$epoch_target" ]]; then
  # Default to old behavior
  epoch_target=13
fi

23
[ -f ~/.profile ] && source ~/.profile
24

25
26
if [ -f ~/.zsh-update ]
then
Gerhard Lazu's avatar
Gerhard Lazu committed
27
  . ~/.zsh-update
28
29
30
31
32

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

Christopher Chow's avatar
Christopher Chow committed
33
  epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
Eric Danielson's avatar
Eric Danielson committed
34
  if [ $epoch_diff -gt $epoch_target ]
35
  then
36
    if [ "$DISABLE_UPDATE_PROMPT" = "true" ]
37
    then
38
39
40
41
42
      _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
43
      if [ "$line" = Y ] || [ "$line" = y ]; then
44
        _upgrade_zsh
45
46
      else
        _update_zsh_update
47
      fi
48
49
    fi
  fi
nebirhos's avatar
nebirhos committed
50
51
52
else
  # create the zsh file
  _update_zsh_update
53
fi
54