Snail/usr/local/bin/nvrun

63 lines
964 B
Plaintext
Raw Normal View History

2011-12-24 00:15:11 +04:00
#!/bin/sh
LOCK_FILE=/tmp/.snail.nvrun.lock
NVRUN=/usr/local/bin/nvrun
2011-12-24 00:15:11 +04:00
(
for i in `seq 8`; do
flock -n 9
2011-12-24 00:15:11 +04:00
if [[ 0 -ne $? && 5 -eq $i ]]; then
echo "Cann't lock $COUNT_FILE. Exiting..."
exit -1
elif [ 0 -eq $? ]; then
break
fi
sleep 1
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 "$@"
(
for i in `seq 8`; do
flock -n 9
2011-12-24 00:15:11 +04:00
if [[ 0 -ne $? && 5 -eq $i ]]; then
echo "Cann't lock $COUNT_FILE. Exiting..."
exit -1
elif [ 0 -eq $? ]; then
break
fi
sleep 1
done
2011-12-24 00:15:11 +04:00
pgrep -f $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 $?