oh-my-bash/tools/check_for_upgrade.sh

55 lines
1.4 KiB
Bash
Raw Permalink Normal View History

2017-03-19 08:40:25 +00:00
#!/usr/bin/env bash
function _omb_upgrade_current_epoch {
local sec=${EPOCHSECONDS-}
[[ $sec ]] || printf -v sec '%(%s)T' -1 2>/dev/null || sec=$(command date +%s)
echo $((sec / 60 / 60 / 24))
2017-03-19 08:40:25 +00:00
}
function _omb_upgrade_update_timestamp {
2023-03-11 08:04:23 +00:00
echo "LAST_EPOCH=$(_omb_upgrade_current_epoch)" >|~/.osh-update
2017-03-19 08:40:25 +00:00
}
function _omb_upgrade_check {
if [[ ! -f ~/.osh-update ]]; then
# create ~/.osh-update
_omb_upgrade_update_timestamp
return 0
fi
2017-03-19 08:40:25 +00:00
local LAST_EPOCH
# shellcheck disable=SC1090
. ~/.osh-update
if [[ ! $LAST_EPOCH ]]; then
_omb_upgrade_update_timestamp
return 0
fi
# Default to the old behavior
local epoch_expires=${UPDATE_OSH_DAYS:-13}
local epoch_elapsed=$(($(_omb_upgrade_current_epoch) - LAST_EPOCH))
if ((epoch_elapsed <= epoch_expires)); then
return 0
fi
# update ~/.osh-update
_omb_upgrade_update_timestamp
if [[ $DISABLE_UPDATE_PROMPT == true ]] ||
2023-03-11 08:04:23 +00:00
{ read -rp '[Oh My Bash] Would you like to check for updates? [Y/n]: ' line &&
[[ $line == Y* || $line == y* || ! $line ]]; }; then
source "$OSH"/tools/upgrade.sh
fi
}
2017-03-19 08:40:25 +00:00
# Cancel upgrade if the current user doesn't have write permissions for the
# oh-my-bash directory.
[[ -w $OSH ]] || return 0
2017-03-19 08:40:25 +00:00
# Cancel upgrade if git is unavailable on the system
type -P git &>/dev/null || return 0
2017-03-19 08:40:25 +00:00
if command mkdir "$OSH/log/update.lock" 2>/dev/null; then
_omb_upgrade_check
command rmdir "$OSH"/log/update.lock
2017-03-19 08:40:25 +00:00
fi