Add comments and standard headers for publication
This commit is contained in:
221
bmc.sh
221
bmc.sh
@ -1,5 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# bmc.sh - BMC command shell
|
||||
#
|
||||
# This program works as the main user shell for the RPi BMC. It provides a
|
||||
# command-line interface for interfacing with the running bmcd daemon
|
||||
# program as well as a few distinct functions such as a serial console, as
|
||||
# well as managing the BMC itself (e.g. BMC hostname, IP address, or host
|
||||
# system name. It is designed to be started automatically on login to the
|
||||
# BMC as the 'bmc' user, e.g. with the following passwd file entry:
|
||||
# bmc:x:2000:2000:BMC:/home/dir:/path/to/bmc.sh
|
||||
#
|
||||
# Has dependencies on the 'bmcd' and 'screen' utilities.
|
||||
#
|
||||
# Part of the RPiBMC project - (c)2017 Joshua Boniface
|
||||
# This software is licenced under the terms of the GNU GPL version 3. For
|
||||
# details please see LICENSE
|
||||
#
|
||||
|
||||
stty eof undef
|
||||
stty intr undef
|
||||
|
||||
@ -79,7 +97,10 @@ readpower() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Read the power state
|
||||
readpower
|
||||
|
||||
# Print our login splash
|
||||
echo
|
||||
echo -e "--------------------"
|
||||
echo -e "| Raspberry Pi BMC |"
|
||||
@ -90,102 +111,108 @@ echo -e "Host state: ${powerstate}"
|
||||
echo
|
||||
help
|
||||
echo
|
||||
|
||||
# Main loop
|
||||
while true; do
|
||||
stty eof undef
|
||||
stty intr undef
|
||||
echo -en "\e[1m\e[34m[$(hostname)]>\e[0m "
|
||||
read input
|
||||
case ${input} in
|
||||
'state')
|
||||
readpower
|
||||
echo -e "Host state: ${powerstate}"
|
||||
echo
|
||||
;;
|
||||
'console')
|
||||
echo "Starting console..."
|
||||
# Connect to screen, or start it
|
||||
sudo screen -r serialconsole &>/dev/null || sudo screen -S serialconsole /dev/ttyUSB0 115200
|
||||
# If the user killed screen, restart it - just in case
|
||||
pgrep screen &>/dev/null || sudo screen -S serialconsole /dev/ttyUSB0 115200
|
||||
echo
|
||||
;;
|
||||
'power')
|
||||
powersw_press
|
||||
readpower
|
||||
echo -e "Host state: ${powerstate}"
|
||||
echo
|
||||
;;
|
||||
'reset')
|
||||
resetsw_press
|
||||
echo
|
||||
;;
|
||||
'kill')
|
||||
powersw_hold
|
||||
readpower
|
||||
echo -e "Host state: ${powerstate}"
|
||||
echo
|
||||
;;
|
||||
'locate')
|
||||
locate_on
|
||||
echo
|
||||
;;
|
||||
'unlocate')
|
||||
locate_off
|
||||
echo
|
||||
;;
|
||||
'help')
|
||||
help
|
||||
echo
|
||||
;;
|
||||
'bmc')
|
||||
bmcinfo
|
||||
echo
|
||||
;;
|
||||
'hostname')
|
||||
echo -n "Enter new hostname: "
|
||||
read newhostname
|
||||
sethostname ${newhostname}
|
||||
echo
|
||||
;;
|
||||
'host')
|
||||
echo -n "Enter new host system name: "
|
||||
read newhost
|
||||
sethost ${newhost}
|
||||
echo -n "Update BMC hostname to '${newhost}-bmc'? (y/N) "
|
||||
read updatehostnameyn
|
||||
if [[ "${updatehostnameyn}" =~ "y" ]]; then
|
||||
sethostname "${newhost}-bmc"
|
||||
fi
|
||||
;;
|
||||
'password')
|
||||
echo -n "Enter new BMC password: "
|
||||
read -s password_1
|
||||
echo
|
||||
echo -n "Reenter new BMC password: "
|
||||
read -s password_2
|
||||
echo
|
||||
if [ "${password_1}" == "${password_2}" ]; then
|
||||
setpassword "${password_1}"
|
||||
else
|
||||
echo "Passwords to not match!"
|
||||
fi
|
||||
echo
|
||||
;;
|
||||
'shell')
|
||||
stty sane
|
||||
/bin/bash
|
||||
help
|
||||
echo
|
||||
;;
|
||||
'exit'|'logout')
|
||||
exit 0
|
||||
;;
|
||||
'')
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
echo "Invalid command."
|
||||
echo
|
||||
;;
|
||||
esac
|
||||
stty eof undef
|
||||
stty intr undef
|
||||
|
||||
# Prompt
|
||||
echo -en "\e[1m\e[34m[$(hostname)]>\e[0m "
|
||||
# Read input
|
||||
read input
|
||||
# Process input
|
||||
case ${input} in
|
||||
'state')
|
||||
readpower
|
||||
echo -e "Host state: ${powerstate}"
|
||||
echo
|
||||
;;
|
||||
'console')
|
||||
echo "Starting console..."
|
||||
# Connect to screen, or start it
|
||||
sudo screen -r serialconsole &>/dev/null || sudo screen -S serialconsole /dev/ttyUSB0 115200
|
||||
# If the user killed screen, restart it - just in case
|
||||
pgrep screen &>/dev/null || sudo screen -S serialconsole /dev/ttyUSB0 115200
|
||||
echo
|
||||
;;
|
||||
'power')
|
||||
powersw_press
|
||||
readpower
|
||||
echo -e "Host state: ${powerstate}"
|
||||
echo
|
||||
;;
|
||||
'reset')
|
||||
resetsw_press
|
||||
echo
|
||||
;;
|
||||
'kill')
|
||||
powersw_hold
|
||||
readpower
|
||||
echo -e "Host state: ${powerstate}"
|
||||
echo
|
||||
;;
|
||||
'locate')
|
||||
locate_on
|
||||
echo
|
||||
;;
|
||||
'unlocate')
|
||||
locate_off
|
||||
echo
|
||||
;;
|
||||
'help')
|
||||
help
|
||||
echo
|
||||
;;
|
||||
'bmc')
|
||||
bmcinfo
|
||||
echo
|
||||
;;
|
||||
'hostname')
|
||||
echo -n "Enter new hostname: "
|
||||
read newhostname
|
||||
sethostname ${newhostname}
|
||||
echo
|
||||
;;
|
||||
'host')
|
||||
echo -n "Enter new host system name: "
|
||||
read newhost
|
||||
sethost ${newhost}
|
||||
echo -n "Update BMC hostname to '${newhost}-bmc'? (y/N) "
|
||||
read updatehostnameyn
|
||||
if [[ "${updatehostnameyn}" =~ "y" ]]; then
|
||||
sethostname "${newhost}-bmc"
|
||||
fi
|
||||
;;
|
||||
'password')
|
||||
echo -n "Enter new BMC password: "
|
||||
read -s password_1
|
||||
echo
|
||||
echo -n "Reenter new BMC password: "
|
||||
read -s password_2
|
||||
echo
|
||||
if [ "${password_1}" == "${password_2}" ]; then
|
||||
setpassword "${password_1}"
|
||||
else
|
||||
echo "Passwords to not match!"
|
||||
fi
|
||||
echo
|
||||
;;
|
||||
'shell')
|
||||
stty sane
|
||||
/bin/bash
|
||||
help
|
||||
echo
|
||||
;;
|
||||
'exit'|'logout')
|
||||
exit 0
|
||||
;;
|
||||
'')
|
||||
continue
|
||||
;;
|
||||
*)
|
||||
echo "Invalid command."
|
||||
echo
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
Reference in New Issue
Block a user