#! /bin/sh
if isi services -a smb | grep enabled; then
    touch /tmp/patch-smb
    echo "disabling SMB service"
    isi services -a smb disable
    sleep 10
    if pgrep srvsvc; then
	echo "srvsvc running, killing srvsvc"
	pkill srvsvc
    fi
else
    rm -f /tmp/patch-smb
fi
if isi services -a auth | grep enabled; then
    touch /tmp/patch-auth
    echo "disabling auth"
    isi services -a auth disable
    echo "sleeping 10 seconds for services to settle"
    sleep 10
    if pgrep lwreg; then
	echo "lwreg running, killing lwreg"
	pkill lwreg
    fi
    if pgrep netlogon ; then
	echo "netlogon running, killing netlogon"
	pkill netlogon 
    fi
    if pgrep lwio; then
	echo "lwio running, killing lwio"
	pkill lwio
    fi
    if pgrep lsass ; then
	echo "lsass running, killing lsass"
	pkill lsass
    fi
else
    rm -f /tmp/patch-auth
fi

if isi services -a lwsm | grep enabled; then
    touch /tmp/patch-lwsm
    echo "disabling LWSM service"
    isi services -a lwsm disable
    sleep 10
    if pgrep lwsmd; then
	echo "lwsmd running, killing lwsmd"
	pkill lwsmd
    fi
else
    rm -f /tmp/patch-lwsm
fi

# Just in case the lwio didn't actually die. 
#  So now there are 3 attempts to kill lwio
sleep 5
pkill -9 lwio

exit 0
