#! /bin/bash

#------------------------------------------------------------------
# Sync /etc/netns/ from XR linux to the host
#
# April, 2017 Budhaditya Banerjee
#
# Copyright (c) 2017-2018 by cisco Systems, Inc.
# All rights reserved.
#------------------------------------------------------------------

# Source spirit_log.sh for syslog
source /etc/init.d/spirit_log.sh

function sync_netns()
{
    local directory=$1
    local filename=$2
    
    # Check that directory does have /misc/app_host/etc/netns
    if ! [[ $directory == *"/misc/app_host/etc/netns"* ]]; then
        platform_log_syslog_error "Incorrect directory passed to sync."
        exit 1
    fi

    local newpath=$(echo $directory/$filename | sed "s,/misc/app_host,,g")

    rm -rf --preserve-root --one-file-system "$newpath"
    cp -rpf $directory/$filename $newpath
}

sync_netns $@
