#!/bin/bash # v1.1.0 . /usr/src/m2/framework/bash_functions.sh #. /usr/src/m2/framework/settings.sh # this packet is for whiptail, not present on Hetzner C7 by default yum -y install newt # Available options - # No option - as everything during install # default/main - install default configuration for single server system setup # backup - install configuration for backup system in main/backup configuration # fs - install configuration for FS server #GLOBAL_OPTIONS=("GUI" "DB" "MAIN_DB" "ES" "FREESWITCH" "PCAP" "RADIUS") GLOBAL_OPTIONS=("GUI" "DB" "MAIN_DB" "ES" "RADIUS") remove_global_option() { local option="$1" local i=0 for i in "${!GLOBAL_OPTIONS[@]}"; do if [[ ${GLOBAL_OPTIONS[i]} == "$option" ]]; then unset 'GLOBAL_OPTIONS[i]' fi done } edit_or_add_setting() { # parameters # $1 - setting # $2 - value local config="/etc/m2/system.conf" local setting="$1" local value="$2" if [[ $setting == "DB" ]]; then setting="DB_PRESENT"; elif [[ $setting == "GUI" ]]; then setting="GUI_PRESENT"; elif [[ $setting == "ES" ]]; then setting="ES_PRESENT"; # elif [[ $setting == "FREESWITCH" ]]; then # setting="FREESWITCH_PRESENT"; elif [[ $setting == "RADIUS" ]]; then setting="RADIUS_PRESENT"; # elif [[ $setting == "PCAP" ]]; then # setting="pcap_enabled"; fi if grep -Fq "$setting" "$config"; then replace_line_bash "$config" "$setting" "$setting=$value" else echo "$setting=$value" >> $config fi } handle_pcap_interface() { #Select first non-loopback UP interface local interface="" interface=$(ip addr show | grep -vF 'lo:' | grep -F UP | awk -F' ' '{print $2}' | sed 's/\://g') if [[ -n "$interface" ]]; then edit_or_add_setting "pcap_listening_net_interface" "$interface" fi } ask_components() { local enabled_component local disabled_component #FREESWITCH "Freeswitch active on this server?" ON \ #PCAP "Should we enable PCAP?" ON 3>&1 1>&2 2>&3) components=$(whiptail --title "Components to install" --checklist --nocancel \ "Select components to install:" 15 120 7 \ GUI "GUI active on this server?" ON \ ES "Should we install ElasticSearch?" ON \ RADIUS "Radius active on this server?" ON \ DB "Database active on this server?" ON \ MAIN_DB "Is this main Database? (only one MAIN_DB can be selected on whole system)" ON 3>&1 1>&2 2>&3) report "Following components will be activated: $components" 3 for enabled_component in $components; do enabled_component="${enabled_component%\"}" enabled_component="${enabled_component#\"}" edit_or_add_setting "$enabled_component" "1" #GLOBAL_OPTIONS=${GLOBAL_OPTIONS//$enabled_component/} remove_global_option "$enabled_component" #if [[ $enabled_component == "PCAP" ]]; then # handle_pcap_interface #fi done for disabled_component in "${GLOBAL_OPTIONS[@]}"; do edit_or_add_setting "$disabled_component" "0" done } if [ ! -f /etc/m2/system.conf ]; then mkdir -p /etc/m2 cp -fr /usr/src/m2/system.conf /etc/m2/system.conf if [[ -z $1 || $1 == "update" ]]; then ask_components elif [[ $1 == "main" || $1 == "default" ]]; then # default configuration (everything is enabled) handle_pcap_interface elif [[ $1 == "backup" ]]; then edit_or_add_setting "MAIN_DB" "0" edit_or_add_setting "ES_PRESENT" "0" handle_pcap_interface elif [[ $1 == "fs" ]]; then edit_or_add_setting "DB_PRESENT" "0" edit_or_add_setting "MAIN_DB" "0" edit_or_add_setting "GUI_PRESENT" "0" edit_or_add_setting "ES_PRESENT" "0" edit_or_add_setting "RADIUS_PRESENT" "0" handle_pcap_interface else report "Unrecognised option $1. Leaving /etc/m2/system.conf unchanged" 2 fi report "System file created" 0 fi