Adds support for sliding check

This commit is contained in:
Thomas Forgione 2019-11-22 11:41:52 +01:00
parent 6f0eeea38f
commit fd8039e275
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 25 additions and 6 deletions

View File

@ -46,11 +46,15 @@ _check_date_if_format() {
_date_format() {
if [ "$UPDATE_CHECK_TYPE" = "sliding" ]; then
echo "+%s"
else
case $UPDATE_CHECK in
"daily") echo +%d/%m/%Y;;
"weekly") echo +%V/%Y;;
"monthly") echo +%m/%Y;;
esac
fi
}
@ -95,12 +99,27 @@ _check_date() {
local old_date=`cat ~/.config/dotfiles/.data/update_date`
local new_date=`date $1`
local updated=0
if [ "$new_date" != "$old_date" ] && [ ! -f ~/.config/dotfiles/.data/update_lock ]; then
if [ "$UPDATE_CHECK_TYPE" = "sliding" ]; then
local diff=$(($new_date - $old_date))
case $UPDATE_CHECK in
"daily") [ $diff -lt 86400 ] && updated=1;;
"weekly") [ $diff -lt 604800 ] && updated=1;;
"monthly") [$diff -lt 18748800 ] && updated=1;;
esac
else
if [ "$new_date" = "$old_date" ] ; then
updated=1
fi
fi
if [ $updated -eq 0 ] && [ ! -f ~/.config/dotfiles/.data/update_lock ]; then
_sentence not_updated
elif [ "$UPDATE_CHECK_ALWAYS" = "true" ] || [ "$2" = "force" ]; then
_sentence updated
fi
}
# Returns 0 if $1 > $2