Move the update scripts to root of repo

Also rework the variables in the environment to use /bin/true and
/bin/false instead of string representations of this. Might cause
problems, haven't tested yet
This commit is contained in:
David Todd 2021-01-11 22:20:28 -06:00
parent fdb3222bcb
commit cea6f93354
5 changed files with 17 additions and 18 deletions

View File

@ -15,28 +15,28 @@ export PATH=${HOME}/bin:$PATH:/usr/lib/wine/bin:/sbin:/usr/sbin:/usr/local/bin
# Give the path to the dotfiles
export _DOTFILES="${HOME}/dotfiles"
# Allow automatic updates
export DISABLE_DOTFILES_AUTO_UPDATE="FALSE"
# Allow checking for automatic updates
export ENABLE_DOTFILES_AUTO_UPDATE=true
# Set "true" to update without asking first
export DISABLE_DOTFILES_UPDATE_PROMPT="FALSE"
export DISABLE_DOTFILES_UPDATE_PROMPT=false
# Update every 2 weeks (OMZ default)
export UPDATE_DOTFILES_DAYS=13
# Whether or not to automatically connect to a TMUX session when opening the shell
export ENABLE_TMUXAC="FALSE"
export ENABLE_TMUXAC=false
# If there is not an active tmux session, we probably want one
# Otherwise, the shell will not open the session again (eg. opening tabs, new terminals)
if $(tmux list-sessions >> /dev/null 2>&1); then
export TMUXATT="TRUE"
export TMUXATT=true
else
export TMUXATT="FALSE"
export TMUXATT=false
fi
# Automatically attach tmux session "C0DE"
if [[ -z "$TMUX" && "$TMUXATT" != "TRUE" && "$ENABLE_TMUXAC" != "FALSE" ]]; then
if [[ -z "$TMUX" && "$TMUXATT" && "$ENABLE_TMUXAC" ]]; then
tmux attach -t C0DE || tmux new -s C0DE
fi

4
.zshrc
View File

@ -41,8 +41,8 @@ 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_DOTFILES_UPDATE_PROMPT zsh -f $_DOTFILES/internal_bin/check_for_upgrade.sh
if [ "${ENABLE_DOTFILES_AUTO_UPDATE}" ]; then
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

View File

@ -10,15 +10,14 @@ function _current_epoch() {
echo $(( $EPOCHSECONDS / 60 / 60 / 24 ))
}
function _update_dotfiles_update() {
function _touch_dotfiles_update() {
echo "export LAST_EPOCH=$(_current_epoch)" > ${HOME}/.dotfiles-update
echo "touched ~/.dotfiles-update"
}
function _upgrade_dotfiles() {
env _DOTFILES=$_DOTFILES sh $_DOTFILES/internal_bin/upgrade.sh
# update the zsh file
_update_dotfiles_update
env _DOTFILES=$_DOTFILES sh $_DOTFILES/upgrade.sh
_touch_dotfiles_update
}
# Configure this in shell/env
@ -49,12 +48,12 @@ if mkdir -p "$_DOTFILES/update.lock" 2>/dev/null; then
if [[ -z "$LAST_EPOCH" ]]; then
echo "Missing \$LAST_EPOCH"
_update_dotfiles_update && return 0;
_touch_dotfiles_update && return 0;
fi
epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
if [ $epoch_diff -gt $epoch_target ]; then
if [ "$DISABLE_UPDATE_PROMPT" = "true" ]; then
if [ "${DISABLE_UPDATE_PROMPT}" ]; then
_upgrade_dotfiles
else
echo "[Dotfiles] Would you like to check for updates? [Y/n]: \c"
@ -62,14 +61,14 @@ if mkdir -p "$_DOTFILES/update.lock" 2>/dev/null; then
if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then
_upgrade_dotfiles
else
_update_dotfiles_update
_touch_dotfiles_update
fi
fi
fi
else
echo "Missing ~/.dotfiles-update"
# create the zsh file
_update_dotfiles_update
_touch_dotfiles_update
fi
rmdir $_DOTFILES/update.lock

View File

@ -51,7 +51,7 @@ read -p "Press enter to install my dotfiles " WAIT_FOR_INPUT
# If the update script exists, try to do a normal update
if [ -x "${DOTFILES}/check_for_upgrade.sh" ]; then
source "${DOTFILES}/.environment"
env DOTFILES=${DOTFILES} DISABLE_UPDATE_PROMPT='FALSE' zsh -f "${DOTFILES}/check_for_upgrade.sh"
env DOTFILES=${DOTFILES} DISABLE_UPDATE_PROMPT=false zsh -f ${DOTFILES}/check_for_upgrade.sh
else
echo "Cloning dotfiles to ${DOTFILES}"
rm -rf "${DOTFILES}"