
# x upgrade
# x upgrade pkg-index
# x upgrade pkg
# x upgrade hubfile
# x upgrade


___X_CMD_UPGRADE_TIMESTAMP="$___X_CMD_ROOT_TMP/upgrade/last-check-timestamp"

___x_cmd_upgrade___check(){
    local x_=""
    ___x_cmd_upgrade___timestamp_

    ! ___x_cmd_upgrade___istimetocheck "$x_" || return 0


    ## --get cfg # action --> upgrade, hint, background
    ___x_cmd ensurefp "$___X_CMD_UPGRADE_TIMESTAMP"
    printf "%s\n" "$x_" >"$___X_CMD_UPGRADE_TIMESTAMP"

    ___x_cmd upgrade
}

___x_cmd_upgrade___checkupgrade(){
    # download the version check
    # upgrade
    :
}

___x_cmd_upgrade___istimetocheck(){
    local current="$1"

    local lastcheck=""
    [ -f "$___X_CMD_UPGRADE_TIMESTAMP" ]    || read -r lastcheck <"$___X_CMD_UPGRADE_TIMESTAMP"

    $(( current - lastcheck > 60 * 60 * 24 ))
}

___x_cmd_upgrade___timestamp_(){
    x_="$EPOCHSECONDS"
    [ -n "$x_" ] || x_="$(___x_cmd_cmds date +%s)"
}

