123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- #!/bin/sh
- ROOT="$(git rev-parse --show-toplevel)"
- HEIGHT=13
- WIDTH=51
- check_retval(){
- case $1 in
- 1|255)
- echo "Stopped"
- exit;;
- esac
- }
- check_input(){
- if [ "$1" = "" ]
- then
- echo "Can't be empty"
- exit
- fi
- }
- exec 3>&1
- domain_root=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Domain root:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $domain_root
- exec 3>&1
- sub_domain=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Subdomain (can be empty):" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- exec 3>&1
- signed=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --menu "Use certificate signed by Let's Encrypt?" $HEIGHT $WIDTH 2 \
- "Y" "" \
- "n" "" \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- [ "${signed}" = "${signed#[Yy]}" ]
- signed=$?
- if [ $signed -ne 0 ]; then
- exec 3>&1
- email=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Email:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $email
- fi
- if [ -z "$sub_domain" ]
- then
- domain="${domain_root}"
- else
- domain="${sub_domain}.${domain_root}"
- fi
- mkdir -p $ROOT/docker/bootstrap
- cat > $ROOT/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
- git_dir=$PWD
- while [ ! -d .git ]; do
- git_dir=$(dirname "${git_dir}")
- done
- cd "${git_dir}" || exit
- if [ ! -f ./docker/bootstrap/bootstrap.env ]; then
- printf "bootstrap.env missing! Please run the bootstrap_certificates script.\n"
- exit 1
- fi
- . ./docker/bootstrap/bootstrap.env
- exec 3>&1
- dbms=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --menu "Select DBMS:" $HEIGHT $WIDTH 2 \
- "postgres" "" \
- "mariadb" "" \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- exec 3>&1
- db=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "GNU social database name:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- if [ "${dbms}" = 'mariadb' ]
- then
- exec 3>&1
- user=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Database user:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $user
- fi
- exec 3>&1
- password=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Database password:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $password
- exec 3>&1
- sitename=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Sitename:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $sitename
- exec 3>&1
- admin_nick=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Admin nickname:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $admin_nick
- exec 3>&1
- admin_password=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Admin password:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $admin_password
- exec 3>&1
- profile=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --menu "Site profile:" $HEIGHT $WIDTH 4 \
- "public" "" \
- "private" "" \
- "community" "" \
- "single_user" "" \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- exec 3>&1
- mailer_dsn=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "Mailer dsn:" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $mailer_dsn
- mkdir -p $ROOT/docker/db
- if [ "${dbms}" = 'mariadb' ]; then
- exec 3>&1
- db_root_password=$(dialog \
- --title "Configure" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --inputbox "DB root password" $HEIGHT $WIDTH \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- check_input $db_root_password
- cat > $ROOT/docker/db/db.env <<EOF
- DBMS=${dbms}
- MYSQL_ROOT_PASSWORD=${db_root_password}
- EOF
- database_url="DATABASE_URL=mysql://${user}:${password}@db:3306/${db}"
- else
- cat > $ROOT/docker/db/db.env <<EOF
- DBMS=${dbms}
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=${password}
- EOF
- user='postgres'
- database_url="DATABASE_URL=postgresql://${user}:${password}@db:5432/${db}"
- fi
- echo "${database_url}" >> .env.local
- mkdir -p $ROOT/docker/social
- cat > $ROOT/docker/social/social.env <<EOF
- 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}"
- MAILER_DSN="${mailer_dsn}"
- EOF
- exec 3>&1
- docker_compose=$(dialog \
- --title "Services" \
- --clear \
- --ok-label "Ok" \
- --cancel-label "Exit" \
- --checklist "Services to include in docker-compose:" $HEIGHT $WIDTH 6 \
- "nginx" "" on \
- "certbot" "" on \
- "php" "" on \
- "db" "" on \
- "redis" "" on \
- "mail" "" on \
- 2>&1 1>&3)
- check_retval $?
- exec 3>&-
- echo "version: '3.3'" > docker-compose.yaml
- echo "\nservices:" >> docker-compose.yaml
- case $docker_compose in *"nginx"*)
- $ROOT/docker/social/nginx
- esac
- case $docker_compose in *"certbot"*)
- $ROOT/docker/social/certbot
- esac
- case $docker_compose in *"php"*)
- $ROOT/docker/social/php
- esac
- case $docker_compose in *"db"*)
- $ROOT/docker/social/db
- esac
- case $docker_compose in *"redis"*)
- $ROOT/docker/social/redis
- esac
- case $docker_compose in *"mail"*)
- $ROOT/docker/social/mail
- 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
- esac
- echo "volumes:\n database:" >> docker-compose.yaml
|