dialog-power-control 1.6 KB

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