Commit 872c50f3 authored by Creak's avatar Creak
Browse files

Improve the setup script

* Improve the documentation
* Add handling short and long options
* New options:
  - `--help` shows the help
  - `-h|--host=HOST` sets the hostname
  - `--protocol=PROTOCOL` sets the protocol
* All the configured files are now in the "funkwhale" directory
* The final message points to the reverse-proxy configuration
parent a5d44bef
......@@ -3,9 +3,14 @@
This repo is here to help installing Funkwhale using Docker. It follows the
[multi-container installation documentation][docs-multi-container].
To set up your instance, run this script:
To set up your instance, clone this repo and enter the directory, then run the
script `./setup.sh`.
This script will ask for the needed information, but it is also possible to
pass them to it directly. See the help with this command:
```sh
setup.sh
./setup --help
```
[docs-multi-container]: https://docs.funkwhale.audio/installation/docker.html#docker-multi-container
#!/bin/sh
set -e
FUNKWHALE_VERSION="1.2.2"
FUNKWHALE_HOSTNAME=""
funkwhale_version_default=1.2.2
while getopts "h:" "options"; do
case $options in
h)
FUNKWHALE_HOSTNAME=$OPTARG
;;
funkwhale_version="${FUNKWHALE_VERSION-$funkwhale_version_default}"
funkwhale_hostname=""
funkwhale_protocol="https"
function die
{
echo "$1" >&2
exit 1
}
function show_help
{
bin_name=$(basename $0)
cat << HELP
Usage: $bin_name [OPTION]...
-h, --host=HOST set the hostname (e.g. your.domain.io)
--help display this help text and exit
-p, --protocol=PROTOCOL set the protocol (default: https)
It is possible to define a specific Funkwhale version by setting the
FUNKWHALE_VERSION environment variable before running the script (by
default it will be $funkwhale_version_default)
?)
During the process, the script will ask for the missing information.
Examples:
# Interactively asks for information then run the containers
$bin_name
# Set the hostname to 'localhost' and the protocol to 'http' then run
# the containers. This command line is helpful to test an instance locally.
$bin_name --host=localhost --protocol=http
# Set a specific Funkwhale version.
FUNKWHALE_VERSION=1.2.0 $bin_name
HELP
}
# Parse the script options
while true; do
case $1 in
--help)
show_help
exit
;;
-h|--host)
if [ "$2" ]; then
funkwhale_hostname=$2
shift
else
die "ERROR: \"$1\" requires a non-empty option argument."
fi
;;
--host=?*)
funkwhale_hostname=${1#*=}
;;
--host=)
die "ERROR: \"$1\" requires a non-empty option argument."
;;
-p|--protocol)
if [ "$2" ]; then
funkwhale_protocol=$2
shift
else
die "ERROR: \"$1\" requires a non-empty option argument."
fi
;;
--protocol=?*)
funkwhale_protocol=${1#*=}
;;
--protocol=)
die "ERROR: \"$1\" requires a non-empty option argument."
;;
-?*)
echo "ERROR: Unknown option: $1" >&2
show_help
exit 1
;;
*)
break
esac
shift
done
while [ -z $FUNKWHALE_HOSTNAME ]; do
read -ep "Please enter your Funkwhale hostname: " FUNKWHALE_HOSTNAME
# Ensure the hostname is defined
while [ -z $funkwhale_hostname ]; do
read -ep "Please enter your Funkwhale hostname: " funkwhale_hostname
if [ -z $funkwhale_hostname ]; then
echo "Hostname can't be null."
fi
done
echo -n "Fetching templates... "
mkdir -p templates/nginx
curl -sLo templates/nginx/funkwhale.template "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/${FUNKWHALE_VERSION}/deploy/docker.nginx.template"
curl -sLo templates/nginx/funkwhale_proxy.conf "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/${FUNKWHALE_VERSION}/deploy/docker.funkwhale_proxy.conf"
curl -sLo templates/docker-compose.yml "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/${FUNKWHALE_VERSION}/deploy/docker-compose.yml"
curl -sLo templates/env.prod.sample "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/${FUNKWHALE_VERSION}/deploy/env.prod.sample"
# Fetch the template files
echo -n "Fetching the template files... "
raw_src="https://dev.funkwhale.audio/funkwhale/funkwhale/raw/${funkwhale_version}/deploy"
mkdir -p "templates/nginx"
pushd "templates" > /dev/null
curl -sLo "nginx/funkwhale.template" "${raw_src}/docker.nginx.template"
curl -sLo "nginx/funkwhale_proxy.conf" "${raw_src}/docker.funkwhale_proxy.conf"
curl -sLo "docker-compose.yml" "${raw_src}/docker-compose.yml"
curl -sLo "env.prod.sample" "${raw_src}/env.prod.sample"
popd > /dev/null
echo "done"
# Create .env and reduce permissions on the .env file since it contains
# sensitive data.
echo "Copy files"
mkdir -p nginx
cp templates/nginx/funkwhale.template nginx/
cp templates/nginx/funkwhale_proxy.conf nginx/
cp templates/docker-compose.yml .
cp templates/env.prod.sample .env
chmod 600 .env
# Copy the template files to the "instance" directory
echo "Copy files to the \"instance\" directory"
mkdir -p "instance/nginx"
cd "instance"
cp "../templates/nginx/funkwhale.template" "nginx/"
cp "../templates/nginx/funkwhale_proxy.conf" "nginx/"
cp "../templates/docker-compose.yml" "./"
cp "../templates/env.prod.sample" ".env"
# reduce permissions on the .env file since it contains sensitive data
chmod 600 ".env"
echo "Set Funkwhale version: $FUNKWHALE_VERSION"
sed -i "s/FUNKWHALE_VERSION=latest/FUNKWHALE_VERSION=$FUNKWHALE_VERSION/" .env
# Set up the instance files
echo "Set Funkwhale version: $funkwhale_version"
sed -i "s/FUNKWHALE_VERSION=latest/FUNKWHALE_VERSION=$funkwhale_version/" .env
echo "Set Funkwhale hostname: $FUNKWHALE_HOSTNAME"
sed -i "s/FUNKWHALE_HOSTNAME=yourdomain.funkwhale/FUNKWHALE_HOSTNAME=$FUNKWHALE_HOSTNAME/" .env
echo "Set Funkwhale hostname: $funkwhale_hostname"
sed -i "s/FUNKWHALE_HOSTNAME=yourdomain.funkwhale/FUNKWHALE_HOSTNAME=$funkwhale_hostname/" .env
echo "Set Funkwhale protocol: $funkwhale_protocol"
sed -i "s/FUNKWHALE_PROTOCOL=https/FUNKWHALE_PROTOCOL=$funkwhale_protocol/" .env
echo "Set Django secret key: xxxxxxxx"
DJANGO_SECRET_KEY=$(openssl rand -base64 45)
sed -i "s#DJANGO_SECRET_KEY=#DJANGO_SECRET_KEY=$DJANGO_SECRET_KEY#" .env
django_secret_key=$(openssl rand -base64 45)
sed -i "s#DJANGO_SECRET_KEY=#DJANGO_SECRET_KEY=$django_secret_key#" .env
echo
echo "Pull the Docker images"
docker-compose pull
......@@ -57,8 +146,15 @@ docker-compose run --rm api python manage.py migrate
echo "Create super user"
docker-compose run --rm api python manage.py createsuperuser
echo
echo "Run the Funkwhale instance"
docker-compose up -d
source "$PWD/.env"
echo "The instance is accessible locally at http://localhost:${FUNKWHALE_API_PORT}"
cat << EOF
Next step is to setup the reverse-proxy:
https://docs.funkwhale.audio/installation/index.html#reverse-proxy-setup
And then this instance of Funkwhale ${FUNKWHALE_VERSION} will be accessible
externally at: ${FUNKWHALE_PROTOCOL}://${FUNKWHALE_HOSTNAME}
EOF
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment