Browse code

Updating check_for_upgrade script to fix issue when the LAST_EPOCH file/value got corrupted. Closes #32

Robby Russell authored on 12/12/2009 at 21:45:30
Showing 1 changed files
... ...
@@ -1,11 +1,22 @@
1 1
 #!/bin/sh
2 2
 
3
-current_epoch=$(($(date +%s) / 60 / 60 / 24))
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
+}
4 10
 
5 11
 if [ -f ~/.zsh-update ]
6 12
 then
7 13
   . ~/.zsh-update
8
-  epoch_diff=$(($current_epoch - $LAST_EPOCH))
14
+
15
+  if [[ -z "$LAST_EPOCH" ]]; then
16
+    _update_zsh_update && return 0;
17
+  fi
18
+
19
+  epoch_diff=$((${_current_epoch} - $LAST_EPOCH))
9 20
   if [ $epoch_diff -gt 6 ]
10 21
   then
11 22
     echo "[Oh My Zsh] Would you like to check for updates?"
... ...
@@ -15,14 +26,9 @@ then
15 15
     then
16 16
       /bin/sh $ZSH/tools/upgrade.sh
17 17
     fi
18
-
19
-    # Set the last epoch to the current so that we don't ask for another week
20
-    echo "LAST_EPOCH=${current_epoch}" > ~/.zsh-update
21 18
   fi
22
-else
23
-  # TODO: refactor this so remove duplicates
24
-  # Create the ~/.zsh-update file with the current epoch info
25
-  echo "LAST_EPOCH=${current_epoch}" > ~/.zsh-update
26 19
 fi
27 20
 
21
+# update the zsh file
22
+_update_zsh_update
28 23