Skip to content

Commit

Permalink
Updating check_for_upgrade script to fix issue when the LAST_EPOCH fi…
Browse files Browse the repository at this point in the history
…le/value got corrupted. Closes ohmyzsh#32
  • Loading branch information
robbyrussell authored and dgiunta committed Apr 29, 2011
1 parent a27b19e commit adb320b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tools/check_for_upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#!/bin/sh

current_epoch=$(($(date +%s) / 60 / 60 / 24))
function _current_epoch() {
echo $(($(date +%s) / 60 / 60 / 24))
}

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

if [ -f ~/.zsh-update ]
then
. ~/.zsh-update
epoch_diff=$(($current_epoch - $LAST_EPOCH))

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

epoch_diff=$((${_current_epoch} - $LAST_EPOCH))
if [ $epoch_diff -gt 6 ]
then
echo "[Oh My Zsh] Would you like to check for updates?"
Expand All @@ -15,14 +26,9 @@ then
then
/bin/sh $ZSH/tools/upgrade.sh
fi

# Set the last epoch to the current so that we don't ask for another week
echo "LAST_EPOCH=${current_epoch}" > ~/.zsh-update
fi
else
# TODO: refactor this so remove duplicates
# Create the ~/.zsh-update file with the current epoch info
echo "LAST_EPOCH=${current_epoch}" > ~/.zsh-update
fi

# update the zsh file
_update_zsh_update

0 comments on commit adb320b

Please sign in to comment.