#!/bin/sh

echo "Test 1: Remount read only"
mount -o ro,remount /

if [ $? -ne 255 ]
then
  echo "successful"
  echo "Online flash should work without problems"
  echo "At best reboot box with \"reboot\""
#  exit
fi

echo ""
echo "Test 2: init 2 and kill known problem processes"
init 2
killall nmbd > /dev/null 2>&1
killall smbd > /dev/null 2>&1
killall rpc.mountd > /dev/null 2>&1
killall rpc.statd > /dev/null 2>&1
/etc/init.d/softcam stop > /dev/null 2>&1
killall CCcam > /dev/null 2>&1
pkill -9 -f '[Oo][Ss][Cc][Aa][Mm]' > /dev/null 2>&1
ps w | grep -i oscam | grep -v grep | awk '{print $1}'| xargs kill -9 > /dev/null 2>&1
pkill -9 -f '[Ww][Ii][Cc][Aa][Rr][Dd][Dd]' > /dev/null 2>&1
ps w | grep -i wicardd | grep -v grep | awk '{print $1}'| xargs kill -9 > /dev/null 2>&1
killall kodi.bin > /dev/null 2>&1
killall hddtemp > /dev/null 2>&1
killall transmission-daemon > /dev/null 2>&1
killall openvpn > /dev/null 2>&1
/etc/init.d/sabnzbd stop > /dev/null 2>&1
pkill -9 -f cihelper > /dev/null 2>&1
pkill -9 -f ciplus_helper > /dev/null 2>&1
pkill -9 -f ciplushelper > /dev/null 2>&1
pkill -f vmc.sh > /dev/null 2>&1
pkill -f DBServer.py > /dev/null 2>&1

sleep 10
mount -o ro,remount /

if [ $? -ne 255 ]
then             
  echo "successful"
  echo "Online flash should work without problems"
  echo "At best reboot box with \"reboot\""
  exit
fi

echo "Online flash will most likely abort"
echo "List of open files:"
lsof | grep -v pipe: | grep -v socket: | grep -v anon_inode: | grep -v /dev/ | grep -v /var/volatile | grep -v /proc/ | grep -v "/media"

echo "At best reboot box with \"reboot\""
