diff options
Diffstat (limited to 'share/hydractl/aperiodic-upgrade')
-rwxr-xr-x | share/hydractl/aperiodic-upgrade | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/share/hydractl/aperiodic-upgrade b/share/hydractl/aperiodic-upgrade index 505c309..ba09150 100755 --- a/share/hydractl/aperiodic-upgrade +++ b/share/hydractl/aperiodic-upgrade @@ -21,6 +21,13 @@ TIMEFRAME="${1:-86400}" DATE="`date +%s`" LOG="/var/lib/hydractl/aperidic-upgrade" +# Upgrade and save timestamp +function hydractl_aperiodic_upgrade { + hydractl upgrade + date +%s | $sudo tee $LOG > /dev/null + exit +} + # Set sudo config if [ "`whoami`" != 'root' ]; then sudo="sudo" @@ -29,26 +36,23 @@ fi # Ensure log folder $sudo mkdir -p "`dirname $LOG`" +# Run if [ ! -e "$LOG" ]; then - # Upgrade anyway - hydractl upgrade + hydractl_aperiodic_upgrade else LAST="`cat $LOG`" - if [ -z "$LAST" ]; then - hydractl upgrade - else + if [ ! -z "$LAST" ]; then INTERVAL="$(($DATE - $LAST))" # More than $TIMEFRAME? - if (( $INTERVAL > $TIMEFRAME )); then - hydractl upgrade + if [ "$INTERVAL" -gt "$TIMEFRAME" ]; then + hydractl_aperiodic_upgrade else - echo "Please enjoy life for an additional $(($TIMEFRAME - $INTERVAL)) seconds before running this command again." - exit + NEXT="$(($TIMEFRAME - $INTERVAL))" + echo "Please enjoy life for an additional $NEXT seconds before running this command again." fi + else + hydractl_aperiodic_upgrade fi fi - -# Save timestamp -date +%s | $sudo tee $LOG > /dev/null |