Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
| 16 | PROMPT="" |
| 17 | while true; do |
| 18 | case $1 in |
| 19 | on) |
| 20 | PROMPT="Please turn device power on";; |
| 21 | off) |
| 22 | PROMPT="Please turn device power off";; |
| 23 | cycle) |
| 24 | PROMPT="Please click Done, then turn the device power off then on";; |
| 25 | "") |
| 26 | break;; |
| 27 | esac |
| 28 | shift |
| 29 | done |
| 30 | |
| 31 | if [ "$PROMPT" = "" ] ; then |
| 32 | echo "ERROR: no power action specified on command line" |
| 33 | exit 2 |
| 34 | fi |
| 35 | |
| 36 | if [ "`which kdialog 2>/dev/null`" != "" ] ; then |
| 37 | DIALOGUTIL="kdialog" |
| 38 | elif [ "`which zenity 2>/dev/null`" != "" ] ; then |
| 39 | DIALOGUTIL="zenity" |
| 40 | else |
| 41 | echo "ERROR: couldn't find program to display a message, install kdialog or zenity" |
| 42 | exit 3 |
| 43 | fi |
| 44 | |
| 45 | if [ "$DIALOGUTIL" = "kdialog" ] ; then |
| 46 | kdialog --yesno "$PROMPT" --title "TestImage Power Control" --yes-label "Done" --no-label "Cancel test" |
| 47 | elif [ "$DIALOGUTIL" = "zenity" ] ; then |
| 48 | zenity --question --text="$PROMPT" --title="TestImage Power Control" --ok-label="Done" --cancel-label="Cancel test" |
| 49 | fi |
| 50 | |
| 51 | if [ "$?" != "0" ] ; then |
| 52 | echo "User cancelled test at power prompt" |
| 53 | exit 1 |
| 54 | fi |
| 55 | |