dialog-power-control 1.6 KB

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