instant_play 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. # Uncomment the following line to get debug info
  3. #set -x
  4. SELF="$(basename ${0})"
  5. INSTANT_PLAY_FILE="/mnt/instant_play"
  6. RESUME_PLAY_FILE="/mnt/resume_play"
  7. LAST_OPK_FILE="/mnt/last_opk"
  8. usage() {
  9. >&2 echo "Usage: ${SELF} load"
  10. >&2 echo " ${SELF} save application args..."
  11. exit 1
  12. }
  13. # Check number of arguments
  14. if [ ${#} -lt 1 ]; then
  15. usage
  16. fi
  17. case ${1} in
  18. load)
  19. if [ ${#} -ne 1 ]; then
  20. usage
  21. fi
  22. # Umount any remaining OPK, if any
  23. umount /opk >/dev/null 2>&1
  24. # Mount last OPK, if any
  25. if [ -r "${LAST_OPK_FILE}" ]; then
  26. last_opk=$(cat "${LAST_OPK_FILE}")
  27. mount -t squashfs "${last_opk}" /opk
  28. fi
  29. # Launch Previous Game if any
  30. if [ -f "${INSTANT_PLAY_FILE}" ]; then
  31. keymap resume
  32. echo -n "Found Instant Play file, restarting previous game with command: "
  33. echo $(head -n 1 "${INSTANT_PLAY_FILE}")
  34. rm -f "${RESUME_PLAY_FILE}"
  35. mv "${INSTANT_PLAY_FILE}" "${RESUME_PLAY_FILE}"
  36. source "${RESUME_PLAY_FILE}"
  37. rm -f "${RESUME_PLAY_FILE}"
  38. if [ -r "${LAST_OPK_FILE}" ]; then
  39. umount /opk
  40. rm "${LAST_OPK_FILE}"
  41. fi
  42. keymap default
  43. termfix_all
  44. fi
  45. ;;
  46. save)
  47. if [ ${#} -lt 2 ]; then
  48. usage
  49. fi
  50. shift
  51. # Write quick load file args
  52. echo -n "" > "${INSTANT_PLAY_FILE}"
  53. for arg in "$@"; do
  54. # Add quotes around all arguments
  55. echo -n "'${arg}' " >> "${INSTANT_PLAY_FILE}"
  56. done
  57. # Add the magic sauce to launch the process in background,
  58. # record the PID into a file, wait for the process to
  59. # terminate and erase the recorded PID
  60. cat << EOF >> "${INSTANT_PLAY_FILE}"
  61. &
  62. pid record \$!
  63. wait \$!
  64. pid erase
  65. EOF
  66. # Now terminate gracefully
  67. exec powerdown now
  68. ;;
  69. *)
  70. usage
  71. ;;
  72. esac
  73. exit 0