freedombone/src/freedombone-utils-interactive

256 lines
9.4 KiB
Plaintext
Raw Normal View History

2016-07-03 17:13:34 +02:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2016-07-03 17:13:34 +02:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2016-07-03 17:13:34 +02:00
#
# Interactive install functions
#
# License
# =======
#
2018-02-21 20:32:13 +01:00
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
2016-07-03 17:13:34 +02:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
function interactive_configuration_remote_backups {
2016-10-08 20:32:04 +02:00
if [[ $SYSTEM_TYPE == "mesh"* ]]; then
return
fi
2018-02-26 14:50:40 +01:00
if [ ! -f "/usr/local/bin/${PROJECT_NAME}-remote" ]; then
if [ ! -f "/usr/bin/${PROJECT_NAME}-remote" ]; then
2016-10-08 20:32:04 +02:00
echo $"The command ${PROJECT_NAME}-remote was not found"
exit 87354
fi
fi
2018-02-26 14:50:40 +01:00
if ! "${PROJECT_NAME}-remote" -u "$MY_USERNAME" -l "$FRIENDS_SERVERS_LIST" -m "$MINIMUM_PASSWORD_LENGTH" -r yes; then
2016-10-08 20:32:04 +02:00
echo $'Command failed:'
echo ''
echo $" ${PROJECT_NAME}-remote -u $MY_USERNAME -l $FRIENDS_SERVERS_LIST -m $MINIMUM_PASSWORD_LENGTH -r yes"
echo ''
exit 65892
fi
2016-07-03 17:13:34 +02:00
}
function interactive_configuration {
2018-02-26 14:50:40 +01:00
if [ ! -f "/usr/local/bin/${PROJECT_NAME}-config" ]; then
if [ ! -f "/usr/bin/${PROJECT_NAME}-config" ]; then
2016-10-08 20:32:04 +02:00
echo $"The command ${PROJECT_NAME}-config was not found"
exit 63935
fi
fi
if [ -f /tmp/meshuserdevice ]; then
rm -f /tmp/meshuserdevice
fi
2016-07-03 17:13:34 +02:00
2018-02-26 14:50:40 +01:00
if [ "$SOCIALINSTANCE" ]; then
"${PROJECT_NAME}-config" \
-f "$CONFIGURATION_FILE" \
-w "$PROJECT_WEBSITE" \
-m "$MINIMUM_PASSWORD_LENGTH" \
2017-06-16 16:39:48 +02:00
--minimal "yes" \
2018-02-26 14:50:40 +01:00
--social "$SOCIALINSTANCE"
2017-06-16 16:39:48 +02:00
else
if [[ $ONION_ONLY == "no" ]]; then
if [[ $MINIMAL_INSTALL == "no" ]]; then
2018-02-26 14:50:40 +01:00
"${PROJECT_NAME}-config" \
-f "$CONFIGURATION_FILE" \
-w "$PROJECT_WEBSITE" \
-m "$MINIMUM_PASSWORD_LENGTH"
2017-06-16 16:39:48 +02:00
else
2018-02-26 14:50:40 +01:00
"${PROJECT_NAME}-config" \
-f "$CONFIGURATION_FILE" \
-w "$PROJECT_WEBSITE" \
-m "$MINIMUM_PASSWORD_LENGTH" \
2017-06-16 16:39:48 +02:00
--minimal "yes"
fi
2016-10-08 20:32:04 +02:00
else
2018-02-26 14:50:40 +01:00
"${PROJECT_NAME}-config" \
-f "$CONFIGURATION_FILE" \
-w "$PROJECT_WEBSITE" \
-m "$MINIMUM_PASSWORD_LENGTH" \
2017-06-16 16:39:48 +02:00
--onion "yes"
2016-10-08 20:32:04 +02:00
fi
fi
if [ -f /tmp/meshuserdevice ]; then
# mesh network user device installation
rm -f /tmp/meshuserdevice
exit 0
fi
2018-02-26 14:50:40 +01:00
# shellcheck disable=SC2181
2016-10-08 20:32:04 +02:00
if [ ! "$?" = "0" ]; then
echo $'Command failed:'
echo ''
echo $" ${PROJECT_NAME}-config -u $MY_USERNAME -f $CONFIGURATION_FILE -w $PROJECT_WEBSITE -b $PROJECT_BITMESSAGE -m $MINIMUM_PASSWORD_LENGTH --minimal [yes|no]"
echo ''
exit 73594
fi
2016-07-03 17:13:34 +02:00
2016-10-08 20:32:04 +02:00
if [[ $SYSTEM_TYPE == "mesh"* ]]; then
FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
2016-07-03 17:13:34 +02:00
2016-10-08 20:32:04 +02:00
dialog --title $"Encrypted backup to other servers" \
--backtitle $"${PROJECT_NAME} Configuration" \
--defaultno \
2018-02-26 14:50:40 +01:00
--yesno $"\\nDo you wish to configure some remote backup locations?" 7 60
2016-10-08 20:32:04 +02:00
sel=$?
case $sel in
0) interactive_configuration_remote_backups;;
esac
fi
2016-07-03 17:13:34 +02:00
}
function interactive_site_details {
site_name="$1"
site_name_upper=${site_name^^}
SITE_BACKTITLE=$"Freedombone Configuration"
2016-10-15 21:34:01 +02:00
SITE_CONFIG_TITLE=$"${site_name^} Configuration"
2018-02-26 14:50:40 +01:00
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
2018-02-26 14:50:40 +01:00
data=$(mktemp 2>/dev/null)
2018-05-12 18:48:20 +02:00
if [[ $DDNS_PROVIDER == "freedns" ]]; then
dialog --backtitle "$SITE_BACKTITLE" \
--title "$SITE_CONFIG_TITLE" \
--form "$SITE_FORM_TEXT" 14 55 3 \
2018-02-26 14:50:40 +01:00
$"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 \
2018-02-26 14:50:40 +01:00
$"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
2018-02-26 14:50:40 +01:00
1) rm -f "$data"
exit 1;;
255) rm -f "$data"
exit 1;;
esac
2018-02-26 14:50:40 +01:00
SITE_DOMAIN_NAME=$(sed -n 1p < "$data")
if [ "$SITE_DOMAIN_NAME" ]; then
TEST_DOMAIN_NAME=$SITE_DOMAIN_NAME
validate_domain_name
2018-02-26 14:50:40 +01:00
if [[ "$TEST_DOMAIN_NAME" != "$SITE_DOMAIN_NAME" ]]; then
SITE_DOMAIN_NAME=
dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
2018-05-12 18:48:20 +02:00
if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
2018-02-26 14:50:40 +01:00
SITE_CODE=$(sed -n 2p < "$data")
validate_freedns_code "$SITE_CODE"
2018-02-26 14:50:40 +01:00
if [ ! "$VALID_CODE" ]; then
SITE_DOMAIN_NAME=
fi
fi
fi
fi
2018-02-26 14:50:40 +01:00
if [ "$SITE_DOMAIN_NAME" ]; then
SITE_DETAILS_COMPLETE="yes"
fi
2018-02-26 14:50:40 +01:00
rm -f "$data"
done
# save the results in the config file
write_config_param "${site_name_upper}_DOMAIN_NAME" "$SITE_DOMAIN_NAME"
2016-10-17 11:20:55 +02:00
site_code_str="$SITE_CODE"
if [ ${#site_code_str} -gt 1 ]; then
write_config_param "${site_name_upper}_CODE" "${SITE_CODE}"
fi
}
2016-10-15 21:34:01 +02:00
function interactive_site_details_with_title {
site_name="${1}"
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:"
2016-10-15 23:01:59 +02:00
SITE_TITLE=
SITE_DOMAIN_NAME=
SITE_CODE=
2016-10-15 21:34:01 +02:00
SITE_DETAILS_COMPLETE=
while [ ! $SITE_DETAILS_COMPLETE ]
do
2018-02-26 14:50:40 +01:00
data=$(mktemp 2>/dev/null)
2018-05-12 18:48:20 +02:00
if [[ $DDNS_PROVIDER == *"freedns"* ]]; then
2016-10-15 21:34:01 +02:00
dialog --backtitle $"Freedombone Configuration" \
--title "$SITE_BACKTITLE" \
--form "$SITE_FORM_TEXT" 14 55 4 \
2018-02-26 14:50:40 +01:00
$"Domain:" 2 1 "$(grep "$SITE_DOMAIN_NAME" temp.cfg | awk -F '=' '{print $2}')" 2 16 33 40 \
$"Code:" 3 1 "$(grep "$SITE_CODE" temp.cfg | awk -F '=' '{print $2}')" 3 16 33 255 \
2> "$data"
2016-10-15 21:34:01 +02:00
else
dialog --backtitle "$SITE_BACKTITLE" \
--title "$SITE_CONFIG_TITLE" \
--form "$SITE_FORM_TEXT" 11 55 3 \
2018-02-26 14:50:40 +01:00
$"Title:" 1 1 "$(grep "$SITE_TITLE" temp.cfg | awk -F '=' '{print $2}')" 1 16 33 40 \
$"Domain:" 2 1 "$(grep "$SITE_DOMAIN_NAME" temp.cfg | awk -F '=' '{print $2}')" 2 16 33 40 \
2> "$data"
2016-10-15 21:34:01 +02:00
fi
sel=$?
case $sel in
2018-02-26 14:50:40 +01:00
1) rm -f "$data"
exit 1;;
255) rm -f "$data"
exit 1;;
2016-10-15 21:34:01 +02:00
esac
2018-02-26 14:50:40 +01:00
SITE_TITLE=$(sed -n 1p < "$data")
SITE_DOMAIN_NAME=$(sed -n 2p < "$data")
2016-10-15 23:01:59 +02:00
site_domain_name_str="$SITE_DOMAIN_NAME"
if [ ${#site_domain_name_str} -gt 1 ]; then
TEST_DOMAIN_NAME="$SITE_DOMAIN_NAME"
2016-10-15 21:34:01 +02:00
validate_domain_name
2016-10-15 23:01:59 +02:00
if [[ "$TEST_DOMAIN_NAME" != "${SITE_DOMAIN_NAME}" ]]; then
SITE_DOMAIN_NAME=
2016-10-15 21:34:01 +02:00
dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
else
2018-05-12 18:48:20 +02:00
if [[ "$DDNS_PROVIDER" == *"freedns"* ]]; then
2018-02-26 14:50:40 +01:00
SITE_CODE=$(sed -n 3p < "$data")
2016-10-15 23:01:59 +02:00
validate_freedns_code "${SITE_CODE}"
2018-02-26 14:50:40 +01:00
if [ ! "$VALID_CODE" ]; then
2016-10-15 23:01:59 +02:00
SITE_DOMAIN_NAME=
2016-10-15 21:34:01 +02:00
fi
fi
fi
fi
2016-10-15 23:01:59 +02:00
site_title_str="$SITE_TITLE"
2016-10-15 22:23:56 +02:00
if [ ${#site_title_str} -gt 0 ]; then
2016-10-15 23:01:59 +02:00
if [ ${SITE_DOMAIN_NAME} ]; then
2016-10-15 21:34:01 +02:00
SITE_DETAILS_COMPLETE="yes"
fi
fi
2018-02-26 14:50:40 +01:00
rm -f "$data"
2016-10-15 21:34:01 +02:00
done
# save the results in the config file
2016-10-17 11:20:55 +02:00
write_config_param "$2" "${SITE_TITLE}"
write_config_param "$3" "${SITE_DOMAIN_NAME}"
2016-10-15 23:01:59 +02:00
site_code_str="$SITE_CODE"
if [ ${#site_code_str} -gt 1 ]; then
2016-10-17 11:20:55 +02:00
write_config_param "$4" "${SITE_CODE}"
2016-10-15 21:34:01 +02:00
fi
}
2016-07-03 17:13:34 +02:00
# NOTE: deliberately no exit 0