Skip to content
Snippets Groups Projects
Commit 7b5811e6 authored by Creak's avatar Creak
Browse files

Merge branch 'improve-script' into 'main'

Get the superuser information before calling createsuperuser

See merge request !2
parents cc0e25e5 be912431
No related branches found
No related tags found
1 merge request!2Get the superuser information before calling createsuperuser
......@@ -3,6 +3,8 @@
This repo is here to help installing Funkwhale using Docker. It follows the
[multi-container installation documentation][docs-multi-container].
## Usage
To set up your instance, clone this repo and enter the directory, then run the
script `./setup.sh`.
......@@ -13,4 +15,9 @@ pass them to it directly. See the help with this command:
./setup --help
```
## Developer
Prerequisites:
* docker-compose
[docs-multi-container]: https://docs.funkwhale.audio/installation/docker.html#docker-multi-container
......@@ -6,7 +6,11 @@ funkwhale_version_default=1.2.2
funkwhale_version="${FUNKWHALE_VERSION-$funkwhale_version_default}"
funkwhale_hostname=""
funkwhale_protocol="https"
funkwhale_username=""
funkwhale_userpasswd=""
funkwhale_useremail=""
# Show an error message and exit.
# Params:
# 1. message
function die
......@@ -15,11 +19,12 @@ function die
exit 1
}
# Get the value out of a "key=value" argument.
# Params:
# 1. option, in the format "key=value"
# 1. the option (in the format "key=value")
function get_not_empty_arg
{
value=${1#*=}
local value=${1#*=}
if [ -z $value ]; then
die "ERROR: \"${1%%=*}\" requires a non-empty option argument."
fi
......@@ -27,15 +32,20 @@ function get_not_empty_arg
echo $value
}
# Show the help text.
# No param.
function show_help
{
bin_name=$(basename $0)
local bin_name=$(basename $0)
cat << HELP
Usage: $bin_name [OPTION]...
-h, --host=HOST set the hostname (e.g. your.domain.io)
-e, --email=EMAIL set the superuser e-mail
--help display this help text and exit
--protocol=PROTOCOL set the protocol (default: https)
-h, --host=HOST set the hostname (e.g. your.domain.io)
-p, --password=PASSWORD set the superuser password
--protocol=PROTOCOL set the protocol (default: $funkwhale_protocol)
-u, --user=USER set the superuser name
It is possible to define a specific Funkwhale version by setting the
FUNKWHALE_VERSION environment variable before running the script (by
......@@ -60,13 +70,81 @@ Examples:
HELP
}
# Run an interactive shell to prompt for a value.
# Params:
# 1. the prompt text
# 2. the variable name
function prompt_value
{
local input=""
while [ -z "$input" ]; do
read -ep "$1: " input
if [ -z "$input" ]; then
echo "Text can't be empty."
fi
done
eval $2="$input"
}
# Run an interactive shell to prompt for a password.
# Params:
# 1. the prompt text
# 2. the variable name
function prompt_password
{
local passwd=""
local passwd_verif="invalid"
while [ "$passwd" != "$passwd_verif" ]; do
while [ -z "$passwd" ]; do
read -sep "$1: " passwd
# Newline to replace the one eaten by read.
echo
if [ -z "$passwd" ]; then
echo "Password can't be empty."
fi
done
read -sep "$1 (again): " passwd_verif
# Newline to replace the one eaten by read.
echo
if [ "$passwd" != "$passwd_verif" ]; then
echo "Passwords don't match."
passwd=""
passwd_verif="invalid"
fi
done
eval $2="$passwd"
}
# Parse the script options
while true; do
case $1 in
# Superuser e-mail
-e|--email)
if [ -n "$2" ]; then
funkwhale_useremail=$2
shift
else
die "ERROR: \"$1\" requires a non-empty option argument."
fi
;;
--email=*)
funkwhale_useremail=$(get_not_empty_arg $1)
;;
# Help
--help)
show_help
exit
;;
# Hostname
-h|--host)
if [ -n "$2" ]; then
funkwhale_hostname=$2
......@@ -78,6 +156,21 @@ while true; do
--host=*)
funkwhale_hostname=$(get_not_empty_arg $1)
;;
# Superuser password
-p|--password)
if [ -n "$2" ]; then
funkwhale_userpasswd=$2
shift
else
die "ERROR: \"$1\" requires a non-empty option argument."
fi
;;
--password=*)
funkwhale_userpasswd=$(get_not_empty_arg $1)
;;
# Protocol
--protocol)
if [ -n "$2" ]; then
funkwhale_protocol=$2
......@@ -89,6 +182,20 @@ while true; do
--protocol=*)
funkwhale_protocol=$(get_not_empty_arg $1)
;;
# Superuser name
-u|--user)
if [ -n "$2" ]; then
funkwhale_username=$2
shift
else
die "ERROR: \"$1\" requires a non-empty option argument."
fi
;;
--user=*)
funkwhale_username=$(get_not_empty_arg $1)
;;
-?*)
echo "ERROR: Unknown option: $1" >&2
show_help
......@@ -102,12 +209,24 @@ while true; do
done
# 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."
prompt_value "Please enter the Funkwhale hostname" funkwhale_hostname
fi
# Ensure the superuser name is defined
if [ -z $funkwhale_username ]; then
prompt_value "Please enter the superuser name" funkwhale_username
fi
# Ensure the superuser password is defined
if [ -z $funkwhale_userpasswd ]; then
prompt_password "Please enter the superuser password" funkwhale_userpasswd
fi
# Ensure the superuser password is defined
if [ -z $funkwhale_useremail ]; then
prompt_value "Please enter the superuser e-mail" funkwhale_useremail
fi
done
# Fetch the template files
echo -n "Fetching the template files... "
......@@ -122,6 +241,7 @@ popd > /dev/null
echo "done"
# Copy the template files to the "funkwhale" directory
echo
echo "Copy files to the \"funkwhale\" directory"
mkdir -p "funkwhale/nginx"
cd "funkwhale"
......@@ -151,12 +271,17 @@ echo
echo "Pull the Docker images"
docker-compose pull
echo
echo "Run initial DB migrations"
docker-compose up -d postgres
docker-compose run --rm api python manage.py migrate
echo "Create super user"
docker-compose run --rm api python manage.py createsuperuser
docker-compose run --rm \
-e DJANGO_SUPERUSER_USERNAME="$funkwhale_username" \
-e DJANGO_SUPERUSER_PASSWORD="$funkwhale_userpasswd" \
-e DJANGO_SUPERUSER_EMAIL="$funkwhale_useremail" \
api python manage.py createsuperuser --no-input
echo
echo "Run the Funkwhale instance"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment