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
This commit is contained in:
David Todd (c0de) 2018-02-10 23:18:23 -06:00
parent 3f71537d9d
commit 56444c027c
3 changed files with 25 additions and 11 deletions

View File

@ -7,7 +7,8 @@ function _current_epoch() {
} }
function _update_dotfiles_update() { 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() { function _upgrade_dotfiles() {
@ -23,19 +24,28 @@ if [[ -z "$epoch_target" ]]; then
epoch_target=13 epoch_target=13
fi fi
# Cancel upgrade if the current user doesn't have write permissions for the # Cancel upgrade if the current user doesn't have
# dotfiles directory. # write permissions for the dotfiles directory.
[[ -w "$_DOTFILES" ]] || echo "You can't write to $(dotfiles)"; return 1 if [[ -w "$_DOTFILES" ]]; then
else
echo "You can't write to $(_dotfiles)!"
return 1
fi
# Cancel upgrade if git is unavailable on the system # 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 mkdir -p "$_DOTFILES/update.lock" 2>/dev/null; then
if [ -f ~/.dotfiles-update ]; then if [ -f ${HOME}/.dotfiles-update ]; then
. ~/.dotfiles-update . ${HOME}/.dotfiles-update
if [[ -z "$LAST_EPOCH" ]]; then if [[ -z "$LAST_EPOCH" ]]; then
_update_zsh_update && return 0; echo "Missing \$LAST_EPOCH"
_update_dotfiles_update && return 0;
fi fi
epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
@ -53,9 +63,10 @@ if mkdir "$_DOTFILES/log/update.lock" 2>/dev/null; then
fi fi
fi fi
else else
echo "Missing ~/.dotfiles-update"
# create the zsh file # create the zsh file
_update_dotfiles_update _update_dotfiles_update
fi fi
rmdir $_DOTFILES/log/update.lock rmdir $_DOTFILES/update.lock
fi fi

View File

@ -15,6 +15,9 @@ export _DOTFILES="${HOME}/dotfiles"
# Allow automatic updates # Allow automatic updates
export DISABLE_DOTFILES_AUTO_UPDATE="FALSE" 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) # Update every 2 weeks (OMZ default)
export UPDATE_DOTFILES_DAYS=13 export UPDATE_DOTFILES_DAYS=13

View File

@ -42,7 +42,7 @@ bindkey "^[s" insert-sudo
# Check for updates... # Check for updates...
# Stolen and modified Oh-My-ZSH's update system # Stolen and modified Oh-My-ZSH's update system
if [ "$DISABLE_DOTFILES_AUTO_UPDATE" != "true" ]; then 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 fi
# Oh-My-ZSH Options below this line # Oh-My-ZSH Options below this line