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

View File

@ -28,58 +28,7 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
function read_config_param { configuration_variables=(FRIENDS_MIRRORS_SERVER
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
FRIENDS_MIRRORS_SSH_PORT FRIENDS_MIRRORS_SSH_PORT
FRIENDS_MIRRORS_PASSWORD FRIENDS_MIRRORS_PASSWORD
MY_MIRRORS_PASSWORD MY_MIRRORS_PASSWORD
@ -154,7 +103,69 @@ function read_configuration_values {
ENABLE_CJDNS ENABLE_CJDNS
PUBLIC_MAILING_LIST) 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 do
read_config_param "$v" read_config_param "$v"
done done