Skip to content
This repository has been archived by the owner on Jun 1, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbyWibowo committed Oct 23, 2019
2 parents cf959c4 + 29e412f commit 7ae51fa
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions nvidia-xrun
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ function printHelp {
}

function execute {
if [[ ${DRY_RUN} -eq 1 ]]
then
echo ">>Dry run. Command: $*"
if [[ ${DRY_RUN} -ne 0 ]]; then
echo ">>Dry run. Command: $@"
else
eval $*
eval "$@"
fi
}

Expand Down Expand Up @@ -49,7 +48,7 @@ function turn_on_gpu {
say 'Waiting 1 second'
execute "sleep 1"

if [[ ! -d /sys/bus/pci/devices/${DEVICE_BUS_ID} ]]; then
if [[ ! -d "/sys/bus/pci/devices/${DEVICE_BUS_ID}" ]]; then
say 'Rescanning PCI devices'
execute "sudo $TEE /sys/bus/pci/rescan <<<1"
say "Waiting ${BUS_RESCAN_WAIT_SEC} second for rescan"
Expand Down Expand Up @@ -94,7 +93,8 @@ done

# this is used by the systemd service to turn off the gpu at boot
if [[ "$TURN_OFF_GPU_ONLY" == '1' ]]; then
turn_off_gpu && exit 0
turn_off_gpu
exit 0
fi

if [[ $EUID -eq 0 ]]; then
Expand All @@ -103,26 +103,24 @@ if [[ $EUID -eq 0 ]]; then
fi

# calculate current VT
LVT=`fgconsole`
LVT="$(fgconsole)"

# calculate first usable display
XNUM="-1"
SOCK="something"
while [[ ! -z "$SOCK" ]]
XNUM=0
while [[ -e "/tmp/.X11-unix/X$XNUM" ]]
do
XNUM=$(( $XNUM + 1 ))
SOCK=$(ls -A -1 /tmp/.X11-unix | grep "X$XNUM" )
done

NEWDISP=":$XNUM"

if [[ ! -z "$*" ]] # generate exec line if arguments are given
if [[ -n "$*" ]] # generate exec line if arguments are given
then
# test if executable exists in path
if [[ -x "$(which $1 2> /dev/null)" ]]
if [[ -x "$(which "$1" 2> /dev/null)" ]]
then
# generate exec line
EXECL="$(which $1)"
EXECL="$(which "$1")"
# test if executable exists on disk
elif [[ -e "$(realpath "$1")" ]]
then
Expand Down Expand Up @@ -151,7 +149,7 @@ fi
load_modules

# ---------- EXECUTING COMMAND --------
execute ${COMMAND}
execute "${COMMAND}"

# ---------- UNLOADING MODULES --------
unload_modules
Expand Down

0 comments on commit 7ae51fa

Please sign in to comment.