summaryrefslogtreecommitdiff
path: root/iptv.sh
diff options
context:
space:
mode:
authorZhineng Li <im@zhineng.li>2026-05-06 11:08:20 +0800
committerZhineng Li <im@zhineng.li>2026-05-06 11:08:20 +0800
commit5fb2c4624e18415823ba7dfa80713c8073e6fd25 (patch)
tree9756cae193a5dc44b4ef95c8e16e996797293144 /iptv.sh
parentc51c5cd43305b1a2291422ce2d804b193ee941a0 (diff)
downloadchina-unicom-iptv-gd-5fb2c4624e18415823ba7dfa80713c8073e6fd25.tar.gz
china-unicom-iptv-gd-5fb2c4624e18415823ba7dfa80713c8073e6fd25.zip
make color setup safe in non-interactive environmentsHEADmain
When run by cron, TERM may be unset, which causes tput to fail with: tput: No value for $TERM and no -T specified Initialize color variables to empty strings by default, then apply tput-based colors only when terminal capabilities are available. This prevents startup failure in non-interactive runs while preserving colored output in interactive shells.
Diffstat (limited to 'iptv.sh')
-rwxr-xr-xiptv.sh12
1 files changed, 9 insertions, 3 deletions
diff --git a/iptv.sh b/iptv.sh
index e702a55..78e1484 100755
--- a/iptv.sh
+++ b/iptv.sh
@@ -5,9 +5,15 @@ set -euo pipefail
CURL_ARGS=(--silent --max-time 6)
# Color definitions
-COLOR_DANGER=$(tput setaf 1)
-COLOR_SUCCESS=$(tput setaf 2)
-COLOR_RESET=$(tput sgr0)
+COLOR_DANGER=''
+COLOR_SUCCESS=''
+COLOR_RESET=''
+
+if [[ -n "${TERM-}" ]] && command -v tput &>/dev/null && tput sgr0 &>/dev/null; then
+ COLOR_DANGER=$(tput setaf 1)
+ COLOR_SUCCESS=$(tput setaf 2)
+ COLOR_RESET=$(tput sgr0)
+fi
show_usage () {
echo "Usage: $0 [COMMAND] [OPTIONS]"