br-kodi 929 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. # We're called with the real Kodi executable as
  3. # first argument, followed by any Kodi extra args
  4. KODI="${1}"
  5. shift
  6. # In case someone asked we terminate, just kill
  7. # the Kodi process
  8. trap_kill() {
  9. LOOP=0
  10. killall "${KODI##*/}"
  11. }
  12. trap trap_kill INT QUIT TERM
  13. LOOP=1
  14. while [ ${LOOP} -eq 1 ]; do
  15. # Hack: BusyBox ash does not catch signals while a non-builtin
  16. # is running, and only catches the signal when the non-builtin
  17. # command ends. So, we just background the Kodi binary, and wait
  18. # for it. But BusyBox' ash's wait builtin does not return the
  19. # exit code even if there was only one job (which is correct
  20. # for POSIX). So we explicitly wait for the Kodi job
  21. "${KODI}" "${@}" &
  22. wait %1
  23. ret=$?
  24. case "${ret}" in
  25. 0) ;;
  26. 64) poweroff; LOOP=0;;
  27. 66) reboot; LOOP=0;;
  28. *) # Crash
  29. sleep 1
  30. ;;
  31. esac
  32. done
  33. exit ${ret}