#!/bin/bash # # .---. . . # | | | # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-' # ' ' --' --' -' - -' ' ' -' -' -' ' - --' # # Freedom in the Cloud # # Initial reading of the configuration file, typically called freedombone.cfg # # License # ======= # # Copyright (C) 2014-2016 Bob Mottram # # 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 . 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 { # 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 [[ $INSTALLING_FROM_CONFIGURATION_FILE == "yes" ]]; then if [ ! -f $CONFIGURATION_FILE ]; then echo $"The configuration file $CONFIGURATION_FILE was not found" exit 8935 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_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) for v in "${read_config_variables[@]}" do read_config_param "$v" done if grep -q "DEBIAN_REPO" $CONFIGURATION_FILE; then 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 echo "System type: $SYSTEM_TYPE" } # check that domain names are sensible function check_domains { if [ ${#WIKI_DOMAIN_NAME} -gt 1 ]; then function_check test_domain_name test_domain_name "$WIKI_DOMAIN_NAME" if [[ "$test_domain_name" == "$FULLBLOG_DOMAIN_NAME" ]]; then echo $'Wiki domain name is the same as blog domain name. They must be different' exit 97326 fi if [[ "$test_domain_name" == "$MICROBLOG_DOMAIN_NAME" ]]; then echo $'Wiki domain name is the same as microblog domain name. They must be different' exit 36827 fi if [[ "$test_domain_name" == "$HUBZILLA_DOMAIN_NAME" ]]; then echo $'Wiki domain name is the same as hubzilla domain name. They must be different' exit 65848 fi if [ ${#GIT_DOMAIN_NAME} -gt 1 ]; then if [[ "$test_domain_name" == "$GIT_DOMAIN_NAME" ]]; then echo $'Wiki domain name is the same as Gogs domain name. They must be different' exit 73529 fi fi fi if [ ${#FULLBLOG_DOMAIN_NAME} -gt 1 ]; then function_check test_domain_name test_domain_name "$FULLBLOG_DOMAIN_NAME" if [[ "$test_domain_name" == "$WIKI_DOMAIN_NAME" ]]; then echo $'Blog domain name is the same as wiki domain name. They must be different' exit 62348 fi if [[ "$test_domain_name" == "$MICROBLOG_DOMAIN_NAME" ]]; then echo $'Blog domain name is the same as microblog domain name. They must be different' exit 38236 fi if [[ "$test_domain_name" == "$HUBZILLA_DOMAIN_NAME" ]]; then echo $'Blog domain name is the same as hubzilla domain name. They must be different' exit 35483 fi if [ $GIT_DOMAIN_NAME ]; then if [[ "$test_domain_name" == "$GIT_DOMAIN_NAME" ]]; then echo $'Blog domain name is the same as Gogs domain name. They must be different' exit 84695 fi fi fi if [ ${#MICROBLOG_DOMAIN_NAME} -gt 1 ]; then function_check test_domain_name test_domain_name "$MICROBLOG_DOMAIN_NAME" if [[ "$test_domain_name" == "$WIKI_DOMAIN_NAME" ]]; then echo $'Microblog domain name is the same as wiki domain name. They must be different' exit 73924 fi if [[ "$test_domain_name" == "$FULLBLOG_DOMAIN_NAME" ]]; then echo $'Microblog domain name is the same as blog domain name. They must be different' exit 26832 fi if [[ "$test_domain_name" == "$HUBZILLA_DOMAIN_NAME" ]]; then echo $'Microblog domain name is the same as hubzilla domain name. They must be different' exit 678382 fi if [ $GIT_DOMAIN_NAME ]; then if [[ "$test_domain_name" == "$GIT_DOMAIN_NAME" ]]; then echo $'Microblog domain name is the same as Gogs domain name. They must be different' exit 684325 fi fi fi if [ $HUBZILLA_DOMAIN_NAME ]; then function_check test_domain_name test_domain_name "$HUBZILLA_DOMAIN_NAME" if [[ "$test_domain_name" == "$WIKI_DOMAIN_NAME" ]]; then echo $'Hubzilla domain name is the same as wiki domain name. They must be different' exit 83682 fi if [[ "$test_domain_name" == "$FULLBLOG_DOMAIN_NAME" ]]; then echo $'Hubzilla domain name is the same as blog domain name. They must be different' exit 74817 fi if [[ "$test_domain_name" == "$MICROBLOG_DOMAIN_NAME" ]]; then echo $'Hubzilla domain name is the same as microblog domain name. They must be different' exit 83683 fi if [ ${#GIT_DOMAIN_NAME} -gt 1 ]; then if [[ "$test_domain_name" == "$GIT_DOMAIN_NAME" ]]; then echo $'Hubzilla domain name is the same as Gogs domain name. They must be different' exit 135523 fi fi fi if [ ${#GIT_DOMAIN_NAME} -gt 1 ]; then function_check test_domain_name test_domain_name "$GIT_DOMAIN_NAME" if [[ "$test_domain_name" == "$WIKI_DOMAIN_NAME" ]]; then echo $'Hubzilla domain name is the same as wiki domain name. They must be different' exit 83682 fi if [[ "$test_domain_name" == "$FULLBLOG_DOMAIN_NAME" ]]; then echo $'Hubzilla domain name is the same as blog domain name. They must be different' exit 74817 fi if [[ "$test_domain_name" == "$MICROBLOG_DOMAIN_NAME" ]]; then echo $'Hubzilla domain name is the same as microblog domain name. They must be different' exit 83683 fi if [[ "$test_domain_name" == "$HUBZILLA_DOMAIN_NAME" ]]; then echo $'Microblog domain name is the same as hubzilla domain name. They must be different' exit 678382 fi fi } # NOTE: deliberately no exit 0