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