From 8fa4566ff0ab74065418f4843e968f47169ba40e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 15 Oct 2016 18:35:04 +0100 Subject: [PATCH] Consolidate some interactive configuration --- src/freedombone-app-gogs | 55 ++------------------------- src/freedombone-app-hubzilla | 51 ++----------------------- src/freedombone-utils-interactive | 62 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 100 deletions(-) diff --git a/src/freedombone-app-gogs b/src/freedombone-app-gogs index cf47ba2d..ba62b8f9 100755 --- a/src/freedombone-app-gogs +++ b/src/freedombone-app-gogs @@ -53,60 +53,11 @@ gogs_variables=(ONION_ONLY function install_interactive_gogs { if [[ $ONION_ONLY != "no" ]]; then GIT_DOMAIN_NAME='git.local' + write_config_param "GIT_DOMAIN_NAME" "$GIT_DOMAIN_NAME" else - DEVELOPER_DETAILS_COMPLETE= - while [ ! $DEVELOPER_DETAILS_COMPLETE ] - do - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - - if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then - dialog --backtitle $"Freedombone Configuration" \ - --title $"Developer Configuration" \ - --form $"\nPlease enter your Git hosting site details.\nIf You don't need developer tools then just select Ok" 11 55 3 \ - $"Domain:" 1 1 "$(grep 'GIT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \ - $"Code:" 2 1 "$(grep 'GIT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 33 255 \ - 2> $data - else - dialog --backtitle $"Freedombone Configuration" \ - --title $"Developer Configuration" \ - --form $"\nPlease enter your Git hosting site details.\nIf You don't need developer tools then just select Ok" 11 55 2 \ - $"Domain:" 1 1 "$(grep 'GIT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \ - 2> $data - fi - sel=$? - case $sel in - 1) exit 1;; - 255) exit 1;; - esac - GIT_DOMAIN_NAME=$(cat $data | sed -n 1p) - if [ ${GIT_DOMAIN_NAME} ]; then - TEST_DOMAIN_NAME=$GIT_DOMAIN_NAME - validate_domain_name - if [[ ${TEST_DOMAIN_NAME} != ${GIT_DOMAIN_NAME} ]]; then - GIT_DOMAIN_NAME= - dialog --title $"Domain name validation" --msgbox "${TEST_DOMAIN_NAME}" 15 50 - else - if [[ ${DDNS_PROVIDER} == "default@freedns.afraid.org" ]]; then - GIT_CODE=$(cat $data | sed -n 2p) - validate_freedns_code "$GIT_CODE" - if [ ! ${VALID_CODE} ]; then - GIT_DOMAIN_NAME= - fi - fi - fi - else - DEVELOPER_DETAILS_COMPLETE="yes" - fi - if [ ${GIT_DOMAIN_NAME} ]; then - DEVELOPER_DETAILS_COMPLETE="yes" - fi - done - - # save the results in the config file - write_config_param "GIT_CODE" "$GIT_CODE" + function_check interactive_site_details + interactive_site_details git fi - write_config_param "GIT_DOMAIN_NAME" "$GIT_DOMAIN_NAME" APP_INSTALLED=1 } diff --git a/src/freedombone-app-hubzilla b/src/freedombone-app-hubzilla index 16b5ade7..dfd56cb1 100755 --- a/src/freedombone-app-hubzilla +++ b/src/freedombone-app-hubzilla @@ -140,54 +140,9 @@ function install_interactive_hubzilla { return fi - HUBZILLA_DETAILS_COMPLETE= - while [ ! $HUBZILLA_DETAILS_COMPLETE ] - do - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then - dialog --backtitle $"Freedombone Configuration" \ - --title $"Hubzilla Configuration" \ - --form $"\nPlease enter your Hubzilla details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 55 3 \ - $"Domain:" 1 1 "$(grep 'HUBZILLA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \ - $"Code:" 2 1 "$(grep 'HUBZILLA_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 33 255 \ - 2> $data - else - dialog --backtitle $"Freedombone Configuration" \ - --title $"Hubzilla Configuration" \ - --form $"\nPlease enter your Hubzilla details\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 11 55 3 \ - $"Domain:" 1 1 "$(grep 'HUBZILLA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \ - 2> $data - fi - sel=$? - case $sel in - 1) exit 1;; - 255) exit 1;; - esac - HUBZILLA_DOMAIN_NAME=$(cat $data | sed -n 1p) - if [ $HUBZILLA_DOMAIN_NAME ]; then - TEST_DOMAIN_NAME=$HUBZILLA_DOMAIN_NAME - validate_domain_name - if [[ $TEST_DOMAIN_NAME != $HUBZILLA_DOMAIN_NAME ]]; then - HUBZILLA_DOMAIN_NAME= - dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50 - else - if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then - HUBZILLA_CODE=$(cat $data | sed -n 2p) - validate_freedns_code "$HUBZILLA_CODE" - if [ ! $VALID_CODE ]; then - HUBZILLA_DOMAIN_NAME= - fi - fi - fi - fi - if [ $HUBZILLA_DOMAIN_NAME ]; then - HUBZILLA_DETAILS_COMPLETE="yes" - fi - done - # save the results in the config file - write_config_param "HUBZILLA_DOMAIN_NAME" "$HUBZILLA_DOMAIN_NAME" - write_config_param "HUBZILLA_CODE" "$HUBZILLA_CODE" + function_check interactive_site_details + interactive_site_details hubzilla + APP_INSTALLED=1 } diff --git a/src/freedombone-utils-interactive b/src/freedombone-utils-interactive index cf74a69a..c951398a 100755 --- a/src/freedombone-utils-interactive +++ b/src/freedombone-utils-interactive @@ -106,4 +106,66 @@ function interactive_configuration { fi } +function interactive_site_details { + site_name="$1" + site_name_upper=${site_name^^} + + SITE_BACKTITLE=$"Freedombone Configuration" + SITE_CONFIG_TITLE=$"${site_name} Configuration" + SITE_FORM_TEXT=$"\nPlease enter your ${site_name} details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" + SITE_DOMAIN_NAME= + SITE_CODE= + SITE_DETAILS_COMPLETE= + while [ ! $SITE_DETAILS_COMPLETE ] + do + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then + dialog --backtitle "$SITE_BACKTITLE" \ + --title "$SITE_CONFIG_TITLE" \ + --form "$SITE_FORM_TEXT" 14 55 3 \ + $"Domain:" 1 1 "$(grep '${site_name_upper}_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \ + $"Code:" 2 1 "$(grep '${site_name_upper}_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 33 255 \ + 2> $data + else + dialog --backtitle "$SITE_BACKTITLE" \ + --title "$SITE_CONFIG_TITLE" \ + --form "$SITE_FORM_TEXT" 11 55 3 \ + $"Domain:" 1 1 "$(grep '${site_name_upper}_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \ + 2> $data + fi + sel=$? + case $sel in + 1) exit 1;; + 255) exit 1;; + esac + SITE_DOMAIN_NAME=$(cat $data | sed -n 1p) + if [ $SITE_DOMAIN_NAME ]; then + TEST_DOMAIN_NAME=$SITE_DOMAIN_NAME + validate_domain_name + if [[ $TEST_DOMAIN_NAME != $SITE_DOMAIN_NAME ]]; then + SITE_DOMAIN_NAME= + dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50 + else + if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then + SITE_CODE=$(cat $data | sed -n 2p) + validate_freedns_code "$SITE_CODE" + if [ ! $VALID_CODE ]; then + SITE_DOMAIN_NAME= + fi + fi + fi + fi + if [ $SITE_DOMAIN_NAME ]; then + SITE_DETAILS_COMPLETE="yes" + fi + done + + # save the results in the config file + write_config_param "${site_name_upper}_DOMAIN_NAME" "$SITE_DOMAIN_NAME" + if [ $SITE_CODE ]; then + write_config_param "${site_name_upper}_CODE" "$SITE_CODE" + fi +} + # NOTE: deliberately no exit 0