dialog-power-control 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. #
  3. # Simple script to show a manual power prompt for when you want to use
  4. # automated hardware testing with testimage.bbclass but you don't have a
  5. # web-enabled power strip or similar to do the power on/off/cycle.
  6. #
  7. # You can enable it by enabling testimage (see the Yocto Project
  8. # Development manual "Performing Automated Runtime Testing" section)
  9. # and setting the following in your local.conf:
  10. #
  11. # TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control"
  12. #
  13. PROMPT=""
  14. while true; do
  15. case $1 in
  16. on)
  17. PROMPT="Please turn device power on";;
  18. off)
  19. PROMPT="Please turn device power off";;
  20. cycle)
  21. PROMPT="Please click Done, then turn the device power off then on";;
  22. "")
  23. break;;
  24. esac
  25. shift
  26. done
  27. if [ "$PROMPT" = "" ] ; then
  28. echo "ERROR: no power action specified on command line"
  29. exit 2
  30. fi
  31. if [ "`which kdialog 2>/dev/null`" != "" ] ; then
  32. DIALOGUTIL="kdialog"
  33. elif [ "`which zenity 2>/dev/null`" != "" ] ; then
  34. DIALOGUTIL="zenity"
  35. else
  36. echo "ERROR: couldn't find program to display a message, install kdialog or zenity"
  37. exit 3
  38. fi
  39. if [ "$DIALOGUTIL" = "kdialog" ] ; then
  40. kdialog --yesno "$PROMPT" --title "TestImage Power Control" --yes-label "Done" --no-label "Cancel test"
  41. elif [ "$DIALOGUTIL" = "zenity" ] ; then
  42. zenity --question --text="$PROMPT" --title="TestImage Power Control" --ok-label="Done" --cancel-label="Cancel test"
  43. fi
  44. if [ "$?" != "0" ] ; then
  45. echo "User cancelled test at power prompt"
  46. exit 1
  47. fi