lirc: simplify scripts

This commit is contained in:
Lukas Rusak 2017-02-07 16:41:09 -08:00
parent 8e51cee404
commit 64a31b5378
No known key found for this signature in database
GPG Key ID: 8C310C807E7393A3
4 changed files with 38 additions and 65 deletions

View File

@ -17,52 +17,45 @@
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
ACTION=$(echo "$1")
DEVICE=$(echo "$2" | cut -f1 -d:)
DRIVER=$(echo "$2" | cut -f2 -d:)
CONFIG=$(echo "$2" | cut -f3 -d:)
DEVICE=$(echo "$1" | cut -f1 -d:)
DRIVER=$(echo "$1" | cut -f2 -d:)
CONFIG=$(echo "$1" | cut -f3 -d:)
case "$ACTION" in
add)
if [ "x$DRIVER" = "x" ]; then
exit 1;
fi
if [ "x$DRIVER" = "x" ]; then
exit 1;
fi
mkdir -p '/run/lirc'
mkdir -p '/run/lirc'
if [ ! -e "/run/lirc/lircd-$DEVICE.pid" ]; then
LIRCD="/usr/sbin/lircd"
LIRCD_UINPUT="/usr/sbin/lircd-uinput"
LIRCD_CONFIG="--driver=$DRIVER --device=/dev/$DEVICE"
LIRCD_CONFIG="$LIRCD_CONFIG --output=/run/lirc/lircd-$DEVICE"
LIRCD_CONFIG="$LIRCD_CONFIG --pidfile=/run/lirc/lircd-$DEVICE.pid"
LIRCD_CONFIG="$LIRCD_CONFIG --release=_LIRCUP"
LIRCD="/usr/sbin/lircd"
LIRCD_CONFIG="--driver=$DRIVER --device=/dev/$DEVICE"
LIRCD_CONFIG="$LIRCD_CONFIG --output=/run/lirc/lircd-$DEVICE"
LIRCD_CONFIG="$LIRCD_CONFIG --pidfile=/run/lirc/lircd-$DEVICE.pid"
LIRCD_CONFIG="$LIRCD_CONFIG --release=_LIRCUP"
if [ -e "/storage/.config/lircd.conf" ]; then
LIRCD_CONFIG="$LIRCD_CONFIG /storage/.config/lircd.conf"
elif [ -n "$CONFIG" ]; then
if [ -e "/storage/.config/$CONFIG" ]; then
LIRCD_CONFIG="$LIRCD_CONFIG /storage/.config/$CONFIG"
elif [ -e "/etc/lirc/$CONFIG" ]; then
LIRCD_CONFIG="$LIRCD_CONFIG /etc/lirc/$CONFIG"
else
echo "No device specific $CONFIG file found"
echo "You need to provide your own $CONFIG file"
echo "Place it in /storage/.config/$CONFIG"
exit 0
fi
else
echo "No lircd.conf file found"
echo "You need to provide your own lircd.conf file"
echo "Place it in /storage/.config/lircd.conf"
exit 0
fi
if [ -e "/storage/.config/lircd.conf" ]; then
LIRCD_CONFIG="$LIRCD_CONFIG /storage/.config/lircd.conf"
elif [ -n "$CONFIG" ]; then
if [ -e "/storage/.config/$CONFIG" ]; then
LIRCD_CONFIG="$LIRCD_CONFIG /storage/.config/$CONFIG"
elif [ -e "/etc/lirc/$CONFIG" ]; then
LIRCD_CONFIG="$LIRCD_CONFIG /etc/lirc/$CONFIG"
else
exit 0
fi
else
exit 0
fi
exec $LIRCD $LIRCD_CONFIG
fi
;;
remove)
if [ -e "/run/lirc/lircd-$DEVICE.pid" ]; then
PID=`cat /run/lirc/lircd-$DEVICE.pid`
if [ ! "x$PID" = "x" ]; then
kill $PID
fi
fi
;;
esac
# lircd daemonizes but lircd-uinput doesn't so we need to fork it to the background
$LIRCD $LIRCD_CONFIG
$LIRCD_UINPUT --release=_LIRCUP /run/lirc/lircd-$DEVICE &
exit 0

View File

@ -1,14 +0,0 @@
[Unit]
Description=lircd-uinput with %I
ConditionPathExists=/storage/.cache/services/lircd.conf
[Service]
ExecStart=/usr/sbin/lircd-uinput --release=_LIRCUP /run/lirc/lircd-%I
Slice=system-lircd.slice
Restart=on-failure
RestartSec=2
[Install]
WantedBy=multi-user.target

View File

@ -6,11 +6,11 @@ Requires=lircd-defaults.service
ConditionPathExists=/storage/.cache/services/lircd.conf
[Service]
Type=oneshot
ExecStart=/usr/lib/libreelec/lircd_helper add %I
ExecStop=/usr/lib/libreelec/lircd_helper remove %I
Type=forking
ExecStart=/usr/lib/libreelec/lircd_helper %I
TimeoutStopSec=1
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View File

@ -67,12 +67,6 @@ ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", ACTION=="add", \
TAG+="systemd", ENV{SYSTEMD_WANTS}+="lircd@$name:$env{lircd_driver}:$env{lircd_conf}.service", \
RUN+="lircd_wakeup_enable"
ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", ACTION=="add", \
TAG+="systemd", ENV{SYSTEMD_WANTS}+="lircd-uinput@$name.service"
ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", ACTION=="remove", \
RUN+="/usr/bin/systemctl stop lircd-uinput@$name.service"
ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", ACTION=="remove", \
RUN+="/usr/bin/systemctl stop lircd@$name:$env{lircd_driver}:$env{lircd_conf}.service"