tput queries the termcap or terminfo database based for the terminal whose name is stored in $TERM.
tput is a standard command, but the names of the capabilities except for clear, init and reset (in the POSIX locale only) are not specified.
If some systems don't have tput, they likely don't have a terminfo or termcap database either.
Also beware that terminal names are not standardised.
For instance, there are many terminals that set $TERM to xterm even though they don't implement the xterm API fully or properly, and there are many versions of xterm, and xterm can be compiled or configured with support for different numbers of colours with that not being always reflected in the value of $TERM, not to mention that the shades of the various colours even for those that use the same escape sequences vary from one terminal to the next, so it's not an exact science.
On systems that don't have terminfo/termcap databases, you'd have to ship your own database (maybe a subset with the most commonly used terminals, and only the capabilities of interest) and implement a way to query it from your script.
At the very least, that could be just a big case construct:
case $TERM in ( fbterm ) colors=256 fg_color() { printf '\33[1;%sd}' "$1"; } ;; ( *256color* | alacritty | i[tT]erm* ) colors=256 fg_color() { if [ "$1" -lt 8 ]; then printf '\33[3%sm' "$1" elif [ "$1" -lt 16 ]; then printf '\33[9%sm' "$(( $1 - 8 ))" else printf '\33[38;5;%sm' "$1" fi } # and so on. esac