Browse Source

Initial commit

master
buttstuf 5 months ago
commit
44037c85a0
  1. 9
      README.txt
  2. 0
      audio_queued/.gitkeep
  3. 0
      config/.gitkeep
  4. 0
      playlists/.gitkeep
  5. 4
      playlists/playlist.m3u
  6. 19
      scripts/cron/main-cron_activate
  7. 17
      scripts/cron/main-cron_deactivate
  8. 23
      scripts/cron/main-cron_status
  9. 66
      scripts/playlist/playlist_create
  10. 25
      scripts/playlist/playlist_edit
  11. 411
      scripts/playlist/playlist_view
  12. 56
      scripts/queued/queued_folder_contents
  13. 93
      scripts/streaming/main/main-stream_files
  14. 113
      scripts/streaming/main/main-stream_live_alsa
  15. 99
      scripts/streaming/testing/testing-stream_files
  16. 113
      scripts/streaming/testing/testing-stream_live_alsa
  17. 18
      scripts/system/system-alsa_mixer
  18. 356
      scripts/system/system-config
  19. 67
      scripts/system/system-config_copy
  20. 97
      scripts/system/system-config_delete
  21. 54
      scripts/system/system-config_edit
  22. 29
      scripts/system/system-config_empty_trash
  23. 66
      scripts/system/system-config_new
  24. 108
      scripts/system/system-config_rename
  25. 46
      scripts/system/system-config_use
  26. 68
      scripts/system/system-declarations
  27. 216
      scripts/system/system-functions
  28. 44
      scripts/system/system-killall_and_restart
  29. 92
      scripts/system/system-update_hardware_audio_frame_size
  30. 236
      soapdish.sh
  31. 0
      var/active_config_name
  32. 0
      var/log/.gitkeep
  33. 0
      var/main-cron_gateway
  34. 36
      var/templates/config-sample.json
  35. 3
      var/version

9
README.txt

@ -0,0 +1,9 @@
App: soapdish
Author: buttstuf@tilde.club
--------------------------------------------------------------------------------
(END)

0
audio_queued/.gitkeep

0
config/.gitkeep

0
playlists/.gitkeep

4
playlists/playlist.m3u

@ -0,0 +1,4 @@
# Playlist created date:
#
#
# Playlist tracks:

19
scripts/cron/main-cron_activate

@ -0,0 +1,19 @@
#!/bin/bash
# MAIN: CRON ACTIVATE
# Copy code to cront-show_gateway file
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# HEREDOC the script into a file named "cron-show_gateway"
cat <<-'EOF' > ${APPLICATION_ROOT}/var/main-cron_gateway
#!/bin/bash
${APPLICATION_ROOT}/scripts/main/main-stream_files
EOF
# Echo result
confirmation_message "[A] Activating main stream cron (CRON ON)"
echo "";

17
scripts/cron/main-cron_deactivate

@ -0,0 +1,17 @@
#!/bin/bash
# SHOW: CRON DEACTIVATE
# Empty cron-show_gateway file
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# Deactivate cron job by emptying contents of cron-gateway
sudo cat /dev/null > ${APPLICATION_ROOT}/var/main-cron_gateway
# Echo result
confirmation_message "[D] Deactivating main stream cron (CRON OFF)"
echo "";

23
scripts/cron/main-cron_status

@ -0,0 +1,23 @@
#!/bin/bash
# MAIN: CRON STATUS
# Check if cron-main_gateway is empty
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# Check if cron-gateway is NOT empty
if [ -s ${APPLICATION_ROOT}/var/main-cron_gateway ]
then
# Echo if cron-gateway is empty (cron job is active)
confirmation_message "[S] Cron main stream status: ON / ACTIVE";
echo "";
else
# Echo if cron-gateway is not empty (cron job is inactive!)
confirmation_message "[S] Cron main stream status: OFF / INACTIVE";
echo "";
fi

66
scripts/playlist/playlist_create

