2020-05-06 20:57:32 +09:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
ROOT="$(git rev-parse --show-toplevel)"
|
|
|
|
HEIGHT=13
|
|
|
|
WIDTH=51
|
|
|
|
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval(){
|
|
|
|
case $1 in
|
|
|
|
1|255)
|
|
|
|
echo "Stopped"
|
|
|
|
exit;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
check_input(){
|
|
|
|
if [ "$1" = "" ]
|
|
|
|
then
|
|
|
|
echo "Can't be empty"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
domain_root=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
2020-11-24 05:17:31 +09:00
|
|
|
--ok-label "Ok" \
|
2020-11-24 03:51:17 +09:00
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Domain root:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-21 07:23:51 +09:00
|
|
|
check_input $domain_root
|
2020-10-20 10:49:49 +09:00
|
|
|
|
2020-10-21 07:23:51 +09:00
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
sub_domain=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Subdomain (can be empty):" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
signed=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--menu "Use certificate signed by Let's Encrypt?" $HEIGHT $WIDTH 2 \
|
2020-11-24 03:51:17 +09:00
|
|
|
"Y" "" \
|
|
|
|
"n" "" \
|
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-20 10:49:49 +09:00
|
|
|
|
|
|
|
[ "${signed}" = "${signed#[Yy]}" ]
|
|
|
|
signed=$?
|
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
|
2020-10-20 10:49:49 +09:00
|
|
|
if [ $signed -ne 0 ]; then
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
email=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Email:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-21 07:23:51 +09:00
|
|
|
check_input $email
|
2020-10-20 10:49:49 +09:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$sub_domain" ]
|
|
|
|
then
|
|
|
|
domain="${domain_root}"
|
|
|
|
else
|
|
|
|
domain="${sub_domain}.${domain_root}"
|
|
|
|
fi
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
mkdir -p $ROOT/docker/bootstrap
|
|
|
|
|
2020-10-20 10:49:49 +09:00
|
|
|
|
2020-11-29 09:41:07 +09:00
|
|
|
cat > $ROOT/docker/bootstrap/bootstrap.env <<EOF
|
2020-10-20 10:49:49 +09:00
|
|
|
#!/bin/sh
|
|
|
|
email=${email}
|
|
|
|
domain=${domain}
|
|
|
|
domain_root=${domain_root}
|
|
|
|
signed=${signed}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod +x ./docker/bootstrap/bootstrap.env
|
|
|
|
|
|
|
|
docker-compose -f docker/bootstrap/bootstrap.yaml up
|
|
|
|
|
2020-05-16 21:37:06 +09:00
|
|
|
git_dir=$PWD
|
|
|
|
while [ ! -d .git ]; do
|
|
|
|
git_dir=$(dirname "${git_dir}")
|
|
|
|
done
|
|
|
|
|
|
|
|
cd "${git_dir}" || exit
|
|
|
|
|
2020-10-07 21:29:17 +09:00
|
|
|
if [ ! -f ./docker/bootstrap/bootstrap.env ]; then
|
|
|
|
printf "bootstrap.env missing! Please run the bootstrap_certificates script.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-06-06 00:10:20 +09:00
|
|
|
. ./docker/bootstrap/bootstrap.env
|
2020-05-06 20:57:32 +09:00
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
dbms=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--menu "Select DBMS:" $HEIGHT $WIDTH 2 \
|
2020-11-24 03:51:17 +09:00
|
|
|
"postgres" "" \
|
|
|
|
"mariadb" "" \
|
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
db=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "GNU social database name:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-05-06 20:57:32 +09:00
|
|
|
|
2020-10-20 10:49:49 +09:00
|
|
|
if [ "${dbms}" = 'mariadb' ]
|
|
|
|
then
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
user=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Database user:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-21 07:23:51 +09:00
|
|
|
check_input $user
|
2020-10-20 10:49:49 +09:00
|
|
|
fi
|
2020-05-16 21:37:06 +09:00
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
password=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Database password:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-21 07:23:51 +09:00
|
|
|
check_input $password
|
2020-10-20 10:49:49 +09:00
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
sitename=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Sitename:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-21 07:23:51 +09:00
|
|
|
check_input $sitename
|
2020-10-20 10:49:49 +09:00
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
admin_nick=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Admin nickname:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-21 07:23:51 +09:00
|
|
|
check_input $admin_nick
|
2020-10-20 10:49:49 +09:00
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
admin_password=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Admin password:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-21 07:23:51 +09:00
|
|
|
check_input $admin_password
|
2020-10-20 10:49:49 +09:00
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
profile=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--menu "Site profile:" $HEIGHT $WIDTH 4 \
|
2020-11-24 03:51:17 +09:00
|
|
|
"public" "" \
|
|
|
|
"private" "" \
|
|
|
|
"community" "" \
|
|
|
|
"single_user" "" \
|
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
mailer_dsn=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "Mailer dsn:" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
2020-10-21 07:23:51 +09:00
|
|
|
check_input $mailer_dsn
|
2020-05-16 21:37:06 +09:00
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
mkdir -p $ROOT/docker/db
|
2020-05-06 20:57:32 +09:00
|
|
|
|
2020-05-16 21:37:06 +09:00
|
|
|
if [ "${dbms}" = 'mariadb' ]; then
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
|
|
|
db_root_password=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--inputbox "DB root password" $HEIGHT $WIDTH \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
|
|
|
check_retval $?
|
|
|
|
exec 3>&-
|
|
|
|
check_input $db_root_password
|
|
|
|
|
2020-11-29 09:41:07 +09:00
|
|
|
cat > $ROOT/docker/db/db.env <<EOF
|
2020-05-06 20:57:32 +09:00
|
|
|
DBMS=${dbms}
|
|
|
|
MYSQL_ROOT_PASSWORD=${db_root_password}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
database_url="DATABASE_URL=mysql://${user}:${password}@db:3306/${db}"
|
|
|
|
|
|
|
|
else
|
2020-11-29 09:41:07 +09:00
|
|
|
cat > $ROOT/docker/db/db.env <<EOF
|
2020-05-06 20:57:32 +09:00
|
|
|
DBMS=${dbms}
|
|
|
|
POSTGRES_USER=postgres
|
2020-05-16 21:37:06 +09:00
|
|
|
POSTGRES_PASSWORD=${password}
|
2020-05-06 20:57:32 +09:00
|
|
|
EOF
|
|
|
|
|
2020-05-16 21:37:06 +09:00
|
|
|
user='postgres'
|
2020-05-06 20:57:32 +09:00
|
|
|
database_url="DATABASE_URL=postgresql://${user}:${password}@db:5432/${db}"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2020-07-31 07:40:37 +09:00
|
|
|
echo "${database_url}" >> .env.local
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
mkdir -p $ROOT/docker/social
|
2020-05-06 20:57:32 +09:00
|
|
|
|
2020-11-29 09:41:07 +09:00
|
|
|
cat > $ROOT/docker/social/social.env <<EOF
|
2020-07-10 23:01:49 +09:00
|
|
|
SOCIAL_DBMS="${dbms}"
|
|
|
|
SOCIAL_DB="${db}"
|
|
|
|
SOCIAL_USER="${user}"
|
|
|
|
SOCIAL_PASSWORD="${password}"
|
|
|
|
SOCIAL_DOMAIN="${domain}"
|
|
|
|
SOCIAL_SITENAME="${sitename}"
|
|
|
|
SOCIAL_ADMIN_NICK="${admin_nick}"
|
|
|
|
SOCIAL_ADMIN_PASSWORD="${admin_password}"
|
|
|
|
SOCIAL_ADMIN_EMAIL="${email}"
|
|
|
|
SOCIAL_SITE_PROFILE="${profile}"
|
2020-07-31 07:40:37 +09:00
|
|
|
MAILER_DSN="${mailer_dsn}"
|
2020-05-06 20:57:32 +09:00
|
|
|
EOF
|
2020-10-20 10:49:49 +09:00
|
|
|
|
|
|
|
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&1
|
2020-11-24 05:17:31 +09:00
|
|
|
docker_compose=$(dialog \
|
2020-11-24 03:51:17 +09:00
|
|
|
--title "Services" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
2020-11-24 05:17:31 +09:00
|
|
|
--checklist "Services to include in docker-compose:" $HEIGHT $WIDTH 6 \
|
|
|
|
"nginx" "" on \
|
|
|
|
"certbot" "" on \
|
|
|
|
"php" "" on \
|
|
|
|
"db" "" on \
|
|
|
|
"redis" "" on \
|
|
|
|
"mail" "" on \
|
2020-11-24 03:51:17 +09:00
|
|
|
2>&1 1>&3)
|
2020-10-21 07:23:51 +09:00
|
|
|
check_retval $?
|
2020-11-24 03:51:17 +09:00
|
|
|
exec 3>&-
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
echo "version: '3.3'" > docker-compose.yaml
|
2020-10-20 10:49:49 +09:00
|
|
|
echo "\nservices:" >> docker-compose.yaml
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
case $docker_compose in *"nginx"*)
|
|
|
|
$ROOT/docker/social/nginx
|
2020-10-20 10:49:49 +09:00
|
|
|
esac
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
case $docker_compose in *"certbot"*)
|
|
|
|
$ROOT/docker/social/certbot
|
2020-10-20 10:49:49 +09:00
|
|
|
esac
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
case $docker_compose in *"php"*)
|
|
|
|
$ROOT/docker/social/php
|
2020-10-20 10:49:49 +09:00
|
|
|
esac
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
case $docker_compose in *"db"*)
|
|
|
|
$ROOT/docker/social/db
|
2020-10-20 10:49:49 +09:00
|
|
|
esac
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
case $docker_compose in *"redis"*)
|
|
|
|
$ROOT/docker/social/redis
|
2020-10-20 10:49:49 +09:00
|
|
|
esac
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
case $docker_compose in *"mail"*)
|
|
|
|
$ROOT/docker/social/mail
|
2020-11-29 09:41:07 +09:00
|
|
|
exec 3>&1
|
|
|
|
mail_domain_root=$(dialog \
|
|
|
|
--title "Configure Mail" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "E-mail domain root:" $HEIGHT $WIDTH \
|
|
|
|
2>&1 1>&3)
|
|
|
|
check_retval $?
|
|
|
|
exec 3>&-
|
|
|
|
check_input $mail_domain_root
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
mail_subdomain=$(dialog \
|
|
|
|
--title "Configure Mail" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "E-mail subdomain (can be empty):" $HEIGHT $WIDTH \
|
|
|
|
2>&1 1>&3)
|
|
|
|
check_retval $?
|
|
|
|
exec 3>&-
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
mail_user=$(dialog \
|
|
|
|
--title "Configure Mail" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "E-mail user (name without @domain): " $HEIGHT $WIDTH \
|
|
|
|
2>&1 1>&3)
|
|
|
|
check_retval $?
|
|
|
|
exec 3>&-
|
|
|
|
check_input $mail_user
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
mail_pass=$(dialog \
|
|
|
|
--title "Configure Mail" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "E-mail user password: " $HEIGHT $WIDTH \
|
|
|
|
2>&1 1>&3)
|
|
|
|
check_retval $?
|
|
|
|
exec 3>&-
|
|
|
|
check_input $mail_pass
|
|
|
|
|
|
|
|
mkdir -p $ROOT/docker/mail
|
|
|
|
|
|
|
|
cat > $ROOT/docker/mail/mail.env <<EOF
|
|
|
|
MAIL_DOMAIN_ROOT="${mail_domain_root}"
|
|
|
|
MAIL_SUBDOMAIN="${mail_subdomain}"
|
|
|
|
MAIL_USER="${mail_user}"
|
|
|
|
MAIL_PASSWORD="${mail_pass}"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
$ROOT/docker/mail/setup.sh
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
esac
|
|
|
|
|
|
|
|
echo "volumes:\n database:" >> docker-compose.yaml
|
2020-11-29 09:41:07 +09:00
|
|
|
|
2020-10-20 10:49:49 +09:00
|
|
|
|
|
|
|
|
2020-11-24 05:17:31 +09:00
|
|
|
|
|
|
|
|