#!/bin/sh LOCK_FILE=/tmp/.snail.nvrun.lock NVRUN=snail.nvrun ( let i=16 while [ 0 -lt $i ]; do flock -n 9 status=$? if [[ 0 -ne $status && 5 -eq $i ]]; then echo "Cann't lock $COUNT_FILE. Exiting..." exit -1 elif [ 0 -eq $status ]; then break fi sleep 0.01 let i-- done 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 "$@" ( let i=16 while [ 0 -lt $i ]; do flock -n 9 status=$? if [[ 0 -ne $status && 5 -eq $i ]]; then echo "Cann't lock $COUNT_FILE. Exiting..." exit -1 elif [ 0 -eq $status ]; then break fi sleep 0.01 let i-- done pgrep $NVRUN &>/dev/null 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 $?