Fix initial spaces to tabs

This commit is contained in:
Joshua Boniface 2017-03-31 05:41:16 +00:00
parent be3d0efa28
commit 8deb042356
1 changed files with 107 additions and 107 deletions

214
bmc.sh
View File

@ -8,64 +8,64 @@ bmcd_cmdpipe="/run/bmcd/bmcd.cmd"
bmcd_statepipe="/run/bmcd/bmcd.state" bmcd_statepipe="/run/bmcd/bmcd.state"
help() { help() {
echo -e "Available commands:" echo -e "Available commands:"
echo -e " \e[1mstate\e[0m - Show the system power state" echo -e " \e[1mstate\e[0m - Show the system power state"
echo -e " \e[1mconsole\e[0m - Connect to host via serial console; ^A+D to disconnect" echo -e " \e[1mconsole\e[0m - Connect to host via serial console; ^A+D to disconnect"
echo -e " \e[1mpower\e[0m - Press power switch on host" echo -e " \e[1mpower\e[0m - Press power switch on host"
echo -e " \e[1mreset\e[0m - Press reset switch on host" echo -e " \e[1mreset\e[0m - Press reset switch on host"
echo -e " \e[1mkill\e[0m - Forcibly power off host" echo -e " \e[1mkill\e[0m - Forcibly power off host"
echo -e " \e[1mlocate\e[0m - Enable locator (flash power LED)" echo -e " \e[1mlocate\e[0m - Enable locator (flash power LED)"
echo -e " \e[1munlocate\e[0m - Disable locator" echo -e " \e[1munlocate\e[0m - Disable locator"
echo -e " \e[1mhelp\e[0m - This help menu" echo -e " \e[1mhelp\e[0m - This help menu"
echo -e " \e[1mbmc\e[0m - Show BMC information" echo -e " \e[1mbmc\e[0m - Show BMC information"
echo -e " \e[1mhostname\e[0m - Set BMC hostname" echo -e " \e[1mhostname\e[0m - Set BMC hostname"
echo -e " \e[1mpassword\e[0m - Set BMC password" echo -e " \e[1mpassword\e[0m - Set BMC password"
echo -e " \e[1mshell\e[0m - Start a BMC bash shell" echo -e " \e[1mshell\e[0m - Start a BMC bash shell"
echo -e " \e[1mexit/logout\e[0m - Disconnect from the BMC" echo -e " \e[1mexit/logout\e[0m - Disconnect from the BMC"
} }
bmcinfo() { bmcinfo() {
echo -e "BMC information:" echo -e "BMC information:"
echo -e " IP address: $( ip -4 addr list eth0 | grep inet | awk '{ print $2 }' )" echo -e " IP address: $( ip -4 addr list eth0 | grep inet | awk '{ print $2 }' )"
echo -e " Hostname: $( hostname )" echo -e " Hostname: $( hostname )"
echo -e " BMC temperature: $( sudo /opt/vc/bin/vcgencmd measure_temp | awk -F'=' '{ print $2 }' )" echo -e " BMC temperature: $( sudo /opt/vc/bin/vcgencmd measure_temp | awk -F'=' '{ print $2 }' )"
} }
sethostname() { sethostname() {
echo -n "Enter new hostname: " echo -n "Enter new hostname: "
read newhostname read newhostname
sudo sed -i '/^127.0.1.1/d' /etc/hosts &>/dev/null sudo sed -i '/^127.0.1.1/d' /etc/hosts &>/dev/null
sudo tee -a /etc/hosts <<<"127.0.1.1 $newhostname" &>/dev/null sudo tee -a /etc/hosts <<<"127.0.1.1 $newhostname" &>/dev/null
sudo hostname $newhostname &>/dev/null sudo hostname $newhostname &>/dev/null
sudo tee /etc/hostname <<<"$newhostname" &>/dev/null sudo tee /etc/hostname <<<"$newhostname" &>/dev/null
echo "Hostname set to $newhostname" echo "Hostname set to $newhostname"
} }
setpassword() { setpassword() {
echo -n "Enter new BMC password: " echo -n "Enter new BMC password: "
read -s password_1 read -s password_1
echo echo
echo -n "Reenter new BMC password: " echo -n "Reenter new BMC password: "
read -s password_2 read -s password_2
echo echo
if [ "${password_1}" == "${password_2}" ]; then if [ "${password_1}" == "${password_2}" ]; then
echo -n "Setting BMC password... " echo -n "Setting BMC password... "
sudo chpasswd <<<"bmc:${password_1}" sudo chpasswd <<<"bmc:${password_1}"
echo "done." echo "done."
else else
echo "Passwords to not match!" echo "Passwords to not match!"
fi fi
} }
resetsw_press() { resetsw_press() {
echo "Pressing reset switch." echo "Pressing reset switch."
echo "resetsw_press" > ${bmcd_cmdpipe} echo "resetsw_press" > ${bmcd_cmdpipe}
} }
powersw_press() { powersw_press() {
echo "Pressing power switch." echo "Pressing power switch."
echo "powersw_press" > ${bmcd_cmdpipe} echo "powersw_press" > ${bmcd_cmdpipe}
sleep 2 sleep 2
} }
powersw_hold() { powersw_hold() {
echo "Holding power switch." echo "Holding power switch."
echo "powersw_hold" > ${bmcd_cmdpipe} echo "powersw_hold" > ${bmcd_cmdpipe}
sleep 2 sleep 2
} }
locate_on() { locate_on() {
echo "Enabling locator - host power LED will flash." echo "Enabling locator - host power LED will flash."
@ -76,12 +76,12 @@ locate_off() {
echo "locate_off" > ${bmcd_cmdpipe} echo "locate_off" > ${bmcd_cmdpipe}
} }
readpower() { readpower() {
powerstate_raw=$(cat ${bmcd_statepipe}) powerstate_raw=$(cat ${bmcd_statepipe})
if [[ "${powerstate_raw}" -eq 1 ]]; then if [[ "${powerstate_raw}" -eq 1 ]]; then
powerstate="\e[32mOn\e[0m" powerstate="\e[32mOn\e[0m"
else else
powerstate="\e[31mOff\e[0m" powerstate="\e[31mOff\e[0m"
fi fi
} }
readpower readpower
@ -101,36 +101,36 @@ stty intr undef
echo -en "\e[1m\e[34m[$(hostname)]>\e[0m " echo -en "\e[1m\e[34m[$(hostname)]>\e[0m "
read input read input
case $input in case $input in
'state') 'state')
readpower readpower
echo -e "Host state: $powerstate" echo -e "Host state: $powerstate"
echo echo
;; ;;
'console') 'console')
echo "Starting console..." echo "Starting console..."
# Connect to screen, or start it # Connect to screen, or start it
sudo screen -r serialconsole &>/dev/null || sudo screen -S serialconsole /dev/ttyUSB0 115200 sudo screen -r serialconsole &>/dev/null || sudo screen -S serialconsole /dev/ttyUSB0 115200
# If the user killed screen, restart it - just in case # If the user killed screen, restart it - just in case
pgrep screen &>/dev/null || sudo screen -S serialconsole /dev/ttyUSB0 115200 pgrep screen &>/dev/null || sudo screen -S serialconsole /dev/ttyUSB0 115200
echo echo
;; ;;
'power') 'power')
powersw_press powersw_press
readpower readpower
echo -e "Host state: $powerstate" echo -e "Host state: $powerstate"
echo echo
;; ;;
'reset') 'reset')
resetsw_press resetsw_press
readpower readpower
echo -e "Host state: $powerstate" echo -e "Host state: $powerstate"
echo echo
;; ;;
'kill') 'kill')
powersw_hold powersw_hold
readpower readpower
echo -e "Host state: $powerstate" echo -e "Host state: $powerstate"
echo echo
;; ;;
'locate') 'locate')
locate_on locate_on
@ -139,38 +139,38 @@ case $input in
'unlocate') 'unlocate')
locate_off locate_off
echo echo
;; ;;
'help') 'help')
help help
echo echo
;; ;;
'bmc') 'bmc')
bmcinfo bmcinfo
echo echo
;; ;;
'hostname') 'hostname')
sethostname sethostname
echo echo
;; ;;
'password') 'password')
setpassword setpassword
echo echo
;; ;;
'shell') 'shell')
stty sane stty sane
/bin/bash /bin/bash
help help
echo echo
;; ;;
'exit'|'logout') 'exit'|'logout')
exit 0 exit 0
;; ;;
'') '')
continue continue
;; ;;
*) *)
echo "Invalid command." echo "Invalid command."
echo echo
;; ;;
esac esac
done done