This commit is contained in:
Nikolai Rinas
2016-07-29 20:49:49 -07:00
parent 2de9611c89
commit e85b7bc326
12 changed files with 2598 additions and 1 deletions

60
utils/jslisten-init Executable file
View File

@@ -0,0 +1,60 @@
#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides: jslisten
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Listen to the joystick input and run a script on key combination
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d. This example start a
# single forking daemon capable of writing a pid
# file. To get other behavoirs, implemend
# do_start(), do_stop() or other functions to
# override the defaults in /lib/init/init-d-script.
### END INIT INFO
# Author: Nikolai Rinas <nrinas@cube4fun.org>
#
DESC="jslisten daemon"
NAME="jslisten"
PIDFILE="/var/run/${NAME}.pid"
DAEMON="/opt/bin/$NAME"
do_start_cmd() {
start-stop-daemon --start --background --make-pidfile --quiet ${PIDFILE:+--pidfile ${PIDFILE}} \
$START_ARGS \
--startas $DAEMON --name $NAME --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --background --make-pidfile --quiet ${PIDFILE:+--pidfile ${PIDFILE}} \
$START_ARGS \
--startas $DAEMON --name $NAME --exec $DAEMON -- $DAEMON_ARGS \
|| return 2
}
do_stop_cmd_123() {
start-stop-daemon --stop --quiet --retry=TERM/30/INT/5 \
$STOP_ARGS \
${PIDFILE:+--pidfile ${PIDFILE}} --name $NAME --exec $DAEMON
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/INT/5 \
$STOP_ARGS \
--exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return $RETVAL
}

77
utils/modeSwitcher.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/bash
#
# Switch between Kodi and Retropie
#
KODISERVICE="/usr/bin/kodi"
KODIINIT="/etc/init.d/kodi"
X11SERVICE="/usr/sbin/lightdm"
X11INIT="/etc/init.d/lightdm"
RETROSERVICE="emulationstation"
RETROINIT="/etc/init.d/retropie"
KODIRUN="FALSE"
X11RUN="FALSE"
RETRORUN="FALSE"
check_kodi() {
if ps ax | grep -v grep | grep $KODISERVICE > /dev/null ; then
KODIRUN="TRUE"
else
KODIRUN="FALSE"
fi
}
check_lightdm() {
if ps ax | grep -v grep | grep $X11SERVICE > /dev/null ; then
X11RUN="TRUE"
else
X11RUN="FALSE"
fi
}
check_retropie() {
if ps ax | grep -v grep | grep $RETROSERVICE > /dev/null ; then
RETRORUN="TRUE"
else
RETRORUN="FALSE"
fi
}
check_kodi
check_lightdm
check_retropie
# Switch to Kodi
if [ $RETRORUN == "TRUE" ];then
# Stop Retropie service
$RETROINIT stop
# Only if the service was shut down properly
if [ $? == 0 ]; then
# Start lightdm
#$X11INIT start
# Start kodi
chmod g-rw /dev/input/*
$KODIINIT start
fi
exit 0
else
# Shut down lightdm if running
if [ $X11RUN == "TRUE" ]; then
$X11INIT stop
check_lightdm
fi
# Shut down kodi if running
if [ $KODIRUN == "TRUE" ]; then
$KODIINIT stop
check_kodi
fi
# If nothing else is running, start Retropie
if [ $X11RUN == "FALSE" ] && [ $KODIRUN == "FALSE" ]; then
chmod g+rw /dev/input/*
$RETROINIT start
fi
exit 0
fi