119 lines
3.3 KiB
Bash
119 lines
3.3 KiB
Bash
#!/bin/sh
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
# Script to initialize a FunQuail instance
|
|
#
|
|
# Copyright (c) 2026 Shin'ya Minazuki. All rights reserved.
|
|
#
|
|
# Redistribution and use in source or binary forms, with or without
|
|
# modification, are permitted provided that the following conditions
|
|
# are met:
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions, and the following disclaimer.
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions, and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution.
|
|
# 3. Neither the name of the authors nor the names of its contributors
|
|
# may be used to endorse or promote products derived from this software
|
|
# without specific prior written permission.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
# SUCH DAMAGE.
|
|
|
|
[ -f generated_config.env ] && rm -f generated_config.env
|
|
[ -f setup_db.psql ] && rm -f setup_db.psql
|
|
|
|
echo "What domain will your instance use?"
|
|
read HOSTNAME
|
|
export HOSTNAME
|
|
|
|
echo "What is your admin email address?"
|
|
read ADEMAIL
|
|
|
|
if [ -z $ADEMAIL ]; then
|
|
echo "Using noreply@$HOSTNAME"
|
|
ADEMAIL="noreply@$HOSTNAME"
|
|
fi
|
|
|
|
export ADEMAIL
|
|
|
|
echo "What is the hostname of your database?"
|
|
read DBHOST
|
|
|
|
if [ -z $DBHOST ]; then
|
|
echo "Unset, assume 'localhost'"
|
|
DBHOST="localhost"
|
|
fi
|
|
|
|
export DBHOST
|
|
|
|
echo "What is the name of your database?"
|
|
read DBNAME
|
|
|
|
if [ -z $DBNAME ]; then
|
|
echo "Unset, assume 'funquail'"
|
|
DBNAME="funquail"
|
|
fi
|
|
|
|
export DBNAME
|
|
|
|
echo "What is the user used to connect to your database?"
|
|
read DBUSER
|
|
|
|
if [ -z $DBUSER ]; then
|
|
echo "Unset, assume 'funquail'"
|
|
DBUSER="funquail"
|
|
fi
|
|
export DBUSER
|
|
|
|
echo "What is the password used to connect to your database?"
|
|
read DBPASS
|
|
|
|
if [ -z $DBPASS ]; then
|
|
DBPASS="$(openssl rand -hex 24)"
|
|
fi
|
|
|
|
export DBPASS
|
|
|
|
echo "What is your e-mail user?"
|
|
read EMAIL_USER
|
|
|
|
export EMAIL_USER
|
|
|
|
echo "What is your e-mail password?"
|
|
read EMAIL_PASS
|
|
|
|
export EMAIL_PASS
|
|
|
|
echo "What is your e-mail host?"
|
|
read EMAIL_HOST
|
|
|
|
export EMAIL_HOST
|
|
|
|
cat <<EOF >>generated_config.env
|
|
# --- Autogenerated by funquail-instance-gen
|
|
DATABASE_URL="postgres://$DBUSER:$DBPASS@$DBHOST/$DBNAME"
|
|
DEFAULT_FROM_EMAIL="$ADEMAIL"
|
|
EMAIL_CONFIG=smtp+tls://$EMAIL_USER:$EMAIL_PASS@$EMAIL_HOST:587
|
|
FUNQUAIL_HOSTNAME="$HOSTNAME"
|
|
FUNQUAIL_PROTOCOL="https"
|
|
EOF
|
|
|
|
cat <<EOF >>setup_db.psql
|
|
--- Autogenerated by funquail-instance-gen - do not edit!
|
|
CREATE USER $DBUSER WITH PASSWORD "$DBPASS";
|
|
CREATE DATABASE $DBNAME OWNER $DBUSER;
|
|
\c $DBNAME
|
|
CREATE EXTENSION IF NOT EXISTS 'unaccent';
|
|
CREATE EXTENSION IF NOT EXISTS 'citext';
|
|
EOF
|
|
|
|
echo "Done"
|