Skip to content

Commit

Permalink
Improvements to install script
Browse files Browse the repository at this point in the history
 - Suppport relative music paths
 - Remember that we chose a proxy instead of relying on a profile
 - Use heredocs to reduce echo spam
 - Add defaults to inputs where that seems suitable
 - Add input validation
 - Read only one character for y/n prompt
 - Use fail-early to stop if we reach a bad state
 - Make the script able to run regardless of working directory
  • Loading branch information
za419 committed Jul 31, 2024
1 parent eca4f37 commit deaaad8
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 47 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nginx-compose-section.yml
14 changes: 1 addition & 13 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,7 @@ services:
internal_services:
external_services:

nginx:
profiles: ["nginx"]
image: nginx:latest
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf
container_name: nginx
restart: on-failure
ports:
- 80:80
depends_on:
- cadence
networks:
external_services:
NGINX_CONFIG_SECTION

networks:
external_services:
Expand Down
142 changes: 108 additions & 34 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,130 @@
#!/bin/bash

echo "***************************************************************"
echo "NOTE: If you need help determining configuration values to use,"
echo "installation documentation is available on GitHub:"
echo "https://github.com/kenellorando/cadence/wiki/Installation"
echo "***************************************************************"
echo ""
echo "[1/5] Absolute Path to Music"
echo "Set an absolute path to a directory containing audio files (e.g. mp3, flac)"
echo "to be played on the radio. The target is not recursively searched."
# Exit immediately upon error
set -eo pipefail

if [ $# -gt 0 ]
then
echo "$(basename $0): No parameters allowed, $# given."
exit 1
fi

cat <<END
"***************************************************************"
NOTE: If you need help determining configuration values to use,
installation documentation is available on GitHub:
https://github.com/kenellorando/cadence/wiki/Installation
***************************************************************
[1/5] Path to Music Directory
Set a path to a directory containing audio files (e.g. mp3, flac) to be played
on the radio. The target will be recursively searched.
END
read -p " Music path: " CADENCE_PATH
echo ""
echo "[2/5] Stream Host Address"
echo "Set the stream host address. This may be a DNS name, public IP, or private IP."
echo "Use localhost:8000 if your Cadence instance is meant for local use only."
while [ ! -d "$CADENCE_PATH" ]
do
echo "Music path must point to a directory that exists and is readable."
read -p " Music path: " CADENCE_PATH
done
# We do need to use absolute paths here - Make sure they end up that way.
# realpath -s is used here instead of readlink -f to retain symlinks - Else,
# we'd automatically go to the destination and use that, even if the user
# changed the symlink and restarted Cadence!
# ... Despite this, symlinks inside CADENCE_PATH probably won't work, since
# they don't get mounted inside our containers. Not a lot we can do about that.
CADENCE_PATH=$(realpath -s "$CADENCE_PATH")

echo

cat <<END
[2/5] Stream Host Address
Set the stream host address. This may be a DNS name, public IP, or private IP.
Use localhost:8000 if your Cadence instance is meant for local use only.
Default: localhost:8000
END
read -p " Stream address: " CADENCE_STREAM_HOST
echo ""
echo "[3/5] Rate Limiter Timeout"
echo "Set a rate limit timeout in integer seconds. This prevents the same listener"
echo "from requesting songs within the configured timeframe. Set to 0 to disable."
read -p " Rate limit: " CADENCE_RATE
echo ""
echo "[4/5] Radio Service Password"
echo "Set a secure, unique service password. Input is hidden."
if [ -z "$CADENCE_STREAM_HOST" ]
then
echo "Streaming to localhost:8000."
CADENCE_STREAM_HOST='localhost:8000'
fi


echo

cat <<END
[3/5] Rate Limiter Timeout
Set a rate limit timeout in integer seconds. This prevents the same listener
from requesting songs within the configured timeframe. Set to 0 to disable.
END
read -p " Rate limit (0): " CADENCE_RATE
while ! [[ "$CADENCE_RATE" =~ ^\d*$ ]]
do
echo "Rate limit must be an integer!"
read -p " Rate limit (0): " CADENCE_RATE
done
[ -z "$CADENCE_RATE" ] && CADENCE_RATE=0


echo

cat <<END
[4/5] Radio Service Password
Set a secure, unique service password. Input is hidden.
END
read -s -p " Password: " CADENCE_PASS
echo ""
echo ""
echo "[5/5] Enable Reverse Proxy?"
echo "Do you want to enable a reverse proxy? Skip if you are broadcasting locally only"
echo "or have your own reverse proxy configured. Skip if you do not know what this means."
read -p " [y/N]: " ENABLE_REVERSE_PROXY
while [ -z "$CADENCE_PASS" ]
do
echo
echo "Password cannot be empty!"
read -s -p " Password: " CADENCE_PASS
done

echo
echo

cat <<END
[5/5] Enable Reverse Proxy?
Do you want to enable a reverse proxy? Skip if you are broadcasting locally only
or have your own reverse proxy configured. Skip if you do not know what this means.
END
ENABLE_REVERSE_PROXY="UNSET"
while ! [[ "$ENABLE_REVERSE_PROXY" =~ ^[yYnN]$ ]] && [ -n "$ENABLE_REVERSE_PROXY" ]
do
read -n1 -p " [y/N]: " ENABLE_REVERSE_PROXY
echo
done

if [[ "$ENABLE_REVERSE_PROXY" =~ ^([yY])$ ]]
then
echo "Please provide the domain name you will use for Cadence UI."
read -p " Web UI Domain: " CADENCE_WEB_HOST
while [ -z "$CADENCE_WEB_HOST" ]
do
echo "Web UI Domain cannot be empty!"
read -p " Web UI Domain: " CADENCE_WEB_HOST
done
else
echo "No reverse proxy will be configured."
fi

SCRIPT_DIR="$(dirname $(readlink -f $0))"
cd $SCRIPT_DIR

cp ./config/cadence.env.example ./config/cadence.env
cp ./config/icecast.xml.example ./config/icecast.xml
cp ./config/liquidsoap.liq.example ./config/liquidsoap.liq
cp ./config/nginx.conf.example ./config/nginx.conf
cp ./docker-compose.yml.example ./docker-compose.yml

if [[ "$ENABLE_REVERSE_PROXY" =~ ^([yY])$ ]]
then
awk -i inplace -v "c=$(cat ./nginx-compose-section.yml)" \
'{gsub(/NGINX_CONFIG_SECTION/,c)}1' docker-compose.yml
else
sed -i 's|NGINX_CONFIG_SECTION||g' ./docker-compose.yml
fi

sed -i 's|CADENCE_PASS_EXAMPLE|'"$CADENCE_PASS"'|g' ./config/cadence.env
sed -i 's|CADENCE_PASS_EXAMPLE|'"$CADENCE_PASS"'|g' ./config/icecast.xml
sed -i 's|CADENCE_PASS_EXAMPLE|'"$CADENCE_PASS"'|g' ./config/liquidsoap.liq
Expand All @@ -61,10 +141,4 @@ echo "Configuration completed."

docker compose down
docker compose pull

if [[ "$ENABLE_REVERSE_PROXY" =~ ^([yY])$ ]]
then
docker compose --profile nginx up
else
docker compose up
fi
docker compose up
13 changes: 13 additions & 0 deletions nginx-compose-section.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# NOTE: Leading indentation in this file must be retained. Do not apply Prettier!
nginx:
image: nginx:latest
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf
container_name: nginx
restart: on-failure
ports:
- 80:80
depends_on:
- cadence
networks:
external_services:

0 comments on commit deaaad8

Please sign in to comment.