Consolidation of configuration variables

This commit is contained in:
Bob Mottram 2016-10-09 11:45:41 +01:00
parent 3750bd9215
commit 811a39a924
2 changed files with 104 additions and 139 deletions

View File

@ -172,7 +172,7 @@ function choose_email_address {
esac
done
fi
save_configuration_file
save_configuration_values
}
function choose_default_domain_name {
@ -227,7 +227,7 @@ function choose_default_domain_name {
fi
done
fi
save_configuration_file
save_configuration_values
}
function choose_static_ip {
@ -271,7 +271,7 @@ function choose_static_ip {
esac
LOCAL_NETWORK_STATIC_IP_ADDRESS=$(cat $data | sed -n 1p)
ROUTER_IP_ADDRESS=$(cat $data | sed -n 2p)
save_configuration_file
save_configuration_values
fi
fi
}
@ -319,7 +319,7 @@ function choose_dynamic_dns {
14) DDNS_PROVIDER="default@changeip.com";;
255) exit 1;;
esac
save_configuration_file
save_configuration_values
valid_ddns_username=
while [ ! $valid_ddns_username ]
@ -343,7 +343,7 @@ function choose_dynamic_dns {
255) exit 1;;
esac
done
save_configuration_file
save_configuration_values
valid_ddns_password=
while [ ! $valid_ddns_password ]
@ -373,7 +373,7 @@ function choose_dynamic_dns {
DDNS_PASSWORD=""
fi
done
save_configuration_file
save_configuration_values
fi
}
@ -455,7 +455,7 @@ function choose_dns {
;;
255) exit 1;;
esac
save_configuration_file
save_configuration_values
else
# as defaults for a minimal install process these settings are debatable
NAMESERVER1='85.214.73.63'
@ -575,7 +575,7 @@ function choose_debian_repo {
49) DEBIAN_REPO='ftp.us.debian.org';;
255) exit 1;;
esac
save_configuration_file
save_configuration_values
else
DEBIAN_REPO='ftp.de.debian.org'
fi
@ -605,7 +605,7 @@ function choose_rng {
else
HWRNG_TYPE="beaglebone"
fi
save_configuration_file
save_configuration_values
fi
}
@ -631,7 +631,7 @@ function choose_social_key_management {
0) ENABLE_SOCIAL_KEY_MANAGEMENT="yes";;
255) exit 1;;
esac
save_configuration_file
save_configuration_values
else
# enable for the minimal case
ENABLE_SOCIAL_KEY_MANAGEMENT="yes"
@ -659,7 +659,7 @@ function choose_beaglebone_options {
if [[ $INSTALLING_ON_BBB == "yes" ]]; then
USB_DRIVE=/dev/sda1
fi
save_configuration_file
save_configuration_values
fi
}
@ -742,7 +742,7 @@ function choose_username {
echo $"The directory /home/$MY_USERNAME does not exist"
exit 6437
fi
save_configuration_file
save_configuration_values
}
function choose_full_name {
@ -768,7 +768,7 @@ function choose_full_name {
255) exit 1;;
esac
done
save_configuration_file
save_configuration_values
}
function choose_system_variant {
@ -795,7 +795,7 @@ function choose_system_variant {
27 40 20 $varslist)
variant_choice=$((variant_choice - 1))
export SYSTEM_TYPE=${variants_list[$variant_choice]}
save_configuration_file
save_configuration_values
write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
}
@ -854,53 +854,6 @@ do
shift
done
function save_configuration_file {
if [ ! $CONFIGURATION_FILE ]; then
CONFIGURATION_FILE='freedombone.cfg'
fi
save_variables=(MY_USERNAME
DEFAULT_DOMAIN_NAME
DEFAULT_DOMAIN_CODE
SYSTEM_TYPE
INSTALLING_ON_BBB
USB_DRIVE
DDNS_PROVIDER
DDNS_USERNAME
DDNS_PASSWORD
DEFAULT_LANGUAGE
MY_NAME
MY_EMAIL_ADDRESS
LOCAL_NETWORK_STATIC_IP_ADDRESS
ROUTER_IP_ADDRESS
ENABLE_CJDNS
ENABLE_BATMAN
ENABLE_BABEL
DEBIAN_REPO
NAMESERVER1
NAMESERVER2
HWRNG_TYPE
ENABLE_SOCIAL_KEY_MANAGEMENT
WIFI_SSID
WIFI_INTERFACE
WIFI_TYPE
WIFI_PASSPHRASE
WIFI_HOTSPOT
BATMAN_CELLID
WIFI_CHANNEL
DH_KEYLENGTH
ONION_ONLY
FRIENDS_MIRRORS_SERVER
FRIENDS_MIRRORS_SSH_PORT
FRIENDS_MIRRORS_PASSWORD
MY_MIRRORS_PASSWORD)
for v in "${save_variables[@]}"
do
write_config_param "$v" "${!v}"
done
}
# test a domain name to see if it's valid
function validate_domain_name {
# count the number of dots in the domain name
@ -1169,7 +1122,7 @@ function set_main_repo {
dialog --title $"Main Repository" \
--msgbox $"Main repository set to $FRIENDS_MIRRORS_SERVER" 6 60
fi
save_configuration_file
save_configuration_values
}
function interactive_select_language {
@ -1320,7 +1273,7 @@ function interactive_select_language {
67) DEFAULT_LANGUAGE='uk_UA.UTF-8';;
68) DEFAULT_LANGUAGE='vi_VN.UTF-8';;
esac
save_configuration_file
save_configuration_values
update-locale LANG=${DEFAULT_LANGUAGE}
update-locale LANGUAGE=${DEFAULT_LANGUAGE}
@ -1415,4 +1368,5 @@ fi
read_configuration_values
interactive_config
show_result
exit 0

View File

@ -28,58 +28,7 @@
# 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 read_config_param {
param_name="$1"
if [ ${#param_name} -gt 0 ]; then
if [ $CONFIGURATION_FILE ]; then
if [ -f $CONFIGURATION_FILE ]; then
if grep -q "${param_name}=" $CONFIGURATION_FILE; then
export ${param_name}=$(cat $CONFIGURATION_FILE | grep "${param_name}=" | head -n 1 | awk -F '=' '{print $2}')
fi
fi
fi
fi
}
function write_config_param {
param_name="$1"
param_value="$2"
if [ ${#param_name} -gt 0 ]; then
if [ ${#param_value} -gt 0 ]; then
if [ $CONFIGURATION_FILE ]; then
if [ -f $CONFIGURATION_FILE ]; then
if grep -q "${param_name}=" $CONFIGURATION_FILE; then
sed -i "s|${param_name}=.*|${param_name}=${param_value}|g" $CONFIGURATION_FILE
else
echo "${param_name}=${param_value}" >> $CONFIGURATION_FILE
fi
else
echo "${param_name}=${param_value}" > $CONFIGURATION_FILE
fi
fi
fi
fi
}
function read_configuration_values {
# if not installing on a Beaglebone then use sdb as the USB drive by default
if [ ! $INSTALLING_ON_BBB ]; then
if [[ $USB_DRIVE == /dev/sda1 ]]; then
USB_DRIVE=/dev/sdb1
fi
fi
if [ -f $CONFIGURATION_FILE ]; then
read_repo_servers
# Ensure that a copy of the config exists for upgrade purposes
if [[ $CONFIGURATION_FILE != "/root/${PROJECT_NAME}.cfg" ]]; then
cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg
fi
read_config_variables=(FRIENDS_MIRRORS_SERVER
configuration_variables=(FRIENDS_MIRRORS_SERVER
FRIENDS_MIRRORS_SSH_PORT
FRIENDS_MIRRORS_PASSWORD
MY_MIRRORS_PASSWORD
@ -154,7 +103,69 @@ function read_configuration_values {
ENABLE_CJDNS
PUBLIC_MAILING_LIST)
for v in "${read_config_variables[@]}"
function read_config_param {
param_name="$1"
if [ ${#param_name} -gt 0 ]; then
if [ $CONFIGURATION_FILE ]; then
if [ -f $CONFIGURATION_FILE ]; then
if grep -q "${param_name}=" $CONFIGURATION_FILE; then
export ${param_name}=$(cat $CONFIGURATION_FILE | grep "${param_name}=" | head -n 1 | awk -F '=' '{print $2}')
fi
fi
fi
fi
}
function write_config_param {
param_name="$1"
param_value="$2"
if [ ${#param_name} -gt 0 ]; then
if [ ${#param_value} -gt 0 ]; then
if [ $CONFIGURATION_FILE ]; then
if [ -f $CONFIGURATION_FILE ]; then
if grep -q "${param_name}=" $CONFIGURATION_FILE; then
sed -i "s|${param_name}=.*|${param_name}=${param_value}|g" $CONFIGURATION_FILE
else
echo "${param_name}=${param_value}" >> $CONFIGURATION_FILE
fi
else
echo "${param_name}=${param_value}" > $CONFIGURATION_FILE
fi
fi
fi
fi
}
function save_configuration_values {
if [ ! $CONFIGURATION_FILE ]; then
CONFIGURATION_FILE='freedombone.cfg'
fi
for v in "${configuration_variables[@]}"
do
write_config_param "$v" "${!v}"
done
}
function read_configuration_values {
# if not installing on a Beaglebone then use sdb as the USB drive by default
if [ ! $INSTALLING_ON_BBB ]; then
if [[ $USB_DRIVE == /dev/sda1 ]]; then
USB_DRIVE=/dev/sdb1
fi
fi
if [ -f $CONFIGURATION_FILE ]; then
read_repo_servers
# Ensure that a copy of the config exists for upgrade purposes
if [[ $CONFIGURATION_FILE != "/root/${PROJECT_NAME}.cfg" ]]; then
cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg
fi
for v in "${configuration_variables[@]}"
do
read_config_param "$v"
done