2020-05-06 12:57:32 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-10-20 23:23:51 +01: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-10-20 02:49:49 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
domain_root=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--clear \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Domain root:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 23:23:51 +01:00
|
|
|
check_input $domain_root
|
2020-10-20 02:49:49 +01:00
|
|
|
|
2020-10-20 23:23:51 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
sub_domain=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Subdomain (can be empty):" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
signed=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--menu "Use certificate signed by Let's Encrypt?" 12 51 2 \
|
|
|
|
"Y" "" \
|
|
|
|
"n" "" \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 02:49:49 +01:00
|
|
|
|
|
|
|
[ "${signed}" = "${signed#[Yy]}" ]
|
|
|
|
signed=$?
|
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
|
2020-10-20 02:49:49 +01:00
|
|
|
if [ $signed -ne 0 ]; then
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
email=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Email:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 23:23:51 +01:00
|
|
|
check_input $email
|
2020-10-20 02:49:49 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$sub_domain" ]
|
|
|
|
then
|
|
|
|
domain="${domain_root}"
|
|
|
|
else
|
|
|
|
domain="${sub_domain}.${domain_root}"
|
|
|
|
fi
|
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
root="$(git rev-parse --show-toplevel)"
|
|
|
|
mkdir -p root/docker/bootstrap
|
2020-10-20 02:49:49 +01:00
|
|
|
|
|
|
|
cat > ./docker/bootstrap/bootstrap.env <<EOF
|
|
|
|
#!/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 13:37:06 +01:00
|
|
|
git_dir=$PWD
|
|
|
|
while [ ! -d .git ]; do
|
|
|
|
git_dir=$(dirname "${git_dir}")
|
|
|
|
done
|
|
|
|
|
|
|
|
cd "${git_dir}" || exit
|
|
|
|
|
2020-10-07 13:29:17 +01:00
|
|
|
if [ ! -f ./docker/bootstrap/bootstrap.env ]; then
|
|
|
|
printf "bootstrap.env missing! Please run the bootstrap_certificates script.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-06-05 16:10:20 +01:00
|
|
|
. ./docker/bootstrap/bootstrap.env
|
2020-05-06 12:57:32 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
dbms=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--menu "Select DBMS:" 12 51 2 \
|
|
|
|
"postgres" "" \
|
|
|
|
"mariadb" "" \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
db=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Social database name:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-05-06 12:57:32 +01:00
|
|
|
|
2020-10-20 02:49:49 +01:00
|
|
|
if [ "${dbms}" = 'mariadb' ]
|
|
|
|
then
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
user=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Database user:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 23:23:51 +01:00
|
|
|
check_input $user
|
2020-10-20 02:49:49 +01:00
|
|
|
fi
|
2020-05-16 13:37:06 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
password=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Database password:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 23:23:51 +01:00
|
|
|
check_input $password
|
2020-10-20 02:49:49 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
sitename=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Sitename:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 23:23:51 +01:00
|
|
|
check_input $sitename
|
2020-10-20 02:49:49 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
admin_nick=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Admin nickname:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 23:23:51 +01:00
|
|
|
check_input $admin_nick
|
2020-10-20 02:49:49 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
admin_password=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Admin password:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 23:23:51 +01:00
|
|
|
check_input $admin_password
|
2020-10-20 02:49:49 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
profile=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--menu "Site profile:" 12 51 4 \
|
|
|
|
"public" "" \
|
|
|
|
"private" "" \
|
|
|
|
"community" "" \
|
|
|
|
"single_user" "" \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
|
|
|
|
|
|
|
exec 3>&1
|
|
|
|
mailer_dsn=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "Mailer dsn:" 12 51 \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
2020-10-20 23:23:51 +01:00
|
|
|
check_input $mailer_dsn
|
2020-05-16 13:37:06 +01:00
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
mkdir -p root/docker/db
|
2020-05-06 12:57:32 +01:00
|
|
|
|
2020-05-16 13:37:06 +01:00
|
|
|
if [ "${dbms}" = 'mariadb' ]; then
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
db_root_password=$(dialog \
|
|
|
|
--title "Configure" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--inputbox "DB root password" 12 51 \
|
|
|
|
2>&1 1>&3)
|
|
|
|
check_retval $?
|
|
|
|
exec 3>&-
|
|
|
|
check_input $db_root_password
|
|
|
|
|
|
|
|
cat > ./docker/db/db.env <<EOF
|
2020-05-06 12:57:32 +01:00
|
|
|
DBMS=${dbms}
|
|
|
|
MYSQL_ROOT_PASSWORD=${db_root_password}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
database_url="DATABASE_URL=mysql://${user}:${password}@db:3306/${db}"
|
|
|
|
|
|
|
|
else
|
|
|
|
cat > ./docker/db/db.env <<EOF
|
|
|
|
DBMS=${dbms}
|
|
|
|
POSTGRES_USER=postgres
|
2020-05-16 13:37:06 +01:00
|
|
|
POSTGRES_PASSWORD=${password}
|
2020-05-06 12:57:32 +01:00
|
|
|
EOF
|
|
|
|
|
2020-05-16 13:37:06 +01:00
|
|
|
user='postgres'
|
2020-05-06 12:57:32 +01:00
|
|
|
database_url="DATABASE_URL=postgresql://${user}:${password}@db:5432/${db}"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2020-07-30 23:40:37 +01:00
|
|
|
echo "${database_url}" >> .env.local
|
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
mkdir -p root/docker/social
|
2020-05-06 12:57:32 +01:00
|
|
|
|
|
|
|
cat > ./docker/social/social.env <<EOF
|
2020-07-10 15:01:49 +01: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-30 23:40:37 +01:00
|
|
|
MAILER_DSN="${mailer_dsn}"
|
2020-05-06 12:57:32 +01:00
|
|
|
EOF
|
2020-10-20 02:49:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
##docker-compose
|
|
|
|
|
|
|
|
echo "version: '3.3'" > docker-compose.yaml
|
|
|
|
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&1
|
|
|
|
choice=$(dialog \
|
|
|
|
--title "Services" \
|
|
|
|
--clear \
|
|
|
|
--ok-label "Ok" \
|
|
|
|
--cancel-label "Exit" \
|
|
|
|
--checklist "Services to include in docker-compose:" 12 44 6 \
|
|
|
|
1 "nginx" on \
|
|
|
|
2 "certbot" on \
|
|
|
|
3 "php" on \
|
|
|
|
4 "db" on \
|
|
|
|
5 "redis" on \
|
|
|
|
2>&1 1>&3)
|
2020-10-20 23:23:51 +01:00
|
|
|
check_retval $?
|
2020-11-23 18:51:17 +00:00
|
|
|
exec 3>&-
|
|
|
|
|
2020-10-20 02:49:49 +01:00
|
|
|
|
|
|
|
echo "\nservices:" >> docker-compose.yaml
|
|
|
|
|
|
|
|
case $choice in *"1"*)
|
|
|
|
echo " nginx:
|
|
|
|
image: nginx:alpine
|
|
|
|
depends_on:
|
|
|
|
- php
|
|
|
|
restart: always
|
|
|
|
tty: false
|
|
|
|
ports:
|
|
|
|
- 80:80
|
|
|
|
- 443:443
|
|
|
|
volumes:
|
|
|
|
# Nginx
|
|
|
|
- ./docker/nginx/nginx.conf:/var/nginx/social.conf
|
|
|
|
- ./docker/nginx/domain.sh:/var/nginx/domain.sh
|
|
|
|
# Certbot
|
|
|
|
- ./docker/certbot/www:/var/www/certbot
|
|
|
|
- ./docker/certbot/.files:/etc/letsencrypt
|
|
|
|
# Social
|
|
|
|
- ./public:/var/www/social/public
|
|
|
|
env_file:
|
|
|
|
- ./docker/bootstrap/bootstrap.env
|
|
|
|
- ./docker/db/db.env
|
|
|
|
command: /bin/sh -c '/var/nginx/domain.sh;
|
|
|
|
while :; do
|
|
|
|
sleep 6h & wait \$\${!};
|
|
|
|
nginx -s reload;
|
|
|
|
done &
|
|
|
|
nginx -g \"daemon off;\"'\n" >> docker-compose.yaml;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $choice in *"2"*)
|
|
|
|
echo " certbot:
|
|
|
|
image: certbot/certbot
|
|
|
|
depends_on:
|
|
|
|
- nginx
|
|
|
|
# Check for certificate renewal every 12h as
|
|
|
|
# recomnended by Let's Encryot
|
|
|
|
entrypoint: /bin/sh -c 'trap exit TERM;
|
|
|
|
while :; do
|
|
|
|
certbot renew > /dev/null;
|
|
|
|
sleep 12h & wait \$\${!};
|
|
|
|
done'
|
|
|
|
volumes:
|
|
|
|
- ./docker/certbot/www:/var/www/certbot
|
|
|
|
- ./docker/certbot/.files:/etc/letsencrypt\n" >> docker-compose.yaml;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $choice in *"3"*)
|
|
|
|
echo " php:
|
|
|
|
build: docker/php
|
|
|
|
depends_on:
|
|
|
|
- db
|
|
|
|
restart: always
|
|
|
|
tty: true
|
|
|
|
ports:
|
|
|
|
- 9000:9000
|
|
|
|
volumes:
|
|
|
|
# Entrypoint
|
|
|
|
- ./docker/php/entrypoint.sh:/entrypoint.sh
|
|
|
|
- ./docker/db/wait_for_db.sh:/wait_for_db.sh
|
|
|
|
- ./docker/social/install.sh:/var/entrypoint.d/social_install.sh
|
|
|
|
# Main files
|
|
|
|
- .:/var/www/social
|
|
|
|
env_file:
|
|
|
|
- ./docker/social/social.env
|
|
|
|
- ./docker/db/db.env
|
|
|
|
command: /entrypoint.sh\n" >> docker-compose.yaml;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $choice in *"4"*)
|
|
|
|
echo " db:
|
|
|
|
image: postgres:alpine
|
|
|
|
restart: always
|
|
|
|
tty: false
|
|
|
|
ports:
|
|
|
|
- 5432:5432
|
|
|
|
environment:
|
|
|
|
- PGDATA=/var/lib/postgres/data
|
|
|
|
env_file:
|
|
|
|
- ./docker/db/db.env
|
|
|
|
volumes:
|
|
|
|
- database:/var/lib/postgres/data\n" >> docker-compose.yaml;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $choice in *"5"*)
|
|
|
|
echo " redis:
|
|
|
|
image: redis:alpine
|
|
|
|
restart: always
|
|
|
|
tty: false
|
|
|
|
ports:
|
|
|
|
- 6379:6379" >> docker-compose.yaml;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "\nvolumes:\n database:" >> docker-compose.yaml
|
|
|
|
clear
|
|
|
|
|
|
|
|
|