Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
USERNAME=""
IDENTITY=""
IP=""
STATE=""
usage() { echo "Usage: $0 [-u <ssh username> ] [-k <ssh identity file>] [-i <ip address>] [-s <on|off>]" 1>&2; exit 1; }
while getopts "u:k:i:s:" o; do
case "${o}" in
u)
USERNAME=${OPTARG}
;;
k)
IDENTITY=${OPTARG}
;;
i)
IP=${OPTARG}
;;
s)
STATE=${OPTARG}
;;
*)
usage
;;
esac
done
if [ -z "$USERNAME" ]; then usage
fi
if [ -z "$IDENTITY" ]; then usage
fi
if [ -z "$IP" ]; then usage
fi
if [[ "$STATE" != "off" ]] && [[ "$STATE" != "on" ]]; then usage
fi
PARAM=0
ENABLED=false
if [ "$STATE" == "on" ]; then
PARAM=1
ENABLED=true
fi
CONFIG_FILE=/var/etc/persistent/cfg/mgmt
GPIO_FILE=/proc/gpio/led_pattern
ssh -i $IDENTITY $USERNAME@$IP "sed -i 's/mgmt.led_enabled=.*/mgmt.led_enabled=$ENABLED/g' $CONFIG_FILE; echo $PARAM > $GPIO_FILE; cat $CONFIG_FILE | grep led_enabled; cat $GPIO_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment