Advertisement
KC9UZR

NRSC5 HD Radio for Debian/Ubuntu

Jun 27th, 2025
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.74 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # --- Field-Grade Terminal Colors (Expanded) ---
  4. C_OFF='\e[0m'
  5. # Bold
  6. B_RED='\e[1;31m'
  7. B_GREEN='\e[1;32m'
  8. B_YELLOW='\e[1;33m'
  9. B_BLUE='\e[1;34m'
  10. B_MAGENTA='\e[1;35m'
  11. B_CYAN='\e[1;36m'
  12. B_WHITE='\e[1;37m'
  13. # Rainbow Sequence
  14. RAINBOW_COLORS=(
  15.     '\e[1;31m' # Red
  16.     '\e[1;33m' # Yellow (as Orange)
  17.     '\e[1;32m' # Green
  18.     '\e[1;36m' # Cyan
  19.     '\e[1;34m' # Blue
  20.     '\e[1;35m' # Magenta (as Violet)
  21. )
  22.  
  23. # --- NEW: Rainbow Rendering Function ---
  24. # This function paints each character of a string with a different color.
  25. rainbow_text() {
  26.     local text="$1"
  27.     local num_colors=${#RAINBOW_COLORS[@]}
  28.     # Use 'tput cols' to get terminal width, default to 51 if not available
  29.     local width=$(tput cols 2>/dev/null || echo 51)
  30.     local padding=$(( (width - ${#text}) / 2 ))
  31.  
  32.     # Print left padding
  33.     printf "%*s" $padding ""
  34.  
  35.     # Print rainbow text
  36.     for (( i=0; i<${#text}; i++ )); do
  37.         local char="${text:$i:1}"
  38.         # Prevent coloring spaces to maintain alignment
  39.         if [[ "$char" == " " ]]; then
  40.             printf " "
  41.         else
  42.             # Cycle through the RAINBOW_COLORS array
  43.             local color_index=$((i % num_colors))
  44.             printf "${RAINBOW_COLORS[color_index]}%s" "$char"
  45.         fi
  46.     done
  47.     # Reset color and print a newline
  48.     printf "${C_OFF}\n"
  49. }
  50.  
  51. # --- Mission-Critical Functions (Unchanged Logic) ---
  52. command_exists() { command -v "$1" &> /dev/null; }
  53.  
  54. # --- Primary Operational Functions (Unchanged Logic) ---
  55. listen_to_hd() {
  56.     if ! command_exists nrsc5; then
  57.         echo -e "${B_RED}[ERROR] 'nrsc5' is not installed.${C_OFF}"
  58.         echo -e "${B_YELLOW}Go to 'Setup & Maintenance' to install it.${C_OFF}"
  59.         read -p "Press [Enter] to continue..."
  60.         return
  61.     fi
  62.     clear
  63.     rainbow_text "--- Begin Listening Operation ---"
  64.     echo -e "${B_YELLOW}Ensure your RTL-SDR is connected.${C_OFF}"
  65.     read -p "Enter target frequency (e.g., 97.1M): " freq
  66.     if [[ -z "$freq" ]]; then
  67.         echo -e "${B_RED}[ABORT] No frequency entered.${C_OFF}"
  68.         read -p "Press [Enter] to continue..."
  69.         return
  70.     fi
  71.     while true; do
  72.         clear
  73.         rainbow_text "Select Program for Frequency: ${freq}"
  74.         echo
  75.         echo -e "      ${B_GREEN}[1] HD1 (Primary Program)${C_OFF}"
  76.         echo -e "      ${B_CYAN}[2] HD2 (Sub-channel 2)${C_OFF}"
  77.         echo -e "      ${B_BLUE}[3] HD3 (Sub-channel 3)${C_OFF}"
  78.         echo -e "      ${B_MAGENTA}[4] HD4 (Sub-channel 4)${C_OFF}"
  79.         echo -e "      ${B_YELLOW}[5] HD5 (Sub-channel 5)${C_OFF}"
  80.         echo
  81.         echo -e "      ${B_RED}[0] Change Frequency / Return${C_OFF}"
  82.         echo
  83.         rainbow_text "-----------------------------------"
  84.         read -p "Select a program to monitor: " prog_choice
  85.         case $prog_choice in
  86.             [1-5])
  87.                 let prog_index=$prog_choice-1
  88.                 echo -e "${B_GREEN}Tuning to ${freq} on HD program ${prog_choice}... Press [Ctrl+C] to stop.${C_OFF}"
  89.                 nrsc5 "$freq" "$prog_index"
  90.                 read -p "Listening stopped. Press [Enter] to return..."
  91.                 ;;
  92.             0) return ;;
  93.             *) echo -e "${B_RED}Invalid selection.${C_OFF}" && sleep 1 ;;
  94.         esac
  95.     done
  96. }
  97.  
  98. # --- Setup & Maintenance Functions (Unchanged Logic) ---
  99. install_dependencies() {
  100.     echo -e "${B_YELLOW}[*] Requesting root access...${C_OFF}"
  101.     sudo apt-get update && sudo apt-get install -y git cmake build-essential librtlsdr-dev libao-dev pkg-config autoconf libtool libfftw3-dev rtl-sdr
  102.     if ! grep -q "blacklist dvb_usb_rtl28xxu" /etc/modprobe.d/blacklist-rtl.conf 2>/dev/null; then
  103.         echo "blacklist dvb_usb_rtl28xxu" | sudo tee /etc/modprobe.d/blacklist-rtl.conf > /dev/null
  104.         echo -e "${B_GREEN}[+] Blacklist rule created. A reboot is recommended.${C_OFF}"
  105.     fi
  106.     echo -e "\n${B_GREEN}[SUCCESS] Dependencies are in place.${C_OFF}"
  107.     read -p "Press [Enter] to return..."
  108. }
  109. install_nrsc5() {
  110.     if command_exists nrsc5; then echo -e "${B_GREEN}[*] 'nrsc5' is already installed.${C_OFF}"; read -p "Press [Enter]..."; return; fi
  111.     if [ -d "nrsc5" ]; then rm -rf nrsc5; fi
  112.     echo -e "${B_YELLOW}[*] Cloning repository...${C_OFF}"
  113.     if ! git clone https://github.com/theori-io/nrsc5.git; then echo -e "${B_RED}[FAILURE] Clone failed.${C_OFF}"; read -p "Press [Enter]..."; return; fi
  114.     cd nrsc5
  115.     echo -e "${B_YELLOW}[*] Building from source...${C_OFF}"
  116.     if mkdir -p build && cd build && cmake .. -DINTERNAL_FFTW=OFF && make && sudo make install; then
  117.         echo -e "\n${B_GREEN}[SUCCESS] 'nrsc5' has been installed.${C_OFF}"
  118.     else echo -e "\n${B_RED}[FAILURE] Build process failed.${C_OFF}"; fi
  119.     cd ../..
  120.     read -p "Press [Enter] to return..."
  121. }
  122. test_sdr() {
  123.     if ! command_exists rtl_test; then echo -e "${B_RED}[ERROR] 'rtl-sdr' not found. Use Option [1].${C_OFF}"; else
  124.         echo -e "${B_YELLOW}[*] Running SDR diagnostic...${C_OFF}"; rtl_test -t
  125.         echo -e "\n${B_GREEN}If you see device info, your SDR is working.${C_OFF}"; fi
  126.     read -p "Press [Enter] to return..."
  127. }
  128.  
  129. # --- Menu Display Functions (Visually Overhauled) ---
  130. show_setup_menu() {
  131.     while true; do
  132.         clear
  133.         rainbow_text "--- Setup & Maintenance ---"
  134.         echo
  135.         echo -e "      ${B_GREEN}[1] Install/Update Dependencies${C_OFF}"
  136.         echo -e "      ${B_CYAN}[2] Compile/Install 'nrsc5' Decoder${C_OFF}"
  137.         echo -e "      ${B_YELLOW}[3] Test RTL-SDR Device Connection${C_OFF}"
  138.         echo
  139.         echo -e "      ${B_RED}[0] Return to Main Menu${C_OFF}"
  140.         echo
  141.         rainbow_text "---------------------------------"
  142.         read -p "Select an option: " setup_choice
  143.         case $setup_choice in
  144.             1) install_dependencies ;;
  145.             2) install_nrsc5 ;;
  146.             3) test_sdr ;;
  147.             0) break ;;
  148.             *) echo -e "${B_RED}Invalid selection.${C_OFF}" && sleep 1 ;;
  149.         esac
  150.     done
  151. }
  152.  
  153. # --- Main Operational Loop (Visually Overhauled) ---
  154. while true; do
  155.     clear
  156.     rainbow_text "H.D.R. - v1.7 // Covert Radio Operations"
  157.     echo
  158.     echo -e "                ${B_CYAN}SDR Activated. Awaiting Tasking.${C_OFF}"
  159.     echo
  160.     echo -e "      ${B_BLUE}   [1] Listen to HD Radio Broadcast${C_OFF}"
  161.     echo -e "      ${B_MAGENTA}[2] Setup & Maintenance${C_OFF}"
  162.     echo
  163.     echo -e "      ${B_RED}   [0] Exit and Clean Traces${C_OFF}"
  164.     echo
  165.     rainbow_text "---------------------------------------------------"
  166.     read -p "Select an option [0-2]: " choice
  167.     case $choice in
  168.         1) listen_to_hd ;;
  169.         2) show_setup_menu ;;
  170.         0) echo -e "${B_RED}Disengaging. Clean your tracks.${C_OFF}"; break ;;
  171.         *) echo -e "${B_RED}Invalid selection.${C_OFF}"; sleep 1 ;;
  172.     esac
  173. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement