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