#! /bin/bash # TILDERADIO MASTER EXECUTABLE - master executable for tilderadio # Top level runtime of tilderadio program # Get Source Dir, and then source Core Declarations file DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source "${DIR}/scripts/system/system-declarations" # Includes and Declarations (global variables, formatting and functions) source "${APPLICATION_ROOT}/scripts/system/system-declarations" source "${APPLICATION_ROOT}/scripts/system/system-functions" source "${APPLICATION_ROOT}/var/version" # Render Main Menu function render_main_menu { # Check to make sure active config file idenifier is valid. If not, then empty identifier. CURRENT_CONFIG_NAME=$(<$CONFIG_FILE_IDENTIFIER_PATH) CURRENT_CONFIG_FILE_CLAIMED_PATH="$CONFIG_DIRECTORY/config-${CURRENT_CONFIG_NAME}.json" if ! [[ -f "$CURRENT_CONFIG_FILE_CLAIMED_PATH" ]]; then truncate -s 0 "$CONFIG_FILE_IDENTIFIER_PATH" CURRENT_CONFIG_NAME=$(<$CONFIG_FILE_IDENTIFIER_PATH) fi # Prepare Pretty Header APP_AND_VERSION_PREFIX="soapdish - v${VERSION}" APP_AND_VERSION_CHARCOUNT=${#APP_AND_VERSION_PREFIX} # Render Main Menu - Appropriate pretty menuheading (check if a config is specified) if [[ -n "$CURRENT_CONFIG_NAME" ]]; then # If config file is set, prep variables CURRENT_CONFIG_NAME_AND_PREFIX="[Using profile: \"${CURRENT_CONFIG_NAME}\"]" CURRENT_CONFIG_NAME_CHARCOUNT=${#CURRENT_CONFIG_NAME_AND_PREFIX} MENU_HEADER_SPACING_COUNT=$(( "80" - "$CURRENT_CONFIG_NAME_CHARCOUNT" - "$APP_AND_VERSION_CHARCOUNT" )) MENU_HEADER_SPACING="" for (( i = 0; i < MENU_HEADER_SPACING_COUNT; i++ )); do MENU_HEADER_SPACING="${MENU_HEADER_SPACING} " done # Render echo -e ""; echo -e ""; echo -e "${FONT_BOLD}${APP_AND_VERSION_PREFIX}${MENU_HEADER_SPACING}${CURRENT_CONFIG_NAME_AND_PREFIX}${FONT_DEFAULT}" render_horizontal_rule echo ""; else # If config file is NOT set, prep variables CURRENT_CONFIG_NAME_AND_PREFIX="[No config specified!]" CURRENT_CONFIG_NAME_CHARCOUNT=${#CURRENT_CONFIG_NAME_AND_PREFIX} MENU_HEADER_SPACING_COUNT=$(( "80" - "$CURRENT_CONFIG_NAME_CHARCOUNT" - "$APP_AND_VERSION_CHARCOUNT" )) MENU_HEADER_SPACING="" for (( i = 0; i < MENU_HEADER_SPACING_COUNT; i++ )); do MENU_HEADER_SPACING="${MENU_HEADER_SPACING} " done # Render echo -e ""; echo -e ""; echo -e "${FONT_BOLD}${APP_AND_VERSION_PREFIX}${MENU_HEADER_SPACING}${COLOR_RED}${CURRENT_CONFIG_NAME_AND_PREFIX}${FONT_DEFAULT}" render_horizontal_rule echo ""; fi # Render Main Menu - Streaming Commands echo -e " ${FONT_BOLD}${COLOR_DARK_GRAY}STREAM ALSA:${COLOR_DEFAULT}${FONT_DEFAULT} "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}L${FONT_DEFAULT}${COLOR_DEFAULT} - stream ALSA/live (to Main) "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}l${FONT_DEFAULT}${COLOR_DEFAULT} - stream ALSA/live (to Testing) "; echo -e ""; # Render Main Menu - Broadcast Commands echo -e " ${FONT_BOLD}${COLOR_DARK_GRAY}STREAM FILES:${COLOR_DEFAULT}${FONT_DEFAULT} "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}F${FONT_DEFAULT}${COLOR_DEFAULT} - stream files (to Main) "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}f${FONT_DEFAULT}${COLOR_DEFAULT} - stream files (to Testing) "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}V${FONT_DEFAULT}${COLOR_DEFAULT} - playlist view "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}C${FONT_DEFAULT}${COLOR_DEFAULT} - playlist create "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}E${FONT_DEFAULT}${COLOR_DEFAULT} - playlist edit "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}Q${FONT_DEFAULT}${COLOR_DEFAULT} - queued folder contents "; echo -e ""; # Render Main Menu - Cron echo -e " ${FONT_BOLD}${COLOR_DARK_GRAY}CRON${COLOR_DEFAULT}${FONT_DEFAULT} "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}S${FONT_DEFAULT}${COLOR_DEFAULT} - cron status "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}A${FONT_DEFAULT}${COLOR_DEFAULT} - cron activate "; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}D${FONT_DEFAULT}${COLOR_DEFAULT} - cron deactivate "; echo -e ""; # Render Main Menu - System echo -e " ${COLOR_DARK_GRAY}${FONT_BOLD}SYSTEM${FONT_DEFAULT}${COLOR_DEFAULT}"; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}K${FONT_DEFAULT}${COLOR_DEFAULT} - killall and restart liquidsoap"; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}J${FONT_DEFAULT}${COLOR_DEFAULT} - config profile options"; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}H${FONT_DEFAULT}${COLOR_DEFAULT} - review hardware audio frame size"; echo -e " ${COLOR_LIGHT_MAGENTA}${FONT_BOLD}M${FONT_DEFAULT}${COLOR_DEFAULT} - alsa mixer"; echo -e ""; echo -e ""; echo -e ""; } # Process input variable function process_input_variable() { # Case Switch case $INPUTCOMMAND in # SHOW COMMANDS: # LIVE-STREAMING # (L) ---- main, stream live/alsa L) source "${APPLICATION_ROOT}/scripts/streaming/main/main-stream_live_alsa" ;; # (l) ---- testing, stream live/alsa l) source "${APPLICATION_ROOT}/scripts/streaming/testing/testing-stream_live_alsa" ;; # FILE-STREAMING # (F) ---- main, stream files F) source "${APPLICATION_ROOT}/scripts/streaming/main/main-stream_files" ;; # (f) ---- testing, stream files f) source "${APPLICATION_ROOT}/scripts/streaming/testing/testing-stream_files" ;; # (V) ---- main, playlist view V) source "${APPLICATION_ROOT}/scripts/playlist/playlist_view" ;; # (C) ---- main, playlist create C) source "${APPLICATION_ROOT}/scripts/playlist/playlist_create" ;; # (E) ---- main, playlist edit E) source "${APPLICATION_ROOT}/scripts/playlist/playlist_edit" ;; # (Q) ---- main, queued folder contents Q) source "${APPLICATION_ROOT}/scripts/queued/queued_folder_contents" ;; # CRON # (S) ---- cron status S) source "${APPLICATION_ROOT}/scripts/cron/main-cron_status" ;; # (A) ---- cron activate A) source "${APPLICATION_ROOT}/scripts/cron/main-cron_activate" ;; # (D) ---- cron deactivate D) source "${APPLICATION_ROOT}/scripts/cron/main-cron_deactivate" ;; # SYSTEM COMMANDS # (K) ---- killall and restart K) source "${APPLICATION_ROOT}/scripts/system/system-killall_and_restart" ;; # (J) ---- edit config J) source "${APPLICATION_ROOT}/scripts/system/system-config" ;; # (H) ---- review hardware audio frame size H) source "${APPLICATION_ROOT}/scripts/system/system-update_hardware_audio_frame_size" ;; # (M) ---- alsa mixer M) source "${APPLICATION_ROOT}/scripts/system/system-alsa_mixer" ;; # Fallback if command not recognized *) printf "${COLOR_RED}[-] Command not recognized.${COLOR_DEFAULT}\n" echo "" ;; esac } # Main Program Function function execute_program { # Check for missing dependencies (if missing, exits) check_for_missing_dependencies # Git touch routine to add .gitkeep and create any missing folders git_keep_touch_routine # Read Command Input while : do # Render Main Menu echo "" render_main_menu # Read main application input command MENU_NAME=$(echo -e "${COLOR_LIGHT_MAGENTA}[Main Menu]${COLOR_DEFAULT}") read -p "$MENU_NAME Choice? (\"quit\" to exit, RETURN for menu): " INPUTCOMMAND; # If "quit" entered if [[ $INPUTCOMMAND == "quit" ]]; then # Kill, just in case sudo pkill "liquidsoap"; # Wait and restart liquidsoap, just in case sleep 2 sudo systemctl restart liquidsoap # Notify of exit printf "${COLOR_GREEN}[quit] Exiting...${COLOR_DEFAULT}\n" echo "" echo "" break # If no key entered elif [[ -z $INPUTCOMMAND ]]; then printf "${COLOR_GREEN}[RETURN] Main menu.${COLOR_DEFAULT}\n" echo "" render_main_menu # Evaluate Character entered else process_input_variable fi done } # Master execution of program execute_program # Closing change of permissions on execution of script reset_permissions