#!/bin/bash
#  execute wineserver -k for all users running a TeamViewer
#  (if not called by root, only successful for the current user)

if [ "$1" = 'kill' ] ; then		# kill for current user
  TV_script_dir=$(dirname $(readlink -f "$0"))
  "$TV_script_dir/wrapper" wineserver -k
elif [ $(id -u) = 0 ] ; then		# launch the script for all users (except root)
  for user in $(ps aux | grep -v "^root" | grep TeamViewer | cut --delimiter=' ' -f 1) ; do
    su -c "$0 kill" - $user
  done
else					# launch the script for the current user
  "$0" "kill"
fi

