#!/bin/sh

export u_path="/media/udisk0"
export exe_name="Radarcape_Local_Server_aarch64-buildroot-linux-gnu-gxx_Linux_Debug"
export guard_exe_name="/bin/sh /etc/init.d/S90E-CAP start"


echo "pkill ！"
pkill -f "${guard_exe_name}"
pkill -f "${exe_name}"

echo "remove logs ！"
rm -rf /root/logs*

echo "update config.json！"
cp -r "$u_path"/config.json /root
echo "update restart_net_service.sh！"
cp -r "$u_path"/restart_net_service.sh /root
echo "update interface！"
cp -r "$u_path"/interface /root
echo "update wwwroot！"
rm -rf /root/wwwroot
cp -rp "$u_path"/wwwroot /root



while pgrep -f "${guard_exe_name}" >/dev/null; do
  echo "${guard_exe_name} Process is still running wait one second!"
  sleep 1
done
while pgrep -f "${exe_name}" >/dev/null; do
  echo "${exe_name} Process is running still running wait one second!"
  sleep 1
done


echo "update ${exe_name}！"
cp -r "$u_path/${exe_name}" /root

#/bin/sh /etc/init.d/S90E-CAP start

echo "程序更新成功！"

#       查看挂载： mount
#       卸载U盘： umount /media/udisk0
#       U盘默认地址：/media/udisk0
#       单独更新 cp -r /media/udisk0/* /root
#       mkdir /root/u && chmod 777  /root/u
#       自动部署：  cp /media/udisk0/deploy.sh /root/u  &&  chmod 777 /root/u/deploy.sh  && /root/u/deploy.sh 190
#       更新：     cp /media/udisk0/update.sh /root/u  &&  chmod 777 /root/u/update.sh  && /root/u/update.sh

#   sudo fdisk -l

# /etc/init.d/S90E-CAP stop
# pkill
