#!/usr/bin/env bash set -euo pipefail # RadioTEDU Terminal — https://radiotedu.com/tui if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then printf '%s\n' 'Node.js and npm are required. Install the current LTS release from https://nodejs.org, then run this installer again.' exit 1 fi if ! node -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 18 ? 0 : 1)'; then printf '%s\n' 'RadioTEDU requires Node.js 18 or newer. Please install the current LTS release.' exit 1 fi terminal_download="$(mktemp -d)" trap 'rm -f "$terminal_download/package.tgz"; rmdir "$terminal_download"' EXIT node --input-type=module - "$terminal_download/package.tgz" <<'NODE' import {writeFileSync} from 'node:fs'; import {createHash} from 'node:crypto'; const response=await fetch('https://radiotedu.com/tui/latest.json',{cache:'no-store',signal:AbortSignal.timeout(20000)}); if(!response.ok)throw new Error('Cannot retrieve the release manifest'); const release=await response.json(),url=new URL(release.package); if(url.origin!=='https://radiotedu.com'||!/^\/tui\/radiotedu-[a-zA-Z0-9.-]+\.tgz$/.test(url.pathname)||!/^[a-f0-9]{64}$/.test(release.sha256))throw new Error('Invalid release manifest'); const result=await fetch(url,{signal:AbortSignal.timeout(60000)}); if(!result.ok)throw new Error('Package download failed'); const bytes=Buffer.from(await result.arrayBuffer()); if(createHash('sha256').update(bytes).digest('hex')!==release.sha256)throw new Error('Package checksum mismatch'); writeFileSync(process.argv[2],bytes); console.log('Installing RadioTEDU Terminal '+release.version+'...'); NODE terminal_args=(install --global --ignore-scripts "$terminal_download/package.tgz") terminal_global_root="$(npm root --global)" if [ -f "$terminal_global_root/radiotedu-tui/package.json" ] || [ -f "$terminal_global_root/radiotedu/package.json" ]; then # Migrate only the command aliases shared by the two official RadioTEDU packages. terminal_args+=(--force) printf '%s\n' 'Updating the existing RadioTEDU aliases. Saved account settings are preserved.' fi if ! npm "${terminal_args[@]}"; then printf '%s\n' 'Installation failed. Previous application and account settings were not deleted.' 'If npm reports a permissions error, configure a user-owned global npm directory or use a Node.js version manager.' exit 1 fi terminal_prefix="$(npm prefix --global)" terminal_command="$terminal_prefix/bin/radiotedu" if [ ! -x "$terminal_command" ]; then printf '%s\n' 'The expected launch command was not found. Check npm prefix --global.' exit 1 fi "$terminal_command" --version printf '%s\n' 'Ready. Type radiotedu to open the player.' if ! command -v radiotedu >/dev/null 2>&1; then printf 'Add %s/bin to your PATH, then open a new terminal.\n' "$terminal_prefix" fi if ! command -v mpv >/dev/null 2>&1 && ! command -v ffplay >/dev/null 2>&1; then printf '%s\n' 'Audio needs mpv or ffplay.' 'macOS with Homebrew: brew install mpv' 'Ubuntu / Debian: sudo apt install mpv' fi printf '%s\n' 'Optional account pairing: radiotedu login'