From 56444c027ca7cd14c5642be42f35dbcd6542b62c Mon Sep 17 00:00:00 2001 From: "David Todd (c0de)" Date: Sat, 10 Feb 2018 23:18:23 -0600 Subject: [PATCH] Finalize automatic updates All instances of dotfiles from this point forward will now ask to update automatically every 2 weeks Delete ~/.dotfiles-update to restart the counter --- check_for_upgrade.sh | 31 +++++++++++++++++++++---------- shell/env | 3 +++ shell/zshrc | 2 +- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/check_for_upgrade.sh b/check_for_upgrade.sh index e0d77dc..b4ff921 100755 --- a/check_for_upgrade.sh +++ b/check_for_upgrade.sh @@ -7,7 +7,8 @@ function _current_epoch() { } function _update_dotfiles_update() { - echo "LAST_EPOCH=$(_current_epoch)" >! ~/.dotfiles-update + echo "export LAST_EPOCH=$(_current_epoch)" > ${HOME}/.dotfiles-update + echo "touched ~/.dotfiles-update" } function _upgrade_dotfiles() { @@ -23,19 +24,28 @@ if [[ -z "$epoch_target" ]]; then epoch_target=13 fi -# Cancel upgrade if the current user doesn't have write permissions for the -# dotfiles directory. -[[ -w "$_DOTFILES" ]] || echo "You can't write to $(dotfiles)"; return 1 +# Cancel upgrade if the current user doesn't have +# write permissions for the dotfiles directory. +if [[ -w "$_DOTFILES" ]]; then +else + echo "You can't write to $(_dotfiles)!" + return 1 +fi # Cancel upgrade if git is unavailable on the system -whence git >/dev/null || echo "git is not available"; return 2 +if [[ $(whence git >/dev/null) || false ]]; then +else + echo "git is not available" + return 2 +fi -if mkdir "$_DOTFILES/log/update.lock" 2>/dev/null; then - if [ -f ~/.dotfiles-update ]; then - . ~/.dotfiles-update +if mkdir -p "$_DOTFILES/update.lock" 2>/dev/null; then + if [ -f ${HOME}/.dotfiles-update ]; then + . ${HOME}/.dotfiles-update if [[ -z "$LAST_EPOCH" ]]; then - _update_zsh_update && return 0; + echo "Missing \$LAST_EPOCH" + _update_dotfiles_update && return 0; fi epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) @@ -53,9 +63,10 @@ if mkdir "$_DOTFILES/log/update.lock" 2>/dev/null; then fi fi else + echo "Missing ~/.dotfiles-update" # create the zsh file _update_dotfiles_update fi - rmdir $_DOTFILES/log/update.lock + rmdir $_DOTFILES/update.lock fi diff --git a/shell/env b/shell/env index c75860b..c92fe1a 100644 --- a/shell/env +++ b/shell/env @@ -15,6 +15,9 @@ export _DOTFILES="${HOME}/dotfiles" # Allow automatic updates export DISABLE_DOTFILES_AUTO_UPDATE="FALSE" +# Set "true" to update without asking first +export DISABLE_DOTFILES_UPDATE_PROMPT="FALSE" + # Update every 2 weeks (OMZ default) export UPDATE_DOTFILES_DAYS=13 diff --git a/shell/zshrc b/shell/zshrc index 4e10408..80f9d2b 100644 --- a/shell/zshrc +++ b/shell/zshrc @@ -42,7 +42,7 @@ bindkey "^[s" insert-sudo # Check for updates... # Stolen and modified Oh-My-ZSH's update system if [ "$DISABLE_DOTFILES_AUTO_UPDATE" != "true" ]; then - env ZSH=$ZSH DOTFILES=$DOTFILES DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $DOTFILES/check_for_upgrade.sh + env ZSH=$ZSH _DOTFILES=$_DOTFILES DISABLE_UPDATE_PROMPT=$DISABLE_DOTFILES_UPDATE_PROMPT zsh -f $_DOTFILES/check_for_upgrade.sh fi # Oh-My-ZSH Options below this line