Snail/usr/local/bin/nvrun

69 lines
1.1 KiB
Plaintext
Raw Normal View History

2011-12-24 00:15:11 +04:00
#!/bin/sh
LOCK_FILE=/tmp/.snail.nvrun.lock
2011-12-25 03:45:06 +04:00
NVRUN=snail.nvrun
2011-12-24 00:15:11 +04:00
(
2012-02-23 22:33:12 +04:00
let i=16
while [ 0 -lt $i ]; do
flock -n 9
2011-12-25 02:55:32 +04:00
status=$?
2011-12-24 00:15:11 +04:00
2011-12-25 02:55:32 +04:00
if [[ 0 -ne $status && 5 -eq $i ]]; then
echo "Cann't lock $COUNT_FILE. Exiting..."
exit -1
2011-12-25 02:55:32 +04:00
elif [ 0 -eq $status ]; then
break
fi
2012-02-23 22:33:12 +04:00
sleep 0.01
let i--
done
2011-12-24 00:15:11 +04:00
snail.nvstat || snail.nvon
if [ 0 -ne $? ]; then
echo "Cann't switch on nVidia graphics. Exiting..."
exit -1
fi
) 9>$LOCK_FILE || exit $?
snail.nvrun "$@"
(
2012-02-23 22:33:12 +04:00
let i=16
while [ 0 -lt $i ]; do
flock -n 9
2011-12-25 02:55:32 +04:00
status=$?
2011-12-24 00:15:11 +04:00
2011-12-25 02:55:32 +04:00
if [[ 0 -ne $status && 5 -eq $i ]]; then
echo "Cann't lock $COUNT_FILE. Exiting..."
exit -1
2011-12-25 02:55:32 +04:00
elif [ 0 -eq $status ]; then
break
fi
2012-02-23 22:33:12 +04:00
sleep 0.01
let i--
done
2011-12-24 00:15:11 +04:00
2011-12-25 03:45:06 +04:00
pgrep $NVRUN &>/dev/null
2011-12-24 00:15:11 +04:00
if [ 0 -eq $? ]; then
echo "Other applications still use nVidia chip. So we aren't switching off it, just exiting..."
exit 0
else
snail.nvoff
[ 0 -ne $? ] && echo "Error: Cann't switch off nVidia graphics. Exiting..." && exit -1
echo "nVidia chip powered off."
exit 0
fi
) 9>$LOCK_FILE
exit $?