sudo removed
This commit is contained in:
parent
4f24bfeb4d
commit
7c4f48df57
|
@ -0,0 +1,26 @@
|
|||
#!/sbin/runscript
|
||||
|
||||
DAEMON="/usr/local/sbin/snail.watcher"
|
||||
DAEMON_ARGS=""
|
||||
PIDFILE=/var/run/snail.pid
|
||||
PATH=$PATH:/usr/local/bin
|
||||
|
||||
depend() {
|
||||
need localmount
|
||||
}
|
||||
|
||||
start() {
|
||||
ebegin "Starting ${SVCNAME}"
|
||||
start-stop-daemon -m -b --start --exec $DAEMON \
|
||||
--pidfile $PIDFILE \
|
||||
-- $DAEMON_ARGS
|
||||
eend $?
|
||||
}
|
||||
|
||||
stop() {
|
||||
ebegin "Stopping ${SVCNAME}"
|
||||
start-stop-daemon --stop --exec $DAEMON \
|
||||
--pidfile $PIDFILE
|
||||
eend $?
|
||||
}
|
||||
|
|
@ -15,9 +15,13 @@ start() {
|
|||
export LD_LIBRARY_PATH=/usr/lib/opengl/nvidia/lib:/usr/lib/opengl/nvidia/lib
|
||||
start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
|
||||
status=$?
|
||||
# FIXME: remove --background flag and next cycle
|
||||
let i=300
|
||||
while [ 0 -lt $i ]; do snail.nvstat >/dev/null && break; sleep 0.01; let i--; done
|
||||
(nohup snail.autostop &>/dev/null)&
|
||||
while [ 0 -lt $i ]; do
|
||||
[ -f $PIDFILE ] && pgrep -s `cat $PIDFILE` &>/dev/null && break
|
||||
sleep 0.01
|
||||
let i--
|
||||
done
|
||||
eend $status
|
||||
}
|
||||
|
||||
|
@ -27,4 +31,3 @@ stop() {
|
|||
snail.nv_pwr_off || eend -1
|
||||
eend $result
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# /etc/conf.d/local.start
|
||||
|
||||
snail.nv_pwr_off
|
|
@ -4,7 +4,7 @@ PREFIX=/usr/local
|
|||
|
||||
# Tell the system to use xorg-x11 OpenGL libraries and nVidia GLX extensions
|
||||
eselect opengl set xorg-x11
|
||||
for arch in 32bit 64bit; do for chip in i915 i965 r300 r600 sw; do sudo eselect mesa set $arch $chip classic &>/dev/null; done; done
|
||||
for arch in 32bit 64bit; do for chip in i915 i965 r300 r600 sw; do eselect mesa set $arch $chip classic &>/dev/null; done; done
|
||||
|
||||
# Create backups of original xorg.conf.* files and replacing with snail's versions
|
||||
[[ -f /etc/X11/xorg.conf && ! -f /etc/X11/xorg.conf.snail-bkp ]] && mv /etc/X11/xorg.conf /etc/X11/xorg.conf.snail-bkp
|
||||
|
@ -19,9 +19,3 @@ BusIDIntel="PCI:`lspci | grep VGA | grep Intel | cut -d" " -f1 | sed 's~\.~\:~g
|
|||
BusIDNvidia="PCI:`lspci | grep VGA | grep nVidia | cut -d" " -f1 | sed 's~\.~\:~g ; s~0\([0-9]\)~\1~g'`"
|
||||
sed -i "s~BusIDIntel~$BusIDIntel~" /etc/X11/xorg.conf.intel
|
||||
sed -i "s~BusIDNvidia~$BusIDNvidia~" /etc/X11/xorg.conf.nvidia
|
||||
|
||||
# Allow in sudo for %video group to start/stop second X-server with nVidia card and run snail.dmidecode
|
||||
sed -i '/snail/d' /etc/sudoers
|
||||
sudoers_lines=`wc -l /etc/sudoers | cut -d" " -f1`
|
||||
sed -i "${sudoers_lines}a#snail:\n#snail: Allow %video group to start/stop second X-server with nVidia card\n#snail:\n%video ALL= NOPASSWD: /etc/init.d/snail start\n%video ALL= NOPASSWD: /etc/init.d/snail stop\n%video ALL= NOPASSWD: /usr/local/sbin/snail.dmidecode" /etc/sudoers
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Tell the system to use both xorg-x11 OpenGL and GLX libraries
|
||||
eselect opengl set xorg-x11
|
||||
|
||||
# Restore xorg.conf.* files from backups
|
||||
[ -f /etc/X11/xorg.conf.snail-bkp ] && rm -f /etc/X11/xorg.conf && mv /etc/X11/xorg.conf.snail-bkp /etc/X11/xorg.conf
|
||||
[ -f /etc/X11/xorg.conf.intel.snail-bkp ] && rm -f /etc/X11/xorg.conf.intel && mv /etc/X11/xorg.conf.intel.snail-bkp /etc/X11/xorg.conf.intel
|
||||
[ -f /etc/X11/xorg.conf.nvidia.snail-bkp ] && rm -f /etc/X11/xorg.conf.nvidia && mv /etc/X11/xorg.conf.nvidia.snail-bkp /etc/X11/xorg.conf.nvidia
|
||||
|
||||
# Remove backup files
|
||||
for f in "" .intel .nvidia ; do
|
||||
rm -f /etc/X11/xorg.conf${f}.snail-bkp
|
||||
done
|
||||
|
||||
# Remove all Snail files
|
||||
rm -f /etc/X11/xorg.conf.intel.snail
|
||||
rm -f /etc/X11/xorg.conf.nvidia
|
||||
rm -f /etc/init.d/snail-watcher
|
||||
rm -f /etc/init.d/snail-xserver
|
||||
rm -f /usr/local/bin/nvrun
|
||||
rm -f /usr/local/bin/snail.vglrun
|
||||
rm -f /usr/local/lib64/libdlfaker.so
|
||||
rm -f /usr/local/lib64/libgefaker.so
|
||||
rm -f /usr/local/lib64/librrfaker.so
|
||||
rm -f /usr/local/lib64/snail/extensions
|
||||
rm -f /usr/local/lib64/snail/modules/drivers
|
||||
rm -f /usr/local/lib64/snail/modules/extensions
|
||||
rm -f /usr/local/lib64/snail/modules/libfb.so
|
||||
rm -f /usr/local/lib64/snail/modules/libwfb.so
|
||||
rmdir /usr/local/lib64/snail/modules 2>/dev/null
|
||||
rm -f /usr/local/sbin/snail.nv_pwr_off
|
||||
rm -f /usr/local/sbin/snail.nv_pwr_on
|
||||
rm -f /usr/local/sbin/snail.watcher
|
|
@ -1,68 +1,30 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
LOCK_FILE=/tmp/.snail.nvrun.lock
|
||||
NVRUN=snail.nvrun
|
||||
PATH=/usr/local/sbin:/usr/local/bin:$PATH
|
||||
|
||||
(
|
||||
let i=16
|
||||
while [ 0 -lt $i ]; do
|
||||
flock -n 9
|
||||
status=$?
|
||||
TIMEOUT=5 # wait timeout for X server start
|
||||
let INTEL_IF_FAIL=1 # run on Intel if nVidia fails
|
||||
|
||||
if [[ 0 -ne $status && 5 -eq $i ]]; then
|
||||
echo "Cann't lock $COUNT_FILE. Exiting..."
|
||||
exit -1
|
||||
SERVICE=/etc/init.d/snail-xserver
|
||||
PROC=nvrun
|
||||
|
||||
elif [ 0 -eq $status ]; then
|
||||
break
|
||||
fi
|
||||
LOCK_FILE=/tmp/.snail.lock
|
||||
FIFO_FILE=/tmp/.snail.fifo
|
||||
|
||||
sleep 0.01
|
||||
let i--
|
||||
done
|
||||
|
||||
snail.nvstat || snail.nvon
|
||||
{
|
||||
echo -n >$FIFO_FILE
|
||||
flock -w $TIMEOUT -s 9
|
||||
|
||||
if [ 0 -ne $? ]; then
|
||||
echo "Cann't switch on nVidia graphics. Exiting..."
|
||||
exit -1
|
||||
fi
|
||||
if [ 0 -eq $? ]; then
|
||||
echo "Running $@ on nVidia"
|
||||
LD_PRELOAD="/usr/lib/opengl/nvidia/lib/libGL.so:/usr/lib/opengl/nvidia/lib/libnvidia-tls.so" snail.vglrun -d :1 "$@"
|
||||
echo "Application $@ was performed on nVidia"
|
||||
|
||||
) 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 $?
|
||||
elif [ 0 -ne $INTEL_IF_FAIL ]; then
|
||||
echo "Running $@ on Intel"
|
||||
"$@"
|
||||
echo "Application $@ was performed on Intel"
|
||||
fi
|
||||
|
||||
} 9 > $LOCK_FILE
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
sudo /etc/init.d/snail stop
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
sudo /etc/init.d/snail start
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
snail.nvstat
|
||||
|
||||
if [ "$?" == 0 ]; then
|
||||
echo "Running $@ on nVidia Optimus"
|
||||
LD_PRELOAD="/usr/lib/opengl/nvidia/lib/libGL.so:\
|
||||
/usr/lib/opengl/nvidia/lib/libnvidia-tls.so" snail.vglrun -d :1 "$@"
|
||||
echo "Application $@ was performed on nVidia Optimus"
|
||||
|
||||
else
|
||||
echo "Running $@ on Intel GPU"
|
||||
"$@"
|
||||
echo "Application $@ was performed on Intel GPU"
|
||||
fi
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
[ -f /tmp/.X1-lock ] && pgrep -s `cat /tmp/.X1-lock` &>/dev/null
|
||||
|
||||
let status=$?
|
||||
|
||||
[ 0 -eq $status ] && echo "nVidia graphics is ACTIVE" \
|
||||
|| echo "nVidia graphics is NOT ACTIVE"
|
||||
|
||||
exit $status
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
LOCK_FILE=/tmp/.snail.nvrun.lock
|
||||
NVRUN=nvrun
|
||||
|
||||
while [ 1 ]; do
|
||||
if [ ! `pgrep $NVRUN` ]; then
|
||||
|
||||
(
|
||||
for i in 0 1 2 3 4 5; 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
|
||||
done
|
||||
|
||||
snail.nvoff
|
||||
[ 0 -ne $? ] && echo "Error: Cann't switch off nVidia graphics. Exiting..." && exit -1
|
||||
echo "nVidia chip powered off."
|
||||
exit 0
|
||||
) 9>$LOCK_FILE ; exit $?
|
||||
fi
|
||||
|
||||
sleep 0.1
|
||||
done
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
dmidecode $@ -s system-product-name
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
model=`sudo snail.dmidecode`
|
||||
model=`dmidecode $@ -s system-product-name`
|
||||
|
||||
let retry=8
|
||||
while [ 0 -lt $retry ]; do
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
model=`sudo snail.dmidecode`
|
||||
model=`dmidecode $@ -s system-product-name`
|
||||
|
||||
let retry=8
|
||||
while [ 0 -lt $retry ]; do
|
|
@ -1,18 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Tell the system to use both xorg-x11 OpenGL and GLX libraries
|
||||
eselect opengl set xorg-x11
|
||||
|
||||
# Restore xorg.conf.* files from backups
|
||||
[ -f /etc/X11/xorg.conf.snail-bkp ] && rm -f /etc/X11/xorg.conf && mv /etc/X11/xorg.conf.snail-bkp /etc/X11/xorg.conf
|
||||
[ -f /etc/X11/xorg.conf.intel.snail-bkp ] && rm -f /etc/X11/xorg.conf.intel && mv /etc/X11/xorg.conf.intel.snail-bkp /etc/X11/xorg.conf.intel
|
||||
[ -f /etc/X11/xorg.conf.nvidia.snail-bkp ] && rm -f /etc/X11/xorg.conf.nvidia && mv /etc/X11/xorg.conf.nvidia.snail-bkp /etc/X11/xorg.conf.nvidia
|
||||
|
||||
# Remove backup files
|
||||
for f in "" .intel .nvidia ; do
|
||||
rm -f /etc/X11/xorg.conf${f}.snail-bkp
|
||||
done
|
||||
|
||||
# Remove records in sudoers
|
||||
sed -i '/snail/d' /etc/sudoers
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:$PATH
|
||||
|
||||
SERVICE=/etc/init.d/snail-xserver
|
||||
PROC=nvrun
|
||||
|
||||
LOCK_FILE=/tmp/.snail.lock
|
||||
FIFO_FILE=/tmp/.snail.fifo
|
||||
|
||||
$SERVICE stop && snail.nv_pwr_off # stop X service
|
||||
|
||||
touch $LOCK_FILE && chown 0:0 $LOCK_FILE # create lock file
|
||||
rm -f $FIFO_FILE && mkfifo --mode 640 $FIFO_FILE && chgrp video $FIFO_FILE # create fifo
|
||||
|
||||
{
|
||||
echo >$FIFO_FILE | cat <$FIFO_FILE >/dev/null # flush fifo
|
||||
flock -n 9 # make exclusive lock
|
||||
|
||||
while [ 1 ]; do
|
||||
cat <$FIFO_FILE >/dev/null
|
||||
flock -u 9 # unlock to get access for clients
|
||||
flock -n 9
|
||||
if [ 0 -ne $? ]; then # test is $LOCK_FILE locked by any client
|
||||
snail.nv_pwr_on && $SERVICE start # starting X server
|
||||
flock 9
|
||||
echo >$FIFO_FILE | cat <$FIFO_FILE >/dev/null # flush fifo
|
||||
$SERVICE stop && snail.nv_pwr_off # stopping X server
|
||||
fi
|
||||
done
|
||||
} 9 > $LOCK_FILE
|
Loading…
Reference in New Issue