SoT-tools-linux/killer/SandsTrilogyKiller

70 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
echo -ne '\033]0;SandsTrilogyKiller\007'
echo "$(date)"
term=$(jq -r '.["term"]' config.json)
hotkey=$(jq -r '.["key"]' config.json)
exe=$(jq -r '.["'$1'"]["exec"]' config.json)
mutexName=$(jq -r '.["'$1'"]["mutexName"]' config.json)
echo "Terminal: $term"
echo "Activation key: $hotkey"
echo "EXE path: $exe"
echo "Mutex name: $mutexName"
mutexPid=''
exePid=''
getMutexPid () {
mutexPid="$(pgrep -af "$mutexName\")$" | awk '{print $1}')"
}
getExePid () {
exePid="$(pgrep -af "POP.EXE$" | awk '{print $1}')"
}
createMutex () {
$term -e wine 'powershell' '-NoExit' '& New-Object System.Threading.Mutex($false, "'$mutexName'")' &
sleep 3s
while [ -z "$mutexPid" ]; do
getMutexPid
done
}
getCreateMutex () {
getMutexPid
if [[ -z $(eval "echo \"\$$1\"") ]]; then
echo "Mutex not detected, creating..."
createMutex $1
else
echo "Mutex detected"
return 1
fi
}
getCreateMutex mutexPid
echo $mutexPid
getExePid
while true; do
read -rsn1 keycode
if [[ "$hotkey" = "$keycode" ]]; then
echo "$(date) activated"
if [[ -n exePid ]] ; then
echo "Killing $exePid"
kill -9 $exePid
rm "$(jq -r '.["0"]["exec"]' config.json | xargs dirname)/PrinceSM"
exePid=''
fi
wine $exe &> /dev/null &
while [ -z $exePid ]; do
getExePid
done
echo $exePid
fi
done