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
SYSTEM_TYPE=$'full'
write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
fi
if [[ $(is_valid_variant) == "0" ]]; then

View File

@ -796,6 +796,7 @@ function choose_system_variant {
variant_choice=$((variant_choice - 1))
export SYSTEM_TYPE=${variants_list[$variant_choice]}
save_configuration_file
write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
}
function validate_freedns_code {
@ -858,134 +859,46 @@ function save_configuration_file {
CONFIGURATION_FILE='freedombone.cfg'
fi
echo "MY_USERNAME=$MY_USERNAME" > $CONFIGURATION_FILE
echo "DEFAULT_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME" >> $CONFIGURATION_FILE
if [ $DEFAULT_DOMAIN_CODE ]; then
echo "DEFAULT_DOMAIN_CODE=$DEFAULT_DOMAIN_CODE" >> $CONFIGURATION_FILE
fi
echo "SYSTEM_TYPE=$SYSTEM_TYPE" >> $CONFIGURATION_FILE
echo "INSTALLING_ON_BBB=$INSTALLING_ON_BBB" >> $CONFIGURATION_FILE
echo "USB_DRIVE=$USB_DRIVE" >> $CONFIGURATION_FILE
echo "DDNS_PROVIDER=$DDNS_PROVIDER" >> $CONFIGURATION_FILE
echo "DDNS_USERNAME=$DDNS_USERNAME" >> $CONFIGURATION_FILE
echo "DDNS_PASSWORD=$DDNS_PASSWORD" >> $CONFIGURATION_FILE
echo "DEFAULT_LANGUAGE=$DEFAULT_LANGUAGE" >> $CONFIGURATION_FILE
if [ "$MY_NAME" ]; then
echo "MY_NAME=$MY_NAME" >> $CONFIGURATION_FILE
fi
echo "MY_EMAIL_ADDRESS=$MY_EMAIL_ADDRESS" >> $CONFIGURATION_FILE
if [ $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
echo "LOCAL_NETWORK_STATIC_IP_ADDRESS=$LOCAL_NETWORK_STATIC_IP_ADDRESS" >> $CONFIGURATION_FILE
echo "ROUTER_IP_ADDRESS=$ROUTER_IP_ADDRESS" >> $CONFIGURATION_FILE
fi
if [ $ENABLE_CJDNS ]; then
echo "ENABLE_CJDNS=$ENABLE_CJDNS" >> $CONFIGURATION_FILE
fi
if [ $ENABLE_BATMAN ]; then
echo "ENABLE_BATMAN=$ENABLE_BATMAN" >> $CONFIGURATION_FILE
fi
if [ $ENABLE_BABEL ]; then
echo "ENABLE_BABEL=$ENABLE_BABEL" >> $CONFIGURATION_FILE
fi
echo "DEBIAN_REPO=$DEBIAN_REPO" >> $CONFIGURATION_FILE
if [ $NAMESERVER1 ]; then
echo "NAMESERVER1=$NAMESERVER1" >> $CONFIGURATION_FILE
fi
if [ $NAMESERVER2 ]; then
echo "NAMESERVER2=$NAMESERVER2" >> $CONFIGURATION_FILE
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
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)
if [ $FRIENDS_MIRRORS_SERVER ]; then
echo "FRIENDS_MIRRORS_SERVER=$FRIENDS_MIRRORS_SERVER" >> $CONFIGURATION_FILE
fi
if [ $FRIENDS_MIRRORS_SSH_PORT ]; then
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
for v in "${save_variables[@]}"
do
write_config_param "$v" "${!v}"
done
}
# test a domain name to see if it's valid

View File

@ -31,10 +31,12 @@
function read_config_param {
param_name="$1"
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}')
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
@ -44,15 +46,19 @@ function write_config_param {
param_name="$1"
param_value="$2"
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
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
else
echo "${param_name}=${param_value}" > $CONFIGURATION_FILE
fi
fi
}
@ -80,95 +86,88 @@ function read_configuration {
cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg
fi
read_config_param "FRIENDS_MIRRORS_SERVER"
read_config_param "FRIENDS_MIRRORS_SSH_PORT"
read_config_param "FRIENDS_MIRRORS_PASSWORD"
read_config_param "MY_MIRRORS_PASSWORD"
read_config_variables=(FRIENDS_MIRRORS_SERVER
FRIENDS_MIRRORS_SSH_PORT
FRIENDS_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"
read_config_param "SSL_PROTOCOLS"
read_config_param "SSL_CIPHERS"
read_config_param "SSH_CIPHERS"
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"
for v in "${read_config_variables[@]}"
do
read_config_param "$v"
done
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."
fi
fi

View File

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