From 6376e99df7c2c4171b4c68bec6828ecb9e77ce60 Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Fri, 4 Mar 2016 16:19:42 +0100 Subject: [PATCH] Implemented unmanaged configurations #16 Replacing merge_default --- openwisp-config/files/openwisp.agent | 59 ++++++++++----------------- openwisp-config/files/openwisp.config | 10 ++++- openwisp-config/files/openwisp.init | 10 ++--- 3 files changed, 35 insertions(+), 44 deletions(-) diff --git a/openwisp-config/files/openwisp.agent b/openwisp-config/files/openwisp.agent index f7f8674..5cae52f 100644 --- a/openwisp-config/files/openwisp.agent +++ b/openwisp-config/files/openwisp.agent @@ -9,7 +9,7 @@ while [ -n "$1" ]; do --uuid) export UUID="$2"; shift;; --key) export KEY="$2"; shift;; --shared-secret) export SHARED_SECRET="$2"; shift;; - --merge-default) export MERGE_DEFAULT="$2"; shift;; + --unmanaged) export UNMANAGED="$2"; shift;; --test-config) export TEST_CONFIG="$2"; shift;; --test-script) export TEST_SCRIPT="$2"; shift;; -*) @@ -48,18 +48,19 @@ TEST_CHECKSUM="$WORKING_DIR/test_checksum" STATUS_REPORT="$WORKING_DIR/status_report" APPLYING_CONF="$WORKING_DIR/applying_conf" REGISTRATION_URL="$URL/controller/register/" -DEFAULT_DIR="/etc/openwisp-config-defaults" +# DEFAULT_DIR="/etc/openwisp-config-defaults" +UNMANAGED_DIR="$WORKING_DIR/unmanaged" FETCH_COMMAND="curl -s" mkdir -p $WORKING_DIR -mkdir -p $DEFAULT_DIR +mkdir -p $UNMANAGED_DIR if [ "$VERIFY_SSL" != "1" ]; then FETCH_COMMAND="$FETCH_COMMAND -k" fi -if [ -n "$MERGE_DEFAULT" ]; then +if [ -n "$UNMANAGED" ]; then # replace commas with spaces - MERGE_DEFAULT=$(echo $MERGE_DEFAULT | tr ',' ' ') + UNMANAGED=$(echo $UNMANAGED | tr ',' ' ') fi # ensures we are dealing with the right web server @@ -170,8 +171,8 @@ configuration_changed() { # applies a specified configuration archive apply_configuration() { local sleep_time=${2-2} - # store default config (if enabled) - store_default + # store unmanaged config (if enabled) + store_unmanaged # -r restores the specified configuration archive sysupgrade -r $1 local exit_code=$? @@ -183,7 +184,7 @@ apply_configuration() { return 1 fi # merge default config (if enabled) - merge_default + merge_unmanaged # apply changes and wait 2 seconds /usr/sbin/apply_config sleep $sleep_time @@ -254,42 +255,26 @@ test_configuration() { return $ret } -# stores default configuration files that will be merged with the -# configuration downloaded from the controller -store_default() { - if [ -z "$MERGE_DEFAULT" ]; then +# stores unmanaged configuration sections that will be merged +# with the configuration downloaded from the controller +store_unmanaged() { + if [ -z "$UNMANAGED" ]; then return 0 fi - - for config in $MERGE_DEFAULT; do - # store default config only if not already done previously - if [ ! -f "$DEFAULT_DIR/$config" ] && [ -f "/etc/config/$config" ]; then - # system is a special case: - # we need to remove hostname and timezone because these - # are automatically generated by the controller - if [ "$config" == "system" ]; then - uci delete system.@system[0] - uci commit system - fi - cp "/etc/config/$config" "$DEFAULT_DIR/$config" - logger -s "Stored $DEFAULT_DIR/$config" \ - -t openwisp \ - -p daemon.info - fi - done + /usr/sbin/store_unmanaged -o="$UNMANAGED" } -# merges default configuration files stored by store_default() -merge_default() { - if [ -z "$MERGE_DEFAULT" ]; then +# merges unmanaged configuration files stored by store_unmanaged() +merge_unmanaged() { + if [ -z "$UNMANAGED" ]; then return 0 fi - for config in $MERGE_DEFAULT; do - if [ -f "$DEFAULT_DIR/$config" ]; then - uci import -m -f $DEFAULT_DIR/$config $config - uci commit $config - fi + for path in $UNMANAGED_DIR/* + do + local config=$(basename $path) + uci import -m -f $path $config + uci commit $config done } diff --git a/openwisp-config/files/openwisp.config b/openwisp-config/files/openwisp.config index 784e449..24d2573 100644 --- a/openwisp-config/files/openwisp.config +++ b/openwisp-config/files/openwisp.config @@ -8,7 +8,13 @@ config controller 'http' option uuid '' option key '' option shared_secret '' - list merge_default 'system' - list merge_default 'network' option test_config '1' #option test_script '/usr/sbin/mytest' + list unmanaged 'system.ntp' + list unmanaged 'system.@led' + list unmanaged 'network.loopback' + list unmanaged 'network.globals' + list unmanaged 'network.lan' + list unmanaged 'network.wan' + list unmanaged 'network.@switch' + list unmanaged 'network.@switch_vlan' diff --git a/openwisp-config/files/openwisp.init b/openwisp-config/files/openwisp.init index dc8b04f..aa10e67 100644 --- a/openwisp-config/files/openwisp.init +++ b/openwisp-config/files/openwisp.init @@ -14,7 +14,7 @@ start_service() { uuid=$(config_get http uuid) key=$(config_get http key) shared_secret=$(config_get http shared_secret) - merge_default=$(config_get http merge_default) + unmanaged=$(config_get http unmanaged) test_config=$(config_get http test_config) test_script=$(config_get http test_script) if [ $url ]; then url="--url $url"; fi @@ -23,11 +23,11 @@ start_service() { if [ $uuid ]; then uuid="--uuid $uuid"; fi if [ $key ]; then key="--key $key"; fi if [ $shared_secret ]; then shared_secret="--shared-secret $shared_secret"; fi - if [ -n "$merge_default" ]; then + if [ -n "$unmanaged" ]; then # replace spaces with commas to avoid problems when # passing this arg to procd_set_param command - merge_default=$(echo $merge_default | tr ' ' ',') - merge_default="--merge-default $merge_default"; + unmanaged=$(echo $unmanaged | tr ' ' ',') + unmanaged="--unmanaged $unmanaged"; fi if [ $test_config ]; then test_config="--test-config $test_config"; fi if [ $test_script ]; then test_script="--test-script $test_script"; fi @@ -48,7 +48,7 @@ start_service() { procd_open_instance procd_set_param command $PROG $url $interval $verify_ssl $uuid $key \ - $shared_secret $merge_default $test_config $test_script + $shared_secret $unmanaged $test_config $test_script procd_set_param respawn procd_close_instance logger -s "$PROG_NAME started" \