Handling app variables

This commit is contained in:
Bob Mottram 2016-10-09 11:02:11 +01:00
parent d50ee1761e
commit d5bedb0e55
4 changed files with 145 additions and 230 deletions

View File

@ -285,6 +285,7 @@ function parse_args {
if [ ! $SYSTEM_TYPE ]; then if [ ! $SYSTEM_TYPE ]; then
SYSTEM_TYPE=$'full' SYSTEM_TYPE=$'full'
write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
fi fi
if [[ $(is_valid_variant) == "0" ]]; then if [[ $(is_valid_variant) == "0" ]]; then

View File

@ -796,6 +796,7 @@ function choose_system_variant {
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_file
write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
} }
function validate_freedns_code { function validate_freedns_code {
@ -858,134 +859,46 @@ function save_configuration_file {
CONFIGURATION_FILE='freedombone.cfg' CONFIGURATION_FILE='freedombone.cfg'
fi fi
echo "MY_USERNAME=$MY_USERNAME" > $CONFIGURATION_FILE save_variables=(MY_USERNAME
echo "DEFAULT_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME" >> $CONFIGURATION_FILE DEFAULT_DOMAIN_NAME
if [ $DEFAULT_DOMAIN_CODE ]; then DEFAULT_DOMAIN_CODE
echo "DEFAULT_DOMAIN_CODE=$DEFAULT_DOMAIN_CODE" >> $CONFIGURATION_FILE SYSTEM_TYPE
fi INSTALLING_ON_BBB
echo "SYSTEM_TYPE=$SYSTEM_TYPE" >> $CONFIGURATION_FILE USB_DRIVE
echo "INSTALLING_ON_BBB=$INSTALLING_ON_BBB" >> $CONFIGURATION_FILE DDNS_PROVIDER
echo "USB_DRIVE=$USB_DRIVE" >> $CONFIGURATION_FILE DDNS_USERNAME
echo "DDNS_PROVIDER=$DDNS_PROVIDER" >> $CONFIGURATION_FILE DDNS_PASSWORD
echo "DDNS_USERNAME=$DDNS_USERNAME" >> $CONFIGURATION_FILE DEFAULT_LANGUAGE
echo "DDNS_PASSWORD=$DDNS_PASSWORD" >> $CONFIGURATION_FILE MY_NAME
echo "DEFAULT_LANGUAGE=$DEFAULT_LANGUAGE" >> $CONFIGURATION_FILE MY_EMAIL_ADDRESS
if [ "$MY_NAME" ]; then LOCAL_NETWORK_STATIC_IP_ADDRESS
echo "MY_NAME=$MY_NAME" >> $CONFIGURATION_FILE ROUTER_IP_ADDRESS
fi ENABLE_CJDNS
echo "MY_EMAIL_ADDRESS=$MY_EMAIL_ADDRESS" >> $CONFIGURATION_FILE ENABLE_BATMAN
if [ $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then ENABLE_BABEL
echo "LOCAL_NETWORK_STATIC_IP_ADDRESS=$LOCAL_NETWORK_STATIC_IP_ADDRESS" >> $CONFIGURATION_FILE DEBIAN_REPO
echo "ROUTER_IP_ADDRESS=$ROUTER_IP_ADDRESS" >> $CONFIGURATION_FILE NAMESERVER1
fi NAMESERVER2
if [ $ENABLE_CJDNS ]; then HWRNG_TYPE
echo "ENABLE_CJDNS=$ENABLE_CJDNS" >> $CONFIGURATION_FILE ENABLE_SOCIAL_KEY_MANAGEMENT
fi WIFI_SSID
if [ $ENABLE_BATMAN ]; then WIFI_INTERFACE
echo "ENABLE_BATMAN=$ENABLE_BATMAN" >> $CONFIGURATION_FILE WIFI_TYPE
fi WIFI_PASSPHRASE
if [ $ENABLE_BABEL ]; then WIFI_HOTSPOT
echo "ENABLE_BABEL=$ENABLE_BABEL" >> $CONFIGURATION_FILE BATMAN_CELLID
fi WIFI_CHANNEL
echo "DEBIAN_REPO=$DEBIAN_REPO" >> $CONFIGURATION_FILE DH_KEYLENGTH
if [ $NAMESERVER1 ]; then ONION_ONLY
echo "NAMESERVER1=$NAMESERVER1" >> $CONFIGURATION_FILE FRIENDS_MIRRORS_SERVER
fi FRIENDS_MIRRORS_SSH_PORT
if [ $NAMESERVER2 ]; then FRIENDS_MIRRORS_PASSWORD
echo "NAMESERVER2=$NAMESERVER2" >> $CONFIGURATION_FILE MY_MIRRORS_PASSWORD)
fi
if [ "$WIKI_TITLE" ]; then
echo "WIKI_TITLE=$WIKI_TITLE" >> $CONFIGURATION_FILE
fi
if [ $WIKI_DOMAIN_NAME ]; then
echo "WIKI_DOMAIN_NAME=$WIKI_DOMAIN_NAME" >> $CONFIGURATION_FILE
fi
if [ $WIKI_CODE ]; then
echo "WIKI_CODE=$WIKI_CODE" >> $CONFIGURATION_FILE
fi
if [ "$MY_BLOG_TITLE" ]; then
echo "MY_BLOG_TITLE=$MY_BLOG_TITLE" >> $CONFIGURATION_FILE
fi
if [ $FULLBLOG_DOMAIN_NAME ]; then
echo "FULLBLOG_DOMAIN_NAME=$FULLBLOG_DOMAIN_NAME" >> $CONFIGURATION_FILE
fi
if [ $FULLBLOG_CODE ]; then
echo "FULLBLOG_CODE=$FULLBLOG_CODE" >> $CONFIGURATION_FILE
fi
if [ $HUBZILLA_DOMAIN_NAME ]; then
echo "HUBZILLA_DOMAIN_NAME=$HUBZILLA_DOMAIN_NAME" >> $CONFIGURATION_FILE
fi
if [ $HUBZILLA_CODE ]; then
echo "HUBZILLA_CODE=$HUBZILLA_CODE" >> $CONFIGURATION_FILE
fi
if [ ${#MICROBLOG_DOMAIN_NAME} -gt 1 ]; then
echo "MICROBLOG_DOMAIN_NAME=$MICROBLOG_DOMAIN_NAME" >> $CONFIGURATION_FILE
fi
if [ $MICROBLOG_CODE ]; then
echo "MICROBLOG_CODE=$MICROBLOG_CODE" >> $CONFIGURATION_FILE
fi
if [ ${#MICROBLOG_WELCOME_MESSAGE} -gt 1 ]; then
echo "MICROBLOG_WELCOME_MESSAGE=$MICROBLOG_WELCOME_MESSAGE" >> $CONFIGURATION_FILE
fi
if [ $MICROBLOG_BACKGROUND_IMAGE_URL ]; then
echo "MICROBLOG_BACKGROUND_IMAGE_URL=$MICROBLOG_BACKGROUND_IMAGE_URL" >> $CONFIGURATION_FILE
fi
if [ $GIT_DOMAIN_NAME ]; then
echo "GIT_DOMAIN_NAME=$GIT_DOMAIN_NAME" >> $CONFIGURATION_FILE
fi
if [ $GIT_CODE ]; then
echo "GIT_CODE=$GIT_CODE" >> $CONFIGURATION_FILE
fi
if [ $MEDIAGOBLIN_DOMAIN_NAME ]; then
echo "MEDIAGOBLIN_DOMAIN_NAME=$MEDIAGOBLIN_DOMAIN_NAME" >> $CONFIGURATION_FILE
fi
if [ $MEDIAGOBLIN_CODE ]; then
echo "MEDIAGOBLIN_CODE=$MEDIAGOBLIN_CODE" >> $CONFIGURATION_FILE
fi
if [ $HWRNG_TYPE ]; then
echo "HWRNG_TYPE=$HWRNG_TYPE" >> $CONFIGURATION_FILE
fi
if [ $ENABLE_SOCIAL_KEY_MANAGEMENT ]; then
echo "ENABLE_SOCIAL_KEY_MANAGEMENT=$ENABLE_SOCIAL_KEY_MANAGEMENT" >> $CONFIGURATION_FILE
fi
if [ $WIFI_SSID ]; then
echo "WIFI_SSID=$WIFI_SSID" >> $CONFIGURATION_FILE
fi
if [ $WIFI_INTERFACE ]; then
echo "WIFI_INTERFACE=$WIFI_INTERFACE" >> $CONFIGURATION_FILE
fi
if [ $WIFI_TYPE ]; then
echo "WIFI_TYPE=$WIFI_TYPE" >> $CONFIGURATION_FILE
fi
if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
echo "WIFI_PASSPHRASE=$WIFI_PASSPHRASE" >> $CONFIGURATION_FILE
fi
if [ $WIFI_HOTSPOT ]; then
echo "WIFI_HOTSPOT=$WIFI_HOTSPOT" >> $CONFIGURATION_FILE
fi
if [ $BATMAN_CELLID ]; then
echo "BATMAN_CELLID=$BATMAN_CELLID" >> $CONFIGURATION_FILE
fi
if [ $WIFI_CHANNEL ]; then
echo "WIFI_CHANNEL=$WIFI_CHANNEL" >> $CONFIGURATION_FILE
fi
if [ $DH_KEYLENGTH ]; then
echo "DH_KEYLENGTH=$DH_KEYLENGTH" >> $CONFIGURATION_FILE
fi
echo "ONION_ONLY=$ONION_ONLY" >> $CONFIGURATION_FILE
if [ $FRIENDS_MIRRORS_SERVER ]; then for v in "${save_variables[@]}"
echo "FRIENDS_MIRRORS_SERVER=$FRIENDS_MIRRORS_SERVER" >> $CONFIGURATION_FILE do
fi write_config_param "$v" "${!v}"
if [ $FRIENDS_MIRRORS_SSH_PORT ]; then done
echo "FRIENDS_MIRRORS_SSH_PORT=$FRIENDS_MIRRORS_SSH_PORT" >> $CONFIGURATION_FILE
fi
if [ $FRIENDS_MIRRORS_PASSWORD ]; then
echo "FRIENDS_MIRRORS_PASSWORD=$FRIENDS_MIRRORS_PASSWORD" >> $CONFIGURATION_FILE
fi
if [ $MY_MIRRORS_PASSWORD ]; then
echo "MY_MIRRORS_PASSWORD=$MY_MIRRORS_PASSWORD" >> $CONFIGURATION_FILE
fi
} }
# test a domain name to see if it's valid # test a domain name to see if it's valid

View File

@ -31,6 +31,7 @@
function read_config_param { function read_config_param {
param_name="$1" param_name="$1"
if [ ${#param_name} -gt 0 ]; then
if [ $CONFIGURATION_FILE ]; then if [ $CONFIGURATION_FILE ]; then
if [ -f $CONFIGURATION_FILE ]; then if [ -f $CONFIGURATION_FILE ]; then
if grep -q "${param_name}=" $CONFIGURATION_FILE; then if grep -q "${param_name}=" $CONFIGURATION_FILE; then
@ -38,12 +39,15 @@ function read_config_param {
fi fi
fi fi
fi fi
fi
} }
function write_config_param { function write_config_param {
param_name="$1" param_name="$1"
param_value="$2" param_value="$2"
if [ ${#param_name} -gt 0 ]; then
if [ ${#param_value} -gt 0 ]; then
if [ $CONFIGURATION_FILE ]; then if [ $CONFIGURATION_FILE ]; then
if [ -f $CONFIGURATION_FILE ]; then if [ -f $CONFIGURATION_FILE ]; then
if grep -q "${param_name}=" $CONFIGURATION_FILE; then if grep -q "${param_name}=" $CONFIGURATION_FILE; then
@ -55,6 +59,8 @@ function write_config_param {
echo "${param_name}=${param_value}" > $CONFIGURATION_FILE echo "${param_name}=${param_value}" > $CONFIGURATION_FILE
fi fi
fi fi
fi
fi
} }
function read_configuration { function read_configuration {
@ -80,95 +86,88 @@ function read_configuration {
cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg
fi fi
read_config_param "FRIENDS_MIRRORS_SERVER" read_config_variables=(FRIENDS_MIRRORS_SERVER
read_config_param "FRIENDS_MIRRORS_SSH_PORT" FRIENDS_MIRRORS_SSH_PORT
read_config_param "FRIENDS_MIRRORS_PASSWORD" FRIENDS_MIRRORS_PASSWORD
read_config_param "MY_MIRRORS_PASSWORD" MY_MIRRORS_PASSWORD
SYSTEM_TYPE
SSL_PROTOCOLS
SSL_CIPHERS
SSH_CIPHERS
SSH_MACS
SSH_KEX
SSH_HOST_KEY_ALGORITHMS
SSH_PASSWORDS
REFRESH_GPG_KEYS_HOURS
GPG_KEYSERVER
ENABLE_SOCIAL_KEY_MANAGEMENT
MY_USERNAME
DOMAIN_NAME
DEFAULT_DOMAIN_NAME
DEFAULT_DOMAIN_CODE
NAMESERVER1
NAMESERVER2
GET_IP_ADDRESS_URL
DDNS_PROVIDER
DDNS_USERNAME
DDNS_PASSWORD
LOCAL_NETWORK_STATIC_IP_ADDRESS
ROUTER_IP_ADDRESS
CPU_CORES
WEBSERVER_LOG_LEVEL
ROUTE_THROUGH_TOR
MY_NAME
MY_EMAIL_ADDRESS
INSTALLING_ON_BBB
SSH_PORT
INSTALLED_WITHIN_DOCKER
GPG_ENCRYPT_STORED_EMAIL
MY_GPG_PUBLIC_KEY
MY_GPG_PRIVATE_KEY
MY_GPG_PUBLIC_KEY_ID
USB_DRIVE
MAX_PHP_MEMORY
TLS_TIME_SOURCE1
TLS_TIME_SOURCE2
ONION_ONLY
DEFAULT_LANGUAGE
MINIMAL_INSTALL
LETSENCRYPT_SERVER
WIFI_INTERFACE
WIFI_SSID
WIFI_TYPE
WIFI_PASSPHRASE
WIFI_HOTSPOT
WIFI_NETWORKS_FILE
DEFAULT_SEARCH
SEARCH_ENGINE_PASSWORD
PROJECT_WEBSITE
PROJECT_REPO
GPGIT_REPO
GPGIT_COMMIT
NGINX_ENSITE_REPO
NGINX_ENSITE_REPO
NGINX_ENSITE_COMMIT
CLEANUP_MAILDIR_COMMIT
CLEANUP_MAILDIR_REPO
INADYN_REPO
INADYN_COMMIT
DH_KEYLENGTH
WIFI_CHANNEL
IPV6_NETWORK
HWRNG_TYPE
ENABLE_BABEL
ENABLE_BATMAN
ENABLE_CJDNS
PUBLIC_MAILING_LIST)
read_config_param "SYSTEM_TYPE" for v in "${read_config_variables[@]}"
read_config_param "SSL_PROTOCOLS" do
read_config_param "SSL_CIPHERS" read_config_param "$v"
read_config_param "SSH_CIPHERS" done
read_config_param "SSH_MACS"
read_config_param "SSH_KEX"
read_config_param "SSH_HOST_KEY_ALGORITHMS"
read_config_param "SSH_PASSWORDS"
read_config_param "REFRESH_GPG_KEYS_HOURS"
read_config_param "GPG_KEYSERVER"
read_config_param "ENABLE_SOCIAL_KEY_MANAGEMENT"
read_config_param "MY_USERNAME"
read_config_param "DOMAIN_NAME"
read_config_param "DEFAULT_DOMAIN_NAME"
read_config_param "DEFAULT_DOMAIN_CODE"
read_config_param "NAMESERVER1"
read_config_param "NAMESERVER2"
read_config_param "GET_IP_ADDRESS_URL"
read_config_param "DDNS_PROVIDER"
read_config_param "DDNS_USERNAME"
read_config_param "DDNS_PASSWORD"
read_config_param "LOCAL_NETWORK_STATIC_IP_ADDRESS"
read_config_param "ROUTER_IP_ADDRESS"
read_config_param "CPU_CORES"
read_config_param "WEBSERVER_LOG_LEVEL"
read_config_param "ROUTE_THROUGH_TOR"
read_config_param "MY_NAME"
read_config_param "MY_EMAIL_ADDRESS"
read_config_param "INSTALLING_ON_BBB"
read_config_param "SSH_PORT"
read_config_param "INSTALLED_WITHIN_DOCKER"
read_config_param "GPG_ENCRYPT_STORED_EMAIL"
read_config_param "MY_GPG_PUBLIC_KEY"
read_config_param "MY_GPG_PRIVATE_KEY"
read_config_param "MY_GPG_PUBLIC_KEY_ID"
read_config_param "USB_DRIVE"
read_config_param "MAX_PHP_MEMORY"
read_config_param "TLS_TIME_SOURCE1"
read_config_param "TLS_TIME_SOURCE2"
read_config_param "ONION_ONLY"
read_config_param "DEFAULT_LANGUAGE"
read_config_param "MINIMAL_INSTALL"
read_config_param "LETSENCRYPT_SERVER"
read_config_param "WIFI_INTERFACE"
read_config_param "WIFI_SSID"
read_config_param "WIFI_TYPE"
read_config_param "WIFI_PASSPHRASE"
read_config_param "WIFI_HOTSPOT"
read_config_param "WIFI_NETWORKS_FILE"
read_config_param "DEFAULT_SEARCH"
read_config_param "SEARCH_ENGINE_PASSWORD"
read_config_param "PROJECT_WEBSITE"
read_config_param "PROJECT_REPO"
read_config_param "GPGIT_REPO"
read_config_param "GPGIT_COMMIT"
read_config_param "NGINX_ENSITE_REPO"
read_config_param "NGINX_ENSITE_REPO"
read_config_param "NGINX_ENSITE_COMMIT"
read_config_param "CLEANUP_MAILDIR_COMMIT"
read_config_param "CLEANUP_MAILDIR_REPO"
read_config_param "INADYN_REPO"
read_config_param "INADYN_COMMIT"
read_config_param "DH_KEYLENGTH"
read_config_param "WIFI_CHANNEL"
read_config_param "IPV6_NETWORK"
read_config_param "HWRNG_TYPE"
read_config_param "ENABLE_BABEL"
read_config_param "ENABLE_BATMAN"
read_config_param "ENABLE_CJDNS"
read_config_param "PUBLIC_MAILING_LIST"
if grep -q "DEBIAN_REPO" $CONFIGURATION_FILE; then if grep -q "DEBIAN_REPO" $CONFIGURATION_FILE; then
DEBIAN_REPO=$(grep "DEBIAN_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}') read_config_param "DEBIAN_REPO"
CHECK_MESSAGE=$"Check your internet connection, /etc/network/interfaces and /etc/resolv.conf, then delete $COMPLETION_FILE, run 'rm -fR /var/lib/apt/lists/* && apt-get update --fix-missing' and run this script again. If hash sum mismatches persist then try setting $DEBIAN_REPO to a different mirror and also change /etc/apt/sources.list." CHECK_MESSAGE=$"Check your internet connection, /etc/network/interfaces and /etc/resolv.conf, then delete $COMPLETION_FILE, run 'rm -fR /var/lib/apt/lists/* && apt-get update --fix-missing' and run this script again. If hash sum mismatches persist then try setting $DEBIAN_REPO to a different mirror and also change /etc/apt/sources.list."
fi fi
fi fi

View File

@ -48,11 +48,12 @@ function app_load_variables {
app_name=$1 app_name=$1
var_name=${app_name}_variables var_name=${app_name}_variables
if [ ! $var_name ]; then if [ ! ${!var_name} ]; then
return return
fi fi
for v in "${$var_name[@]}" varname=${!var_name}
for v in "${var_name[@]}"
do do
read_config_param $v read_config_param $v
done done
@ -63,13 +64,14 @@ function app_save_variables {
app_name=$1 app_name=$1
var_name=${app_name}_variables var_name=${app_name}_variables
if [ ! $var_name ]; then if [ ! ${!var_name} ]; then
return return
fi fi
for v in "${$var_name[@]}" varname=${!var_name}
for v in "${varname[@]}"
do do
save_config_param $v "$$v" save_config_param $v "${!v}"
done done
} }