#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

sys_disk=$(lsblk -l | egrep -B 1 "/$|boot|swap" | egrep -v "lvm|luks|--" | awk '{print $1}' | sed -e '/sd/s/[0-9]//' -e '/nvme/s/p[0-9]//' -e '/vd/s/[0-9]//' | sort|uniq)
data_disk=$(lsblk | grep -E "^s|^n|^v" | grep -v sr0 | awk '{print"/dev/"$1}' | grep -v ${sys_disk} | sort | tr '\n' ',' | sed s/,$//)
echo "DISKLIST=${data_disk}" > /tmp/zjfx.config

practicnic=$(cat /tmp/multidialstatus.json | jq -r .multidial[].practicnic)
if [ -z "${practicnic}" ];then
    zjnic=$(route -n | grep '^0.0.0.0' | awk '{print$NF}')
    echo "NICS=${zjnic}" >> /tmp/zjfx.config 
else
    zjnic=$(echo ${practicnic} | sed 's/ /,/g')
    echo "NICS=${zjnic}" >> /tmp/zjfx.config
fi

if [ ! -e /etc/zjfx.config ];then
    cp -raf /tmp/zjfx.config  /etc/zjfx.config
else
   diff -q /tmp/zjfx.config /etc/zjfx.config
   if [ $? -ne 0 ];then
      cp -raf /tmp/zjfx.config /etc/zjfx.config
   fi
fi
