Here is the solution I went for:
#!/bin/bash
result="$( { stdout="$(curl -Lsv -compressed "$1")" ; } 2>&1; echo "--SePaRaToR--"; echo "$stdout")";
echo '
found:'
echo "$result" | grep -o '\(charset\|encoding\)[ ]*=[ ]*["]*[a-zA-Z0-9_: -]*'
echo ' '
status=1
charset="ISO_8859-1" #set default
# 1: HTTP Content-Type: header
# 2: <meta> element in the page
# 3: <xml> element in the page
regex='.*(charset|encoding)\s*=\s*["]*([a-zA-Z0-9_: -]*)'
if [[ "$result" =~ $regex ]]
then
charset="${BASH_REMATCH[2]}"
status=2
echo "match succes: $charset"
else
echo "match fail: $charset : ${BASH_REMATCH[2]}"
fi
if [[ "$charset" == *utf-8* || "$charset" == *UTF-8* ]]
then
charset='NotModified'
else
echo "iconv '$charset' to UTF-8//TRANSLIT"
html=$(echo "$result" | iconv -f"$charset" -t'UTF-8//TRANSLIT')
if [ $? -ne 0 ]
then
echo "translit failed : iconv '$charset' to UTF-8//IGNORE"
html=$(echo "$result" | iconv -f"$charset" -t"UTF-8//IGNORE")
if [ $? -ne 0 ]
then
charset="ISO_8859-1"
echo "ignore failed : iconv '$charset' to UTF-8//IGNORE"
html=$(echo "$result" | iconv -f"$charset" -t"UTF-8//IGNORE")
status=4
fi
status=3
fi
fi
echo "charset: '$charset' , status: '$status'"
The default is the w3c recomandation.
It's not 100% accurate but it's fast and it will do it's job 99% of the time.
Hope it helps someone in the same situation.
Also thanks to all that answered.