@ -0,0 +1,66 @@
#!/bin/bash
# MAIN: CREATE/UPDATE PLAYLIST
# Creates and/or updates a playlist to reflect what's in main-audio_queued folder
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# If playlist exists, delete it.
if test -f "$PLAYLIST_PATH"; then
sudo rm "$PLAYLIST_PATH";
fi
sudo touch "$PLAYLIST_PATH";
# Create array of directory files
declare -a FILES_ARRAY=()
for FILE in "$AUDIO_QUEUED_DIRECTORY"/*.mp3 ; do
FILES_ARRAY+=("$FILE")
done
# Check if array is empty, then construct accordingly
if (( ${#FILES_ARRAY[@]} )); then
# If files: Append header
CURRENT_DATE=$(date +"%D %T")
echo "# Playlist created date:" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
echo "# $CURRENT_DATE" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
echo "#" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
# Then append tracks
echo "# Playlist tracks:" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
for TRACK in "${FILES_ARRAY[@]}" ; do
echo "$TRACK" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
done
else
# If no files: Append header
CURRENT_DATE=$(date +"%D %T")
echo "# Playlist date created:" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
echo "# $CURRENT_DATE" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
echo "#" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
# Then append empty tracklist
echo "# Playlist tracks:" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
echo "# (((--- PLAYLIST EMPTY ---)))" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
echo "#" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
echo "#" | sudo tee -a "$PLAYLIST_PATH" >/dev/null
error_message
fi
# Set permissions after file creation
sudo chmod 755 "$PLAYLIST_PATH";
sudo chown "$APPLICATION_FILE_OWNER" "$PLAYLIST_PATH";
# Echo result
confirmation_message "[C] Playlist create: Playlist created."
echo ""

25
scripts/playlist/playlist_edit

@ -0,0 +1,25 @@
#!/bin/bash
# SHOW: EDIT PLAYLIST
# Opens show playlist for editing in nano
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# Check file exists, then reset permissions to ensure editing
if [[ -z $PLAYLIST_PATH ]]; then
sudo chmod 755 $PLAYLIST_PATH ;
sudo chown $PLAYLIST_PATH ;
fi
# Edit playlist
sudo nano $PLAYLIST_PATH;
# Confirm after editing
confirmation_message "[E] Main Stream Playlist Editing Completed"
echo "";

411
scripts/playlist/playlist_view

@ -0,0 +1,411 @@
#!/bin/bash
# MAIN: PLAYLIST VIEW
# Displays Playlist, with details such as time and commented out tracks
# $PLAYLIST_PATH
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# Arrays Declarations
MASTER_USABLE_FILE_CONTENTS_ARRAY=()
# FUNCTION: Sum Times
function sum_times {
# Receive parmeters
INBOUND_ARRAY_FOR_SUMMING=("$@")
# Get array length
INBOUND_ARRAY_FOR_SUMMING_LENGTH=${#INBOUND_ARRAY_FOR_SUMMING[@]}
# Sum - Centiseconds in array
for ((i=0; i<INBOUND_ARRAY_FOR_SUMMING_LENGTH; i++));
do
# ECHOVAR=$((i+1));
TIMECS=${INBOUND_ARRAY_FOR_SUMMING[${i}]};
TIMECS=${TIMECS:9};
if [[ ${TIMECS:0:1} == "0" ]] ; then TIMECS="${TIMECS:1}"; fi # If time has leading zero, remove to prevent token fault
# echo $TIMECS # Debug
TOTAL_ARRAY_TIME_CS=$((TOTAL_ARRAY_TIME_CS+TIMECS));
done
# echo "Total Time in MS: ${TOTAL_ARRAY_TIME_MS}" # DEBUG
# Sum - Seconds only in array
for ((i=0; i<INBOUND_ARRAY_FOR_SUMMING_LENGTH; i++));
do
# ECHOVAR=$((i+1));
TIMES=${INBOUND_ARRAY_FOR_SUMMING[${i}]};
TIMES=${TIMES:6};
TIMES=${TIMES::-3};
if [[ ${TIMES:0:1} == "0" ]] ; then TIMES="${TIMES:1}"; fi # If time has leading zero, remove to prevent token fault
# echo $TIMES # Debug
TOTAL_ARRAY_TIME_S=$((TOTAL_ARRAY_TIME_S+TIMES));
done
# echo "Total Time in S: ${TOTAL_ARRAY_TIME_S}" # DEBUG
# Sum - Minutes only in array
for ((i=0; i<INBOUND_ARRAY_FOR_SUMMING_LENGTH; i++));
do
# ECHOVAR=$((i+1));
TIMEM=${INBOUND_ARRAY_FOR_SUMMING[${i}]};
TIMEM=${TIMEM:3};
TIMEM=${TIMEM::-6};
if [[ ${TIMEM:0:1} == "0" ]] ; then TIMEM="${TIMEM:1}"; fi # If time has leading zero, remove to prevent token fault
# echo $TIMEM # Debug
TOTAL_ARRAY_TIME_M=$((TOTAL_ARRAY_TIME_M+TIMEM));
done
# echo "Total Time in M: ${TOTAL_ARRAY_TIME_M}" # DEBUG
# Sum - Hours only in array
for ((i=0; i<INBOUND_ARRAY_FOR_SUMMING_LENGTH; i++));
do
# ECHOVAR=$((i+1));
TIMEH=${INBOUND_ARRAY_FOR_SUMMING[${i}]};
TIMEH=${TIMEH:0};
TIMEH=${TIMEH::-9};
if [[ ${TIMEH:0:1} == "0" ]] ; then TIMEH="${TIMEH:1}"; fi # If time has leading zero, remove to prevent token fault
# echo $TIMEH # Debug
TOTAL_ARRAY_TIME_H=$((TOTAL_ARRAY_TIME_H+TIMEH));
done
# echo "Total Time in H: ${TOTAL_ARRAY_TIME_H}" # DEBUG
# Assign intermediary variables the totals for further processing
TEMPTOTAL_CS=${TOTAL_ARRAY_TIME_CS}
TEMPTOTAL_S=${TOTAL_ARRAY_TIME_S}
TEMPTOTAL_M=${TOTAL_ARRAY_TIME_M}
TEMPTOTAL_H=${TOTAL_ARRAY_TIME_H}
# Calculation of modolo values to assmenble friendly time:
# Milliseconds - modolo and carryover calculation
TT_CS_MOD=$((TEMPTOTAL_CS%100));
TT_CS_DIV=$((TEMPTOTAL_CS/100));
TT_CS_DIV=${TT_CS_DIV%.*} # Get rid of decimal
# echo "ms - "${TEMPTOTAL_MS} "(modolo of:" ${TT_CS_MOD}"), and div of: "${TT_CS_DIV}; #DEBUG
FRIENDLY_CS=${TT_CS_MOD};
TEMPTOTAL_S=$((TEMPTOTAL_S + TT_CS_DIV));
# Seconds - modolo and carryover calculation
TT_S_MOD=$((TEMPTOTAL_S%60));
TT_S_DIV=$((TEMPTOTAL_S/60));
TT_S_DIV=${TT_S_DIV%.*}; # Get rid of decimal
# echo "s - "${TEMPTOTAL_S} "(modolo of:" ${TT_S_MOD}"), and a div of: "${TT_S_DIV}; #DEBUG
FRIENDLY_S=${TT_S_MOD};
TEMPTOTAL_M=$((TEMPTOTAL_M + TT_S_DIV));
# Minutes - modolo and carryover calculation
TT_M_MOD=$((TEMPTOTAL_M%60));
TT_M_DIV=$((TEMPTOTAL_M/60));
TT_M_DIV=${TT_M_DIV%.*}; # Get rid of decimal
# echo "m - "${TEMPTOTAL_M} "(modolo of:" ${TT_M_MOD}"), and a div of: "${TT_M_DIV}; #DEBUG
FRIENDLY_M=${TT_M_MOD};
TEMPTOTAL_H=$((TEMPTOTAL_H + TT_M_DIV));
# Hours - modolo (no carryover, because days are not calculated)
TT_H_MOD=$((TEMPTOTAL_H%24));
TT_H_DIV=$((TEMPTOTAL_H/24));
TT_H_DIV=${TT_H_DIV%.*}; # Get rid of decimal
# echo "h - "${TEMPTOTAL_H} "(modolo of:" ${TT_H_MOD}"), and a div of: "${TT_H_DIV}; #DEBUG
FRIENDLY_H=${TEMPTOTAL_H};
# Display Friendly Time:
SUM_FUNCTION_RETURN="${FRIENDLY_H}h ${FRIENDLY_M}m ${FRIENDLY_S}.${FRIENDLY_CS}s"
echo "$SUM_FUNCTION_RETURN"
# Unset Variables
FRIENDLY_H=""
FRIENDLY_M=""
FRIENDLY_S=""
FRIENDLY_CS=""
TOTAL_ARRAY_TIME_MS=""
TOTAL_ARRAY_TIME_S=""
TOTAL_ARRAY_TIME_M=""
TOTAL_ARRAY_TIME_H=""
SUM_FUNCTION_RETURN=""
}
function get_ffprobe_time {
# Capture value pass
TIME_CHECK_INPUT=$1
# Use ffprobe and various text stream actions to pull time value
FF_OUTPUT=$(ffprobe "$TIME_CHECK_INPUT" 2>&1 | grep "Duration");
FF_OUTPUT=${FF_OUTPUT:12};
FF_OUTPUT=${FF_OUTPUT::-36};
# Return value
echo $FF_OUTPUT;
}
function calculate_playlist_time {
# Instsantiate Array
MASTER_USABLE_FILE_CONTENTS_ARRAY=()
# Read playlist file contents
while IFS= read -r PLAYLIST_FILE_LINE
do
# Remove leading spaces
PLAYLIST_LINE_NO_LEADING_SPACES=$(echo -e "${PLAYLIST_FILE_LINE}" | sed -e 's/^[[:space:]]*//')
# If file line is not empty and ends in .mp3
if [[ "$PLAYLIST_LINE_NO_LEADING_SPACES" != "" && $PLAYLIST_LINE_NO_LEADING_SPACES == *.mp3 ]]; then
# Add file to master file contents array, get length
MASTER_USABLE_FILE_CONTENTS_ARRAY+=("$PLAYLIST_LINE_NO_LEADING_SPACES")
# Master usable array length
MASTER_USABLE_ARRAY_LENGTH=${#MASTER_USABLE_FILE_CONTENTS_ARRAY[@]}
fi
done < "$PLAYLIST_PATH"
# Create arrays for both commented and non commented lines
ARRAY_OF_QUEUED_TIMES=()
ARRAY_OF_ALL_TIMES=()
for LINE_FOR_HASH_CHECK in "${MASTER_USABLE_FILE_CONTENTS_ARRAY[@]}"; do
# If first character beings with hash
if [[ ${LINE_FOR_HASH_CHECK:0:1} = "#" ]]; then
# Remove Hash
# LINE_FOR_HASH_CHECK=$(echo $LINE_FOR_HASH_CHECK | sed -e "s/\#//")
LINE_FOR_HASH_CHECK=$(echo -e "${LINE_FOR_HASH_CHECK}" | sed -e 's/^[#| ]*//')
LINE_FOR_HASH_CHECK=$(echo -e "${LINE_FOR_HASH_CHECK}" | sed -e 's/^[[:space:]]*//')
# Run get_ffprobe_time for value
FF_PROBE_RESULT=$(get_ffprobe_time "${LINE_FOR_HASH_CHECK}")
# Add to arrays (both, in this case)
ARRAY_OF_ALL_TIMES=( "${ARRAY_OF_ALL_TIMES[@]}" "$FF_PROBE_RESULT" )
# Else if line doesn't start with hash
else
# Run get_ffprobe_time for value
FF_PROBE_RESULT=$(get_ffprobe_time "${LINE_FOR_HASH_CHECK}")
# # Add to all array only
ARRAY_OF_QUEUED_TIMES=( "${ARRAY_OF_QUEUED_TIMES[@]}" "$FF_PROBE_RESULT" )
ARRAY_OF_ALL_TIMES=( "${ARRAY_OF_ALL_TIMES[@]}" "$FF_PROBE_RESULT" )
fi
done
# Render Results
printf "${COLOR_GREEN}[V] Playlist view:${COLOR_DEFAULT}\n";
echo ""
echo ""
echo " ${FONT_BOLD}PLAYLIST FILES (HH:MM:SS.MS)${FONT_DEFAULT}"
echo ""
# Numbmering Indexes (the printable ones)
FRIENDLY_INDEX=1;
COMPLETE_INDEX=1;
# Create Array
ARRAY_OF_QUEUED_TRACKS=()
for (( i = 0; i < $MASTER_USABLE_ARRAY_LENGTH; i++ )); do
# Prepare Filename to Echo
FILENAME_TO_ECHO=${MASTER_USABLE_FILE_CONTENTS_ARRAY[$i]}
FILENAME_TO_ECHO=$(sed -e s/"^.*queued\/"// <<< ${FILENAME_TO_ECHO})
# check if line begins with #
if [[ ${MASTER_USABLE_FILE_CONTENTS_ARRAY[$i]:0:1} == "#" ]]; then
if [[ ${MASTER_USABLE_FILE_CONTENTS_ARRAY[$i]:0:1} == "#" ]]; then
# Prepare "printable complete index"
if [[ ${#COMPLETE_INDEX} = 1 ]]; then
printf " ${COLOR_GRAY}[0$COMPLETE_INDEX] ${ARRAY_OF_ALL_TIMES[$i]} โ€“ # ${FILENAME_TO_ECHO}${COLOR_DEFAULT}\n"
else
printf " ${COLOR_GRAY}[$COMPLETE_INDEX] ${ARRAY_OF_ALL_TIMES[$i]} โ€“ # ${FILENAME_TO_ECHO}${COLOR_DEFAULT}\n"
fi
fi
# Else if line doesn't start with #
else
# If does not start with #
if [[ ${#FRIENDLY_INDEX} = 1 ]]; then
printf " 0$FRIENDLY_INDEX"
else
printf " $FRIENDLY_INDEX"
fi
FRIENDLY_INDEX=$((FRIENDLY_INDEX+1))
# Prepare "printable complete index" (later gets indexed outside loop)
if [[ ${#COMPLETE_INDEX} = 1 ]]; then
printf " $SYMBOL_RAQUO [0$COMPLETE_INDEX] "
else
printf " $SYMBOL_RAQUO [$COMPLETE_INDEX] "
fi
# Echo Time
echo -e " ${ARRAY_OF_ALL_TIMES[$i]} โ€“ ${FILENAME_TO_ECHO}"
fi
# Index "complete index"
COMPLETE_INDEX=$((COMPLETE_INDEX+1))
done
# Deincrement friendly index, because increment happens in loop after it's printed
FRIENDLY_INDEX=$(("$FRIENDLY_INDEX-1")) # Get final count of queued times
FINAL_COUNT_OF_QUEUED_ITEMS=${#ARRAY_OF_QUEUED_TIMES[@]}
# Unsetariables and get sum of time arrays (for all files and queued files)
SUM_OF_QUEUED_TIMES=""
# SUM_OF_NT_OF_ALL_ITEMS=${#ARRAY_OF_ALL_TIMES[@]}ALL_TIMES=""
SUM_OF_QUEUED_TIMES=$(sum_times "${ARRAY_OF_QUEUED_TIMES[@]}")
SUM_OF_ALL_TIMES=$(sum_times "${ARRAY_OF_ALL_TIMES[@]}")
# Echo Output
echo -e ""
echo -e " ${FONT_BOLD}Total (${FINAL_COUNT_OF_QUEUED_ITEMS}/${MASTER_USABLE_ARRAY_LENGTH} tracks): $SUM_OF_QUEUED_TIMES / $SUM_OF_ALL_TIMES${FONT_DEFAULT}\n"
echo -e ""
echo -e ""
echo -e ""
}
function verify_playlist_integrity() {
# Clear Array
INTEGRITY_CHECK_FILE_LINES_ARRAY=()
# Declare integrity check flag
INTEGRITY_CHECK_FLAG="true"
# Read playlist file contents
while IFS= read -r PLAYLIST_FILE_LINE
do
# Remove leading spaces
PLAYLIST_LINE_WITH_NO_LEADING_SPACES=$(echo -e "${PLAYLIST_FILE_LINE}" | sed -e 's/^[[:space:]]*//')
# If line isn't blank
if [[ -n $PLAYLIST_LINE_WITH_NO_LEADING_SPACES ]];
then
# If ends in .mp3
if [[ "$PLAYLIST_LINE_WITH_NO_LEADING_SPACES" == *.mp3 ]]; then
# remove pound
PLAYLIST_LINE_WITH_NO_LEADING_POUND=$(echo -e "${PLAYLIST_LINE_WITH_NO_LEADING_SPACES}" | sed -e 's/^[#| ]*//')
# Add file to master file contents array, get length
INTEGRITY_CHECK_FILE_LINES_ARRAY+=("$PLAYLIST_LINE_WITH_NO_LEADING_POUND")
fi
# If line is blank (then don't add to array / continue)
else
continue
fi
done < "$PLAYLIST_PATH"
# Check that a file exists for each playlist line
for INTEGRITY_CHECK_ITEM in "${INTEGRITY_CHECK_FILE_LINES_ARRAY[@]}"
do
# If doesn't exist then throw notice
if [[ ! -f "$INTEGRITY_CHECK_ITEM" ]];
then
# Flag as failed
INTEGRITY_CHECK_FLAG="false"
fi
done
echo $INTEGRITY_CHECK_FLAG
}
# If playlist file exists, then do routine
if test -f "$PLAYLIST_PATH";
# Execute calcualte_playlist_time
then
MASTER_PLAYLIST_INTEGRITY_CHECK=$(verify_playlist_integrity)
if [[ "$MASTER_PLAYLIST_INTEGRITY_CHECK" == "true" ]];
# If playlist integrity check passed
then
echo "Calculating playlist time..."
calculate_playlist_time
# else error
else
error_message "[V] View playlist: playlist contains invalid refs. Please edit or recreate for summary."
echo ""
fi
# else if playlist file doesn't exist
else
error_message "[V] View playlist: playlist file not found. Run \"C\" to create.";
echo ""
fi

56
scripts/queued/queued_folder_contents

@ -0,0 +1,56 @@
#!/bin/bash
# SHOW: CREATE/UPDATE PLAYLIST
# Creates and/or updates a playlist to reflect what's in openmic-audio_queued folder
# Includes and Declarations (global variables, formatting, and functions)
source "$APPLICATION_ROOT/scripts/system/system-functions"
source "$APPLICATION_ROOT/scripts/system/system-declarations"
# Check if directory is empty
if [[ $(ls "$AUDIO_QUEUED_DIRECTORY") ]]; then
# If not empty, render list
echo -e "${COLOR_GREEN}[Q] \"audio_queued\" folder contents (${i} items):${COLOR_DEFAULT}"
echo -e ""
echo -e ""
echo -e " ${FONT_BOLD}SHOW QUEUED FOLDER CONTENTS${FONT_DEFAULT}"
echo -e ""
# Cycle through openmic audio queued directory, and print each line (just filename)
i=1
for FILE in "$AUDIO_QUEUED_DIRECTORY"/*; do
# Check i's length. If less than 10, add zero to front
STRLENGTH=${#i}
if [[ $STRLENGTH == 1 ]]; then
LEADING_ZERO_INSERTION="0"
else
LEADING_ZERO_INSERTION=""
fi
# Render line (FILE printout) with number in front
JUST_FILENAME=$(echo "$FILE" | sed "s/.*\///")
echo -e " $LEADING_ZERO_INSERTION$i: \"$JUST_FILENAME\""
# Increment i
i=$((i+1));
done
FILE_COUNT=$((i-1))
echo -e "";
echo -e " ${FONT_BOLD}[${FILE_COUNT} Files Found]${FONT_DEFAULT}\n"
echo -e "";
echo -e "";
echo -e "";
else
# If directory is empty
error_message "[Q] The \"audio_queued\" directory is empty. Add audio files.";
echo ""
fi

93
scripts/streaming/main/main-stream_files

@ -0,0 +1,93 @@
#!/bin/bash
# SHOW: STREAM FILES
# Streams files as indexed in show-playlist.m3u (which is based on show-audio_queud)
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# Get active config name, construct path to streamable config file (for validation)
CURRENTLY_ACTIVE_CONFIG_NAME=$(<"$CONFIG_FILE_IDENTIFIER_PATH")
STREAMABLE_CONFIG_FILE_PATH="$CONFIG_DIRECTORY/config-$CURRENTLY_ACTIVE_CONFIG_NAME.json"
# Check if config file exists
if [[ -f "$STREAMABLE_CONFIG_FILE_PATH" ]];
# If exists
then
# Parse JSON config file for each variable
v1='main_host'
MAIN_HOST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v1//p" $STREAMABLE_CONFIG_FILE_PATH))
v2='main_port'
MAIN_PORT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v2//p" $STREAMABLE_CONFIG_FILE_PATH))
v3='main_user'
MAIN_USER=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v3//p" $STREAMABLE_CONFIG_FILE_PATH))
v4='main_password'
MAIN_PASSWORD=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v4//p" $STREAMABLE_CONFIG_FILE_PATH))
v5='main_mount'
MAIN_MOUNT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v5//p" $STREAMABLE_CONFIG_FILE_PATH))
v6='playlist_url'
PLAYLIST_URL=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v6//p" $STREAMABLE_CONFIG_FILE_PATH))
v7='randomize_playlist_files'
RANDOMIZE_PLAYLIST_FILES=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v7//p" $STREAMABLE_CONFIG_FILE_PATH))
v8='hardware_audio_frame_size'
HARDWARE_AUDIO_FRAME_SIZE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v8//p" $STREAMABLE_CONFIG_FILE_PATH))
# Ensure all configuration files are not blank
if [ -z "${MAIN_HOST}" ] || [ -z "${MAIN_PORT}" ] || [ -z "${MAIN_USER}" ] || [ -z "${MAIN_PASSWORD}" ] || [ -z "${MAIN_MOUNT}" ] || [ -z "${PLAYLIST_URL}" ] || [ -z "${RANDOMIZE_PLAYLIST_FILES}" ] || [ -z "${HARDWARE_AUDIO_FRAME_SIZE}" ]
then
# Fault if config variable is blank
printf "${COLOR_RED}[F] Stream Files (to Main): Streaming failed. Check your playlist, files, and/or settings.${COLOR_DEFAULT}\n\n";
else
printf "${COLOR_GREEN}[F] Stream Files (to Main):${COLOR_DEFAULT}\n";
printf "\n"
printf "\n"
printf "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[STARTING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n"
printf "${COLOR_MAGENTA}"
# Launch Liquidsoap using variables
# liquidsoap 'set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE'); output.icecast(%mp3,host="'$MAIN_HOST'",port='$MAIN_PORT',user="'$MAIN_USER'",password="'$MAIN_PASSWORD'",mount="'$MAIN_MOUNT'",mksafe(playlist.once(random='$MAIN_RANDOMIZE_PLAYLIST_FILES',on_done=shutdown,"'$PLAYLIST_URL'")))';
liquidsoap '
set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE');
stream_master_source = output.icecast(
%mp3,
host="'$MAIN_HOST'",
port='$MAIN_PORT',
user="'$MAIN_USER'",
password="'$MAIN_PASSWORD'",
mount="'$MAIN_MOUNT'",
fallible=true,
on_stop=shutdown,
playlist.once(
random='$RANDOMIZE_PLAYLIST_FILES',
"'$PLAYLIST_URL'"
)
)
stream_master_source
'
printf ${COLOR_DEFAULT}
printf "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[EXITING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n"
printf "\n"
printf "\n"
printf "\n"
fi
# If no config file exists
else
error_message "[F] Stream Files (to Main): No config file specified. To stream, please assign a config."
echo ""
fi

113
scripts/streaming/main/main-stream_live_alsa

@ -0,0 +1,113 @@
#!/bin/bash
# SHOW: STREAM LIVE
# Streams show live from input/ALSA
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# Get active config name, construct path to streamable config file (for validation)
CURRENTLY_ACTIVE_CONFIG_NAME=$(<"$CONFIG_FILE_IDENTIFIER_PATH")
STREAMABLE_CONFIG_FILE_PATH="$CONFIG_DIRECTORY/config-$CURRENTLY_ACTIVE_CONFIG_NAME.json"
# Check if config file exists
if [[ -f "$STREAMABLE_CONFIG_FILE_PATH" ]];
# If exists
then
# Parse JSON config file for each crucial streaming variable
v1='main_host'
MAIN_HOST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v1//p" $STREAMABLE_CONFIG_FILE_PATH))
v2='main_port'
MAIN_PORT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v2//p" $STREAMABLE_CONFIG_FILE_PATH))
v3='main_user'
MAIN_USER=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v3//p" $STREAMABLE_CONFIG_FILE_PATH))
v4='main_password'
MAIN_PASSWORD=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v4//p" $STREAMABLE_CONFIG_FILE_PATH))
v5='main_mount'
MAIN_MOUNT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v5//p" $STREAMABLE_CONFIG_FILE_PATH))
v6='playlist_url'
PLAYLIST_URL=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v6//p" $STREAMABLE_CONFIG_FILE_PATH))
v7='randomize_playlist_files'
RANDOMIZE_PLAYLIST_FILES=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v7//p" $STREAMABLE_CONFIG_FILE_PATH))
v8='hardware_audio_frame_size'
HARDWARE_AUDIO_FRAME_SIZE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v8//p" $STREAMABLE_CONFIG_FILE_PATH))
# Parse JSON config file for each metadata streaming variable
v9='main_metadata_artist'
MAIN_METADATA_ARTIST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v9//p" $STREAMABLE_CONFIG_FILE_PATH))
# MAIN_METADATA_ARTIST="${MAIN_METADATA_ARTIST// /\+}"
vA='main_metadata_title'
MAIN_METADATA_TITLE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$vA//p" $STREAMABLE_CONFIG_FILE_PATH))
# MAIN_METADATA_TITLE="${MAIN_METADATA_TITLE// /\+}"
# Ensure all configuration files are not blank
if [ -z "${MAIN_HOST}" ] || [ -z "${MAIN_PORT}" ] || [ -z "${MAIN_USER}" ] || [ -z "${MAIN_PASSWORD}" ] || [ -z "${MAIN_MOUNT}" ] || [ -z "${PLAYLIST_URL}" ] || [ -z "${RANDOMIZE_PLAYLIST_FILES}" ] || [ -z "${HARDWARE_AUDIO_FRAME_SIZE}" ]
then
# Fault if config variable is blank
error_message "[L] Stream ALSA (to Main): Streaming failed. Please check your configuration settings.";
echo ""
else
# Notice of Execution
confirmation_message "${COLOR_GREEN}[L] Stream ALSA (to Main):${COLOR_DEFAULT}";
# Encode and Submit Metadata Change (Hack: two requests to get changes to take)
CONVERTED_MAIN_METADATA_TITLE=$(url_encode_string "$MAIN_METADATA_TITLE")
CONVERTED_MAIN_METADATA_ARTIST=$(url_encode_string "$MAIN_METADATA_ARTIST")
curl "http://$MAIN_USER:$MAIN_PASSWORD@$MAIN_HOST:$MAIN_PORT/admin/metadata?mode=updinfo&mount=/&title='$CONVERTED_MAIN_METADATA_TITLE'&artist='$CONVERTED_MAIN_METADATA_ARTIST'"
sleep 5
curl "http://$MAIN_USER:$MAIN_PASSWORD@$MAIN_HOST:$MAIN_PORT/admin/metadata?mode=updinfo&mount=/&title='$CONVERTED_MAIN_METADATA_TITLE'&artist='$CONVERTED_MAIN_METADATA_ARTIST'"
# Liquidsoap Log
echo -e "\n"
echo -e "\n"
echo -e "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[STARTING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n"
echo -e "${COLOR_MAGENTA}"
# Launch Liquidsoap using variables
# liquidsoap 'set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE'); output.icecast(%mp3,host="'$MAIN_HOST'",port='$MAIN_PORT',user="'$MAIN_USER'",password="'$MAIN_PASSWORD'",mount="'$MAIN_MOUNT'",mksafe(playlist.once(random='$MAIN_RANDOMIZE_PLAYLIST_FILES',on_done=shutdown,"'$PLAYLIST_URL'")))';
liquidsoap '
set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE');
stream_master_source = output.icecast(
%mp3(bitrate=192,samplerate=44100),
host="'$MAIN_HOST'",
port='$MAIN_PORT',
user="'$MAIN_USER'",
password="'$MAIN_PASSWORD'",
mount="'$MAIN_MOUNT'",
input.alsa(bufferize = true)
)
stream_master_source
'
printf ${COLOR_DEFAULT}
printf "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[EXITING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n"
printf "\n"
printf "\n"
printf "\n"
fi
# If no config file exists
else
error_message "[L] Stream ALSA (to Main): No config file specified. To stream, please assign a config."
echo ""
fi

99
scripts/streaming/testing/testing-stream_files

@ -0,0 +1,99 @@
#!/bin/bash
# TESTING: STREAM FILES
# Streams files as indexed in openmic-playlist.m3u (which is based on openmic-audio_queud)
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# Get active config name, construct path to streamable config file (for validation)
CURRENTLY_ACTIVE_CONFIG_NAME=$(<"$CONFIG_FILE_IDENTIFIER_PATH")
STREAMABLE_CONFIG_FILE_PATH="$CONFIG_DIRECTORY/config-$CURRENTLY_ACTIVE_CONFIG_NAME.json"
# Check if config file exists
if [[ -f "$STREAMABLE_CONFIG_FILE_PATH" ]];
# If exists
then
# Parse JSON config file for each variable
v1='testing_host'
TESTING_HOST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v1//p" $STREAMABLE_CONFIG_FILE_PATH))
v2='testing_port'
TESTING_PORT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v2//p" $STREAMABLE_CONFIG_FILE_PATH))
v3='testing_user'
TESTING_USER=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v3//p" $STREAMABLE_CONFIG_FILE_PATH))
v4='testing_password'
TESTING_PASSWORD=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v4//p" $STREAMABLE_CONFIG_FILE_PATH))
v5='testing_mount'
TESTING_MOUNT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v5//p" $STREAMABLE_CONFIG_FILE_PATH))
v6='playlist_url'
PLAYLIST_URL=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v6//p" $STREAMABLE_CONFIG_FILE_PATH))
v7='randomize_playlist_files'
RANDOMIZE_PLAYLIST_FILES=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v7//p" $STREAMABLE_CONFIG_FILE_PATH))
v8='hardware_audio_frame_size'
HARDWARE_AUDIO_FRAME_SIZE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v8//p" $STREAMABLE_CONFIG_FILE_PATH))
# Ensure all configuration files are not blank
if [ -z "${TESTING_HOST}" ] || [ -z "${TESTING_PORT}" ] || [ -z "${TESTING_USER}" ] || [ -z "${TESTING_PASSWORD}" ] || [ -z "${TESTING_MOUNT}" ] || [ -z "${PLAYLIST_URL}" ] || [ -z "${RANDOMIZE_PLAYLIST_FILES}" ] || [ -z "${HARDWARE_AUDIO_FRAME_SIZE}" ]
then
# Fault if config variable is blank
error_message "[f] Stream Files (to Testing): Streaming failed. Check your playlist, files, and/or settings.${COLOR_DEFAULT}";
echo ""
else
confirmation_message "[f] Stream Files (to Testing):";
echo ""
echo ""
echo -e "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[STARTING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n"
echo -e "${COLOR_MAGENTA}"
# Launch Liquidsoap using variables
# liquidsoap 'set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE'); output.icecast(%mp3,host="'$TESTING_HOST'",port='$TESTING_PORT',user="'$TESTING_USER'",password="'$TESTING_PASSWORD'",mount="'$TESTING_MOUNT'",mksafe(playlist.once(random='$RANDOMIZE_PLAYLIST_FILES',on_done=shutdown,"'$PLAYLIST_URL'")))';
liquidsoap '
set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE');
stream_master_source = output.icecast(
%mp3,
host="'$TESTING_HOST'",
port='$TESTING_PORT',
user="'$TESTING_USER'",
password="'$TESTING_PASSWORD'",
mount="'$TESTING_MOUNT'",
fallible=true,
on_stop=shutdown,
playlist.once(
random='$RANDOMIZE_PLAYLIST_FILES',
"'$PLAYLIST_URL'"
)
)
stream_master_source
'
echo -e ${COLOR_DEFAULT}
echo -e "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[EXITING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n"
echo -e "\n"
echo -e "\n"
echo -e "\n"
fi
# If no config file exists
else
error_message "[f] Stream Files (to Testing): No config file specified. To stream, please assign a config."
echo ""
fi

113
scripts/streaming/testing/testing-stream_live_alsa

@ -0,0 +1,113 @@
#!/bin/bash
# OPENMIC: STREAM LIVE
# Streams openmic live from input/ALSA
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# Get active config name, construct path to streamable config file (for validation)
CURRENTLY_ACTIVE_CONFIG_NAME=$(<"$CONFIG_FILE_IDENTIFIER_PATH")
STREAMABLE_CONFIG_FILE_PATH="$CONFIG_DIRECTORY/config-$CURRENTLY_ACTIVE_CONFIG_NAME.json"
# Check if config file exists
if [[ -f "$CURRENTLY_ACTIVE_CONFIG_NAME" ]];
# If exists
then
# Parse JSON config file for each crucial streaming variable
v1='testing_host'
TESTING_HOST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v1//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
v2='testing_port'
TESTING_PORT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v2//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
v3='testing_user'
TESTING_USER=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v3//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
v4='testing_password'
TESTING_PASSWORD=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v4//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
v5='testing_mount'
TESTING_MOUNT=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v5//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
v6='playlist_url'
PLAYLIST_URL=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v6//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
v7='randomize_playlist_files'
RANDOMIZE_PLAYLIST_FILES=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v7//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
v8='hardware_audio_frame_size'
HARDWARE_AUDIO_FRAME_SIZE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v8//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
# Parse JSON config file for each metadata streaming variable
v9='testing_metadata_artist'
TESTING_METADATA_ARTIST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$v9//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
# TESTING_METADATA_ARTIST="${TESTING_METADATA_ARTIST// /\+}"
vA='testing_metadata_title'
TESTING_METADATA_TITLE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$vA//p" $CURRENTLY_ACTIVE_CONFIG_NAME))
# TESTING_METADATA_TITLE="${TESTING_METADATA_TITLE// /\+}"
# Ensure all configuration files are not blank
if [ -z "${TESTING_HOST}" ] || [ -z "${TESTING_PORT}" ] || [ -z "${TESTING_USER}" ] || [ -z "${TESTING_PASSWORD}" ] || [ -z "${TESTING_MOUNT}" ] || [ -z "${PLAYLIST_URL}" ] || [ -z "${RANDOMIZE_PLAYLIST_FILES}" ] || [ -z "${HARDWARE_AUDIO_FRAME_SIZE}" ]
then
# Fault if config variable is blank
error_message "[l] Stream ALSA (to Testing): Streaming failed. Please check your configuration settings."
echo ""
else
# Notice of Execution
confirmation_message "${COLOR_GREEN}[l] Stream ALSA (to Testing):${COLOR_DEFAULT}";
# Encode and Submit Metadata Change (Hack: two requests to get changes to take)
CONVERTED_TESTING_METADATA_TITLE=$(url_encode_string "$TESTING_METADATA_TITLE")
CONVERTED_TESTING_METADATA_ARTIST=$(url_encode_string "$TESTING_METADATA_ARTIST")
curl "http://$TESTING_USER:$TESTING_PASSWORD@$TESTING_HOST:$TESTING_PORT/admin/metadata?mode=updinfo&mount=/&title='$CONVERTED_TESTING_METADATA_TITLE'&artist='$CONVERTED_TESTING_METADATA_ARTIST'"
sleep 5
curl "http://$TESTING_USER:$TESTING_PASSWORD@$TESTING_HOST:$TESTING_PORT/admin/metadata?mode=updinfo&mount=/&title='$CONVERTED_TESTING_METADATA_TITLE'&artist='$CONVERTED_TESTING_METADATA_ARTIST'"
# Liquidsoap Log
echo -e "\n"
echo -e "\n"
echo -e "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[STARTING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n"
echo -e "${COLOR_MAGENTA}"
# Launch Liquidsoap using variables
# liquidsoap 'set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE'); output.icecast(%mp3,host="'$TESTING_HOST'",port='$TESTING_PORT',user="'$TESTING_USER'",password="'$TESTING_PASSWORD'",mount="'$TESTING_MOUNT'",mksafe(playlist.once(random='$RANDOMIZE_PLAYLIST_FILES',on_done=shutdown,"'$PLAYLIST_URL'")))';
liquidsoap '
set("frame.audio.size",'$HARDWARE_AUDIO_FRAME_SIZE');
stream_master_source = output.icecast(
%mp3(bitrate=192,samplerate=44100),
host="'$TESTING_HOST'",
port='$TESTING_PORT',
user="'$TESTING_USER'",
password="'$TESTING_PASSWORD'",
mount="'$TESTING_MOUNT'",
input.alsa(bufferize = true)
)
stream_master_source
'
echo -e ${COLOR_DEFAULT}
echo -e "${COLOR_LIGHT_MAGENTA}${FONT_BOLD}[EXITING LIQUIDSOAP]${FONT_DEFAULT}${COLOR_DEFAULT}\n"
echo -e "\n"
echo -e "\n"
echo -e "\n"
fi
# If no config file exists
else
error_message "[l] Stream ALSA (to Testing): No config file specified. To stream, please assign a config."
echo ""
fi

18
scripts/system/system-alsa_mixer

@ -0,0 +1,18 @@
#!/bin/bash
# SYSTEM: ALSA MIXER
# Launch alsamixer
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
# If playlist exists, delete it.
sudo alsamixer
# Echo result
confirmation_message "[M] ALSA mixer visitation completed"
echo "";

356
scripts/system/system-config

@ -0,0 +1,356 @@
#!/bin/bash
# SYSTEM: CONFIG Options
# Edit System Configuration (.json) file
# COPY HAS VALIDATION BUGS
# RENAME IS NOT YET DONE
# Includes and Declarations (global variables, formatting, and functions)
source "${APPLICATION_ROOT}/scripts/system/system-functions"
source "${APPLICATION_ROOT}/scripts/system/system-declarations"
#
#
# FUNCTION: Refresh Config File Reference Array
# Creates two new arrays in parallel of availalble configurations
# Array 1 - $CONFIG_PROFILES_ARRAY : list of profile names
# Array 2 - $CONFIG_PROFILES_PATHS_ARRAY : list of profile paths
#
#
function refresh_config_file_reference_array () {
# Empty Arrays
unset CONFIG_PROFILES_ARRAY
unset CONFIG_PROFILES_PATHS_ARRAY
# If Config Directory is empty
if [ -z "$(ls -A $CONFIG_DIRECTORY)" ]; then
echo - "Config directory is currently empty. Please create a new config file using option 'n'."
# Else if Config Directory is not empty
else
# Instantiate counter, then read directory (declared in file 'system-declarations')
for CONFIG_DIRECTORY_ITEM in "$CONFIG_DIRECTORY"/*; do
# If file is of type json, proceed
if [[ $CONFIG_DIRECTORY_ITEM == *.json ]]; then
# if file is of pitfall condition, rename with timestamp
CONFIG_NAME=$(echo "${CONFIG_DIRECTORY_ITEM}" | sed "s|$CONFIG_DIRECTORY/||")
if [[ $CONFIG_NAME == "config-.json" ]] || [[ $CONFIG_NAME == "config.json" ]]; then
# Create hex value of 6 length, and rename violating files
RANDOM_HEX_VALUE=$( generate_random_hex_value 6 )
CONFIG_NAME_RENAMED="config-${RANDOM_HEX_VALUE}.json"
mv "$CONFIG_DIRECTORY/$CONFIG_NAME" "$CONFIG_DIRECTORY/$CONFIG_NAME_RENAMED"
# Declare chaneges for main name and directory variable (then alert)
CONFIG_DIRECTORY_ITEM="$CONFIG_DIRECTORY/$CONFIG_NAME_RENAMED"
warning_message "[Alert] Unnamed config \"$CONFIG_NAME\" renamed \"$CONFIG_NAME_RENAMED\" "
CONFIG_NAME="$CONFIG_NAME_RENAMED"
fi
# Full File Path, and sed a Display Name (ennumerated)
CONFIG_NAME_TRUNCATED=$(echo "${CONFIG_NAME}" | sed "s|config-||" | sed "s/.json//")
# Apply to master arrays
CONFIG_PROFILES_ARRAY+=("$CONFIG_NAME_TRUNCATED")
CONFIG_PROFILES_PATHS_ARRAY+=("$CONFIG_DIRECTORY_ITEM")
fi
done
# # Debug:
# echo "CONFIG PROFILES ARRAY: ${CONFIG_PROFILES_ARRAY[*]}"
# echo "CONFIG PROFILES PATHS ARRAY: ${CONFIG_PROFILES_PATHS_ARRAY[*]}"
fi
}
#
#
# FUNCTION: List existing config files
# Echos a list of available profile names (called in render_config_menu)
#
#
function list_existing_config_files {
# Get active file name
CURRENTLY_ACTIVE_CONFIG_FILE=$(<"$CONFIG_FILE_IDENTIFIER_PATH")
# List menu section heading
echo -e " ${COLOR_WHITE}${FONT_BOLD}CONFIG PROFILES & META:${FONT_DEFAULT}${COLOR_DEFAULT}";
if (( ${#CONFIG_PROFILES_ARRAY[@]} )); then
# If config array does exist
PROFILE_COUNTER=0
for i in ${CONFIG_PROFILES_ARRAY[*]}
do :
# Check if active profile name is current 'for' item
if [[ $i == "$CURRENTLY_ACTIVE_CONFIG_FILE" ]]; then
# Render profile name
echo -e " ${COLOR_CYAN}${FONT_BOLD}${SYMBOL_RAQUO}${COLOR_DEFAULT}${FONT_DEFAULT} $i ${COLOR_CYAN}(using)${COLOR_DEFAULT}"
# Render profile metadata
JSON_FIELD_NAME_META_ARTIST='main_metadata_artist'
MAIN_METADATA_ARTIST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$JSON_FIELD_NAME_META_ARTIST//p" ${CONFIG_PROFILES_PATHS_ARRAY[$PROFILE_COUNTER]}))
# MAIN_METADATA_ARTIST="${MAIN_METADATA_ARTIST// /\+}"
echo -e " Artist: \"$MAIN_METADATA_ARTIST\"";
JSON_FIELD_NAME_META_TITLE='main_metadata_title'
MAIN_METADATA_TITLE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$JSON_FIELD_NAME_META_TITLE//p" ${CONFIG_PROFILES_PATHS_ARRAY[$PROFILE_COUNTER]}))
# MAIN_METADATA_TITLE="${MAIN_METADATA_TITLE// /\+}"
echo -e " Title: \"$MAIN_METADATA_TITLE\"";
# Empty metadata display variables
MAIN_METADATA_ARTIST=""
MAIN_METADATA_TITLE=""
else
# Render profile name
echo -e " $i"
# Render profile metadata
JSON_FIELD_NAME_META_ARTIST='main_metadata_artist'
MAIN_METADATA_ARTIST=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$JSON_FIELD_NAME_META_ARTIST//p" ${CONFIG_PROFILES_PATHS_ARRAY[$PROFILE_COUNTER]}))
# MAIN_METADATA_ARTIST="${MAIN_METADATA_ARTIST// /\+}"
echo -e " Artist: \"$MAIN_METADATA_ARTIST\"";
JSON_FIELD_NAME_META_TITLE='main_metadata_title'
MAIN_METADATA_TITLE=$(sed -e s/'[ \t]*\"\"\:\"'// -e s/'".*'// <<< $(sed -n "s/$JSON_FIELD_NAME_META_TITLE//p" ${CONFIG_PROFILES_PATHS_ARRAY[$PROFILE_COUNTER]}))
# MAIN_METADATA_TITLE="${MAIN_METADATA_TITLE// /\+}"
echo -e " Title: \"$MAIN_METADATA_TITLE\"";
# Empty metadata display variables
MAIN_METADATA_ARTIST=""
MAIN_METADATA_TITLE=""
fi
# Increment Counter
PROFILE_COUNTER=$((PROFILE_COUNTER+1))
done
else
echo -e " ${COLOR_RED}${FONT_BOLD}[Empty! - run \"n\" to create a profile!]${FONT_DEFAULT}${COLOR_DEFAULT}"
fi
# Empty variables
PROFILE_COUNTER=0
}
#
#
# FUNCTION: Verify Configuration Filename Characters
# Verifies inbound string against specified $REGEX, returning true or false match
# Returns a true or false confirmation
#
#
function verify_configuration_filename_characters()
{
REGEX="^[a-zA-Z0-9\ \_-]+$"
if [[ "$*" =~ ${REGEX} ]]
then
TEMP="true"
else
TEMP="false"
fi
echo $TEMP
}
#
#
# FUNCTION: Convert Spaces to Underscores
# Converts inbound string's spaces to underscores, returns converted string
#
#
function convert_spaces_to_underscores() {
TEMP=${*// /_}
echo "$TEMP"
}
#
#
# FUNCTION: Render Config Menu
# Renders main configuration menu (option "J" from main menu)
#
#
function render_config_menu {
list_existing_config_files
echo -e ""
# Mini HR
printf " "
render_mini_horizontal_rule
echo -e ""
# Render
echo -e " ${COLOR_WHITE}${FONT_BOLD}CONFIG OPTIONS:${FONT_DEFAULT}${COLOR_DEFAULT}";
echo -e " ${COLOR_CYAN}${FONT_BOLD}e${FONT_DEFAULT}${COLOR_DEFAULT} : edit";
echo -e " ${COLOR_CYAN}${FONT_BOLD}n${FONT_DEFAULT}${COLOR_DEFAULT} : new";
echo -e " ${COLOR_CYAN}${FONT_BOLD}d${FONT_DEFAULT}${COLOR_DEFAULT} : delete";
echo -e " ${COLOR_CYAN}${FONT_BOLD}c${FONT_DEFAULT}${COLOR_DEFAULT} : copy";
echo -e " ${COLOR_CYAN}${FONT_BOLD}r${FONT_DEFAULT}${COLOR_DEFAULT} : rename";
echo -e " ${COLOR_CYAN}${FONT_BOLD}x${FONT_DEFAULT}${COLOR_DEFAULT} : empty deleted trash";
echo -e ""
echo -e " ${COLOR_WHITE}${FONT_BOLD}CONFIG ACTIVATION:${FONT_DEFAULT}${COLOR_DEFAULT}";
echo -e " ${COLOR_CYAN}${FONT_BOLD}u${FONT_DEFAULT}${COLOR_DEFAULT} : use";
echo -e ""
echo -e ""
echo -e ""
}
#
#
# FUNCTION: Process Config Menu Selection
# Processes main input from config menu
#
#
function process_config_menu_selection() {
# Case Switch
case $1 in
e) # Edit JSON Streaming Profile:
source "${APPLICATION_ROOT}/scripts/system/system-config_edit" ;;
n) # New JSON Streaming Profile:
source "${APPLICATION_ROOT}/scripts/system/system-config_new" ;;
d) # Delete JSON Streaming Profile:
source "${APPLICATION_ROOT}/scripts/system/system-config_delete" ;;
c) # Copy Profile
source "${APPLICATION_ROOT}/scripts/system/system-config_copy" ;;
r) # Rename Profile
source "${APPLICATION_ROOT}/scripts/system/system-config_rename" ;;
u) # Use Profile
source "${APPLICATION_ROOT}/scripts/system/system-config_use" ;;
x) # Empty Trash
source "${APPLICATION_ROOT}/scripts/system/system-config_empty_trash" ;;
esac
}
#
#
# FUNCTION: Main Program Function
# Master program run routine (and run execution)
#
#
function execute_config_routine {
# Refresh Array of Available Configs and render menu
printf "${COLOR_GREEN}[J] Config Options menu:${COLOR_DEFAULT}\n";
echo -e ""
echo -e ""
# Declare, localize, and refresh arrays
unset CONFIG_PROFILES_ARRAY
declare -a CONFIG_PROFILES_ARRAY=() >/dev/null
local $CONFIG_PROFILES_ARRAY >/dev/null
unset CONFIG_PROFILES_PATHS_ARRAY
declare -a CONFIG_PROFILES_PATHS_ARRAY=() >/dev/null
local $CONFIG_PROFILES_PATHS_ARRAY >/dev/null
# Refresh config file list and render menu
refresh_config_file_reference_array
render_config_menu
# Read Command Input
while :
do
# Declare, localize, and refresh arrays
unset CONFIG_PROFILES_ARRAY
declare -a CONFIG_PROFILES_ARRAY=() >/dev/null
local $CONFIG_PROFILES_ARRAY >/dev/null
unset CONFIG_PROFILES_PATHS_ARRAY
declare -a CONFIG_PROFILES_PATHS_ARRAY=() >/dev/null
local $CONFIG_PROFILES_PATHS_ARRAY >/dev/null
# Refresh config file list
refresh_config_file_reference_array
# Refresh config list array and read input
MENU_NAME=`echo -e "${COLOR_CYAN}[Config Menu]${COLOR_DEFAULT}"`
read -p "$MENU_NAME Choice? (RETURN main menu, or \"J\" config options menu): " CONFIG_MENU_INPUT;
# If "J" entered
if [[ $CONFIG_MENU_INPUT == "J" ]]; then
# Refresh Array of Available Configs and render menu
printf "${COLOR_GREEN}[J] Config options menu.${COLOR_DEFAULT}\n"
echo ""
echo ""
refresh_config_file_reference_array
render_config_menu
# If no key entered
elif [[ -z $CONFIG_MENU_INPUT ]]; then
printf "${COLOR_GREEN}[RETURN] Main menu.${COLOR_DEFAULT}\n"
echo ""
refresh_config_file_reference_array
break
# Evaluate Character entered
else
refresh_config_file_reference_array
process_config_menu_selection $CONFIG_MENU_INPUT
fi
done
}
execute_config_routine

67
scripts/system/system-config_copy

@ -0,0 +1,67 @@
#!/bin/bash
# SYSTEM: CONFIG Copy
# If profiles exist
if (( ${#CONFIG_PROFILES_ARRAY[@]} ));
then
# Read input
read -p "Profile to Copy?: " PROFILE_NAME_TO_COPY
# Input validate (check if empty)
if [[ -z "$PROFILE_NAME_TO_COPY" ]]; then
error_message "[c] Config (copy): Input blank. No file identied for copying."
echo -e ""
# Input validate (check for alphanum & "-_")
elif [[ "$PROFILE_NAME_TO_COPY" =~ [^a-zA-Z0-9_-] ]]; then
# Validate response: Invalid characters
error_message "[c] Config (copy): Filenames are alphanum only (no spaces). Try again."
echo -e ""
else
# Check if in array of available files. If not, then create new.
if [[ "${CONFIG_PROFILES_ARRAY[*]}" =~ ${PROFILE_NAME_TO_COPY} ]]; then
# Read Input
read -p "New name for Copy?: " PROFILE_COPY_NAME
# Input validate (check if empty)
if [[ -z "$PROFILE_COPY_NAME" ]]; then
error_message "[c] Config (copy): No filename provide for new copy."
echo -e ""
# Input validate (check for alphanum & "-_")
elif [[ "$PROFILE_COPY_NAME" =~ [^a-zA-Z0-9_-] ]]; then
error_message "[c] Config (copy): New filenames are alphanum only (no spaces). Try again."
echo -e ""
else
# Proceed with copy procedure
sudo cp "$CONFIG_DIRECTORY/config-$PROFILE_NAME_TO_COPY.json" "$CONFIG_DIRECTORY/config-$PROFILE_COPY_NAME.json"
confirmation_message "[c] Config (copy): Copy \"$PROFILE_COPY_NAME\" created from \"$PROFILE_NAME_TO_COPY\"."
echo -e ""
fi
else
error_message "[c] Config (copy): No file \"$PROFILE_NAME_TO_COPY\" exists to copy."
echo -e ""
fi
fi
# If no profiles exist
else
error_message "[c] Config (copy): No config profiles to Copy. Create with \"new\"."
echo -e ""
fi

97
scripts/system/system-config_delete

@ -0,0 +1,97 @@
#!/bin/bash
# SYSTEM: CONFIG Delete
# If profiles exist
if (( ${#CONFIG_PROFILES_ARRAY[@]} ));
then
# Read input
read -p "Name of profile to Delete? (spaces allowable): " CONFIG_PROFILE_TO_DELETE
# Input validate (check if empty)
if [[ -z "$CONFIG_PROFILE_TO_DELETE" ]]
then
error_message "[d] Config (delete): Input blank. No file identied for deletion deleted."
echo -e ""
# Input validate (check for alphanum & "-_ ")
elif [[ "$CONFIG_PROFILE_TO_DELETE" =~ [^a-zA-Z0-9_-] ]]
then
error_message "[n] Config (delete): Filenames are alphanum only (spaces OK). Try again."
echo -e ""
# Proceed with profile deletion
else
# Check if name exists, and if so mark flag
PROFILE_EXISTS_FLAG="false"
for FILE_TO_DELETE_NAME in "${CONFIG_PROFILES_ARRAY[@]}"
do
if [[ "${FILE_TO_DELETE_NAME}" == ${CONFIG_PROFILE_TO_DELETE} ]]
then
PROFILE_EXISTS_FLAG="true"
fi
done
# Perform final action based on flag
if [[ $PROFILE_EXISTS_FLAG == "true" ]]
then
# Reference $CURRENTLY_ACTIVE_CONFIG_FILE to see if deleting is current in use
CURRENTLY_ACTIVE_CONFIG_FILE=$(<"$CONFIG_FILE_IDENTIFIER_PATH")
if [[ ${CONFIG_PROFILE_TO_DELETE} == "$CURRENTLY_ACTIVE_CONFIG_FILE" ]]
# If to delete is in use
then
# Delete file (move to trash)
TIMESTAMP=$(date +%Y-%m-%d--%H-%M-%S)
mv "$CONFIG_DIRECTORY/config-$CONFIG_PROFILE_TO_DELETE.json" "$CONFIG_DIRECTORY/trash/config-$CONFIG_PROFILE_TO_DELETE.json_(DELETED_${TIMESTAMP})"
# Delete config file identifier
truncate -s 0 "$CONFIG_FILE_IDENTIFIER_PATH"
# Confirmation / Alert
warning_message "[WARNING]: Config file no longer specified. Please specify one to stream."
confirmation_message "[d] Config (delete): Deletion of \"$CONFIG_PROFILE_TO_DELETE\" completed (file moved to trash)."
echo -e ""
# If to delete is not in use
else
TIMESTAMP=$(date +%Y-%m-%d--%H-%M-%S)
mv "$CONFIG_DIRECTORY/config-$CONFIG_PROFILE_TO_DELETE.json" "$CONFIG_DIRECTORY/trash/config-$CONFIG_PROFILE_TO_DELETE.json_(DELETED_${TIMESTAMP})"
confirmation_message "[d] Config (delete): Deletion of \"$CONFIG_PROFILE_TO_DELETE\" completed (file moved to trash)."
echo -e ""
fi
# Unset currently actie config file variable
unset CURRENTLY_ACTIVE_CONFIG_FILE
# If profile doesn't exist
else
error_message "[d] Config (delete): No Config named \"$CONFIG_PROFILE_TO_DELETE\" to delete."
echo -e ""
fi
# Unset Flag
unset PROFILE_EXISTS_FLAG
fi
# If no profiles exist
else
error_message "[d] Config (delete): No config profiles to delete. Create with \"new\"."
echo -e ""
fi

54
scripts/system/system-config_edit

@ -0,0 +1,54 @@
#!/bin/bash
# SYSTEM: CONFIG Edit
# Edit System Configuration (.json) file
# If profiles exist
if (( ${#CONFIG_PROFILES_ARRAY[@]} ));
then
# Read Input
read -p "Profile Name to Edit?: " CONFIG_PROFILE_TO_EDIT
# Input validate (check if empty)
if [[ -z "$CONFIG_PROFILE_TO_EDIT" ]]
then
error_message "[e] Config (edit): Input blank. No file specified for editing."
echo -e ""
# Input validate (check for alphanum & "-_ "), convert spaces to underscores
elif [[ "$CONFIG_PROFILE_TO_EDIT" =~ [^a-zA-Z0-9_-] ]]
then
error_message "[e] Config (edit): Files are alphanum characters only. No spaces."
else
# Precautionary Convert Spaces to Understores
UNDERSCORED_PROFILE_NAME_INPUT=$(convert_spaces_to_underscores "$CONFIG_PROFILE_TO_EDIT")
# Check if in array of available files. If so, process
if [[ " ${CONFIG_PROFILES_ARRAY[*]} " =~ ${UNDERSCORED_PROFILE_NAME_INPUT} ]]
then
sudo nano "$CONFIG_DIRECTORY/config-$UNDERSCORED_PROFILE_NAME_INPUT.json"
TIMESTAMP=$(date +%Y-%m-%d" ("%H"h "%M"m "%S"s)")
sed -i "s/\/\/ Last modified.*/\/\/ Last modified: $TIMESTAMP/" "$CONFIG_DIRECTORY/config-$UNDERSCORED_PROFILE_NAME_INPUT.json"
confirmation_message "[e] Config (edit): Editing of \"$CONFIG_PROFILE_TO_EDIT\" completed."
echo -e ""
else
error_message "[e] Config (edit): No config \"$CONFIG_PROFILE_TO_EDIT\" to edit."
echo -e ""
fi
fi
# If no profiles exist
else
error_message "[e] Config (edit): No config profiles to edit. Create with \"new\"."
echo -e ""
fi

29
scripts/system/system-config_empty_trash

@ -0,0 +1,29 @@
#!/bin/bash
# SYSTEM: CONFIG Empty Trash (rm all deleted config profiles in trash can)
# Get number of files in folder
TRASH_FILES_COUNT=$(ls "$CONFIG_DIRECTORY/trash/" | wc -l)
# Delete Routine
if [[ "$TRASH_FILES_COUNT" == 0 ]]
then
echo -e "[x] Empty Trash (deleted config files): Trash empty / no files to delete."
echo -e ""
elif [[ "$TRASH_FILES_COUNT" == 1 ]]
then
sudo rm -r "$CONFIG_DIRECTORY/trash/"*
confirmation_message "[x] Empty Trash (deleted config files): Completed. $TRASH_FILES_COUNT file deleted."
echo -e ""
else
sudo rm -r "$CONFIG_DIRECTORY/trash/"*
confirmation_message "[x] Empty Trash (deleted config files): Completed. $TRASH_FILES_COUNT files deleted."
echo -e ""
fi

66
scripts/system/system-config_new

@ -0,0 +1,66 @@
#!/bin/bash
# SYSTEM: CONFIG New
# Edit System Configuration (.json) file
# Read input
read -p "New Profile Name?: " NEW_PROFILE_NAME
# Input validate (check if empty)
if [[ -z "$NEW_PROFILE_NAME" ]]
then
error_message "[n] Config (new): Input blank. No new file created."
echo -e ""
# Input validate (check for alphanum & "-_ "), convert spaces to underscores
elif [[ "$NEW_PROFILE_NAME" =~ [^a-zA-Z0-9_-] ]]
then
error_message "[n] Config (new): Filenames are alphanum only (no spaces). No file created."
echo -e ""
# Proceed with profile creation
else
# Check if name exists, and if so mark flag
PROFILE_EXISTS_FLAG="false"
for NEW_NAME_CHECK_LOOPED in "${CONFIG_PROFILES_ARRAY[@]}"
do
if [[ "${NEW_NAME_CHECK_LOOPED}" == ${NEW_PROFILE_NAME} ]]
then
PROFILE_EXISTS_FLAG="true"
fi
done
# Perform final action based on flag
if [[ $PROFILE_EXISTS_FLAG == "true" ]]
# If profile exists
then
error_message "[n] Config (new): config profile named \"$NEW_PROFILE_NAME\" already exist."
echo -e""
# If profile doesn't exist
else
sudo cp "$CONFIG_TEMPLATE_DIRECTORY/config-sample.json" "$CONFIG_DIRECTORY/config-$NEW_PROFILE_NAME.json"
TIMESTAMP=$(date +%Y-%m-%d" ("%H"h "%M"m "%S"s)")
sed -i "s/%%%%config_name%%%%/$NEW_PROFILE_NAME/" "$CONFIG_DIRECTORY/config-$NEW_PROFILE_NAME.json"
sed -i "s/%%%%creation_date%%%%/$TIMESTAMP/" "$CONFIG_DIRECTORY/config-$NEW_PROFILE_NAME.json"
sed -i "s/%%%%last_modified%%%%/$TIMESTAMP/" "$CONFIG_DIRECTORY/config-$NEW_PROFILE_NAME.json"
confirmation_message "[n] Config (new): Blank config profile \"$NEW_PROFILE_NAME\" created."
echo -e ""
fi
# Unset Flag
unset PROFILE_EXISTS_FLAG
fi

108
scripts/system/system-config_rename

@ -0,0 +1,108 @@
#!/bin/bash
# SYSTEM: CONFIG Rename
# If profiles exist
if (( ${#CONFIG_PROFILES_ARRAY[@]} ));
# Main Rename Routine
then
# Read input
read -p "Profile to Rename?: " PROFILE_TO_RENAME
# Input validate (check if empty)
if [[ -z "$PROFILE_TO_RENAME" ]]; then
error_message "[r] Config (rename): Input blank. No file identied for renaming."
echo -e ""
# Input validate (check for alphanum & "-_")
elif [[ "$PROFILE_TO_RENAME" =~ [^a-zA-Z0-9_-] ]]; then
error_message "[r] Config (rename): Filenames are alphanum only (no spaces). Try again."
echo -e ""
else
# Check if file exists
if [[ "${CONFIG_PROFILES_ARRAY[*]}" =~ ${PROFILE_TO_RENAME} ]]; then
# Read input
read -p "New name for file?: " PROFILE_NEW_NAME
# Input Validate (check if empty)
if [[ -z "$PROFILE_NEW_NAME" ]]; then
error_message "[r] Config (rename): New file name is blank."
echo -e ""
# Input validate (check for alphanum & "-_")
elif [[ "$PROFILE_NEW_NAME" =~ [^a-zA-Z0-9_-] ]]; then
error_message "[r] Config (rename): Filenames are alphanum only (no spaces). Try again."
echo -e ""
else
# Input validate (check for alphanum & "-_")
if [[ "${CONFIG_PROFILES_ARRAY[*]}" =~ ${PROFILE_NEW_NAME} ]]; then
error_message "[r] Config (rename): New name for file already exists."
echo -e ""
# Renaming routine
else
# Get name of current config
CURRENTLY_ACTIVE_CONFIG_FILE=$(<"$CONFIG_FILE_IDENTIFIER_PATH")
if [[ "$CURRENTLY_ACTIVE_CONFIG_FILE" == "$PROFILE_TO_RENAME" ]];
# If profile being renamed is the currently used profile
then
# Rename/mv file and change internal name
sudo mv "$CONFIG_DIRECTORY/config-$PROFILE_TO_RENAME.json" "$CONFIG_DIRECTORY/config-$PROFILE_NEW_NAME.json"
sed -i "s/\/\/ Config name.*/\/\/ Config name: $PROFILE_NEW_NAME/" "$CONFIG_DIRECTORY/config-$PROFILE_NEW_NAME.json"
# Delete config file identifier contents and push new name
truncate -s 0 "$CONFIG_FILE_IDENTIFIER_PATH"
echo "$PROFILE_NEW_NAME" >> $CONFIG_FILE_IDENTIFIER_PATH
# Confirm
confirmation_message "[r] Config (rename): Config file \"$PROFILE_TO_RENAME\" renamed to \"$PROFILE_NEW_NAME\"."
echo -e ""
# If profile being renamed is NOT the currently used profile
else
# Rename/mv file and change internal name
sudo mv "$CONFIG_DIRECTORY/config-$PROFILE_TO_RENAME.json" "$CONFIG_DIRECTORY/config-$PROFILE_NEW_NAME.json"
sed -i "s/\/\/ Config name.*/\/\/ Config name: $PROFILE_NEW_NAME/" "$CONFIG_DIRECTORY/config-$PROFILE_NEW_NAME.json"
# Confirm
confirmation_message "[r] Config (rename): Config file \"$PROFILE_TO_RENAME\" renamed to \"$PROFILE_NEW_NAME\"."
echo -e ""
fi
fi
fi
else
error_message "[r] Config (Rename): No file named \"$PROFILE_TO_RENAME\" to rename."
echo -e ""
fi
fi
# No profiles exist
else
error_message "[r] Config (rename): No config profiles to rename. Create with \"new\"."
echo -e ""
fi

46
scripts/system/system-config_use

@ -0,0 +1,46 @@
#!/bin/bash
# SYSTEM: CONFIG Use
# If profiles exist
if (( ${#CONFIG_PROFILES_ARRAY[@]} ));
# Main Use Routine
then
# Read input
read -p "Profile to use?: " PROFILE_NAME_TO_USE
# Check if empty
if [[ -z $PROFILE_NAME_TO_USE ]]; then
error_message "[u] Config (use): No filename entered."
echo -e ""
# Validate: If input not alphanum/underscore
elif [[ "$PROFILE_NAME_TO_USE" =~ [^a-zA-Z0-9_-] ]]; then
error_message "[u] Config (use): Filename must be alphanum or underscored."
echo -e ""
# Check if in array
elif [[ "${CONFIG_PROFILES_ARRAY[*]}" =~ ${PROFILE_NAME_TO_USE} ]]; then
# Empty active config declaration file, and copy new name to it
sudo truncate -s 0 $CONFIG_FILE_IDENTIFIER_PATH
echo "$PROFILE_NAME_TO_USE" >> $CONFIG_FILE_IDENTIFIER_PATH
confirmation_message "[u] Config (use): Now using profile \"$PROFILE_NAME_TO_USE\"."
echo -e ""