Vijay Khemka | 45269ba | 2018-12-13 11:07:06 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Usage of this utility |
| 3 | function usage() { |
| 4 | echo "usage: power-util mb 1 [on|off]"; |
| 5 | } |
| 6 | |
| 7 | GPIO_BASE=$(cat /sys/class/gpio/gpio*/base) |
| 8 | PWR_GPIO=$(($GPIO_BASE + 32 + 3)) |
| 9 | BMC_RDY_GPIO=$(($GPIO_BASE + 144 +1)) |
| 10 | |
| 11 | if [ $# -lt 3 ]; then |
| 12 | echo "Total number of parameter=$#" |
| 13 | echo "Insufficient parameter" |
| 14 | usage; |
| 15 | exit 0; |
| 16 | fi |
| 17 | |
| 18 | if [ $1 != "mb" ]; then |
| 19 | echo "Invalid parameter1=$1" |
| 20 | usage; |
| 21 | exit 0; |
| 22 | fi |
| 23 | |
| 24 | if [ $2 -ne 1 ]; then |
| 25 | echo "Invalid parameter2=$2, Server $2 not supported" |
| 26 | usage; |
| 27 | exit 0; |
| 28 | fi |
| 29 | |
| 30 | if [ $3 = "on" ]; then |
| 31 | echo "Powering on Server $2" |
| 32 | echo 0 > /sys/class/gpio/gpio${BMC_RDY_GPIO}/value |
| 33 | echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 34 | echo 0 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 35 | sleep 1 |
| 36 | echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 37 | elif [ $3 = "off" ]; then |
| 38 | echo "Shutting down Server $2" |
| 39 | echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 40 | sleep 1 |
| 41 | echo 0 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 42 | sleep 6 |
| 43 | echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value |
| 44 | else |
| 45 | echo "Invalid parameter3=$3" |
| 46 | usage; |
| 47 | fi |
| 48 | |
| 49 | exit 0; |