[TOOLS][DOCKER] Change dialog method to command substitution and redirection and add way of finding git's root

This commit is contained in:
margarida 2020-11-23 18:51:17 +00:00 committed by Hugo Sales
parent a8d211cdbf
commit 6cb6eeb8a3
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

227
bin/configure vendored
View File

@ -16,38 +16,59 @@ check_input(){
fi fi
} }
DIALOG=${DIALOG=dialog}
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15
$DIALOG --title "Configure" \ exec 3>&1
--inputbox "Domain root:" 12 51 2> $tempfile domain_root=$(dialog \
--title "Configure" \
--ok-label "Ok" \
--clear \
--cancel-label "Exit" \
--inputbox "Domain root:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
domain_root=`cat $tempfile` exec 3>&-
check_input $domain_root check_input $domain_root
$DIALOG --title "Configure" \ exec 3>&1
--inputbox "Subdomain (can be empty):" 12 51 2> $tempfile sub_domain=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Subdomain (can be empty):" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
sub_domain=`cat $tempfile` exec 3>&-
exec 3>&1
$DIALOG --title "Configure" --clear \ signed=$(dialog \
--menu "Use certificate signed by Let's Encrypt?" 12 51 2 \ --title "Configure" \
"Y" "" \ --clear \
"n" "" 2> $tempfile --ok-label "Ok" \
--cancel-label "Exit" \
--menu "Use certificate signed by Let's Encrypt?" 12 51 2 \
"Y" "" \
"n" "" \
2>&1 1>&3)
check_retval $? check_retval $?
signed=`cat $tempfile` exec 3>&-
[ "${signed}" = "${signed#[Yy]}" ] [ "${signed}" = "${signed#[Yy]}" ]
signed=$? signed=$?
if [ $signed -ne 0 ]; then if [ $signed -ne 0 ]; then
$DIALOG --title "Configure" \ exec 3>&1
--inputbox "Email:" 12 51 2> $tempfile email=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Email:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
email=`cat $tempfile` exec 3>&-
check_input $email check_input $email
fi fi
@ -58,7 +79,8 @@ else
domain="${sub_domain}.${domain_root}" domain="${sub_domain}.${domain_root}"
fi fi
mkdir -p ./docker/bootstrap root="$(git rev-parse --show-toplevel)"
mkdir -p root/docker/bootstrap
cat > ./docker/bootstrap/bootstrap.env <<EOF cat > ./docker/bootstrap/bootstrap.env <<EOF
#!/bin/sh #!/bin/sh
@ -86,75 +108,137 @@ fi
. ./docker/bootstrap/bootstrap.env . ./docker/bootstrap/bootstrap.env
$DIALOG --clear --title "Configure" \ exec 3>&1
--menu "Select DBMS:" 12 51 2 \ dbms=$(dialog \
"postgres" "" \ --title "Configure" \
"mariadb" "" 2> $tempfile --clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--menu "Select DBMS:" 12 51 2 \
"postgres" "" \
"mariadb" "" \
2>&1 1>&3)
check_retval $? check_retval $?
dbms=`cat $tempfile` exec 3>&-
$DIALOG --title "Configure" --clear \ exec 3>&1
--inputbox "Social database name:" 12 51 2> $tempfile db=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Social database name:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
db=`cat $tempfile` exec 3>&-
if [ "${dbms}" = 'mariadb' ] if [ "${dbms}" = 'mariadb' ]
then then
$DIALOG --title "Configure" --clear \ exec 3>&1
--inputbox "Database user:" 12 51 2> $tempfile user=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Database user:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
user=`cat $tempfile` exec 3>&-
check_input $user check_input $user
fi fi
$DIALOG --title "Configure" --clear \
--inputbox "Database password:" 12 51 2> $tempfile exec 3>&1
password=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Database password:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
password=`cat $tempfile` exec 3>&-
check_input $password check_input $password
$DIALOG --title "Configure" --clear \ exec 3>&1
--inputbox "Sitename:" 12 51 2> $tempfile sitename=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Sitename:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
sitename=`cat $tempfile` exec 3>&-
check_input $sitename check_input $sitename
$DIALOG --title "Configure" --clear \ exec 3>&1
--inputbox "Admin nickname:" 12 51 2> $tempfile admin_nick=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Admin nickname:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
admin_nick=`cat $tempfile` exec 3>&-
check_input $admin_nick check_input $admin_nick
$DIALOG --title "Configure" --clear \ exec 3>&1
--inputbox "Admin password:" 12 51 2> $tempfile admin_password=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Admin password:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
admin_password=`cat $tempfile` exec 3>&-
check_input $admin_password check_input $admin_password
$DIALOG --clear --title "Configure" \ exec 3>&1
--menu "Site profile:" 12 51 4 \ profile=$(dialog \
"public" "" \ --title "Configure" \
"private" "" \ --clear \
"community" "" \ --ok-label "Ok" \
"single_user" "" 2> $tempfile --cancel-label "Exit" \
--menu "Site profile:" 12 51 4 \
"public" "" \
"private" "" \
"community" "" \
"single_user" "" \
2>&1 1>&3)
check_retval $? check_retval $?
profile=`cat $tempfile` exec 3>&-
$DIALOG --title "Configure" --clear \ exec 3>&1
--inputbox "Mailer dsn:" 12 51 2> $tempfile mailer_dsn=$(dialog \
--title "Configure" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "Mailer dsn:" 12 51 \
2>&1 1>&3)
check_retval $? check_retval $?
mailer_dsn=`cat $tempfile` exec 3>&-
check_input $mailer_dsn check_input $mailer_dsn
mkdir -p ./docker/db mkdir -p root/docker/db
if [ "${dbms}" = 'mariadb' ]; then if [ "${dbms}" = 'mariadb' ]; then
$DIALOG --title "Configure" --clear \ exec 3>&1
--inputbox "DB root password" 12 51 2> $tempfile db_root_password=$(dialog \
check_retval $? --title "Configure" \
db_root_password=`cat $tempfile` --clear \
check_input $db_root_password --ok-label "Ok" \
cat > ./docker/db/db.env <<EOF --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
DBMS=${dbms} DBMS=${dbms}
MYSQL_ROOT_PASSWORD=${db_root_password} MYSQL_ROOT_PASSWORD=${db_root_password}
EOF EOF
@ -175,7 +259,7 @@ fi
echo "${database_url}" >> .env.local echo "${database_url}" >> .env.local
mkdir -p ./docker/social mkdir -p root/docker/social
cat > ./docker/social/social.env <<EOF cat > ./docker/social/social.env <<EOF
SOCIAL_DBMS="${dbms}" SOCIAL_DBMS="${dbms}"
@ -196,15 +280,22 @@ EOF
echo "version: '3.3'" > docker-compose.yaml echo "version: '3.3'" > docker-compose.yaml
$DIALOG --title "Services" --clear \ exec 3>&1
--checklist "Services to include in docker-compose:" 12 44 6 \ choice=$(dialog \
1 "nginx" on \ --title "Services" \
2 "certbot" on \ --clear \
3 "php" on \ --ok-label "Ok" \
4 "db" on \ --cancel-label "Exit" \
5 "redis" on 2> $tempfile --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)
check_retval $? check_retval $?
choice=`cat $tempfile` exec 3>&-
echo "\nservices:" >> docker-compose.yaml echo "\nservices:" >> docker-compose.yaml