#!/bin/bash

mount -o remount,rw /

# Source directory
source_dir="/data/dbus-fzsonick-48tl"

# Destination directory
destination_dir_upper="/opt/victronenergy/"
destination_dir="/opt/victronenergy/dbus-fzsonick-48tl/"

# Check if the destination directory exists
if [ -d "$destination_dir" ]; then
    # Remove the destination directory
    rm -r "$destination_dir"
fi

# Copy the contents of the source directory to the destination directory
cp -r "$source_dir" "$destination_dir_upper"

# Set MPPT network mode to 0
sed -i "s|('/Link/NetworkMode', [^)]*)|('/Link/NetworkMode', 0)|g" /opt/victronenergy/dbus-systemcalc-py/delegates/dvcc.py

find /data/innovenergy/openvpn -type f -exec chmod 777 {} \;

/data/innovenergy/openvpn/service/run

exit 0