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