bmc-debug-tools/includes.sh

73 lines
1.6 KiB
Bash
Raw Normal View History

2024-06-13 12:31:56 +02:00
#!/usr/bin/env bash
# Copyright (C) 2024 Adrien 'neox' Bourmault <neox@gnu.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
## SSH Management -------------------------------------------------------------
ssh_bmc()
{
sshpass -p '0penBmc' ssh root@ppalsoc08-bmc ${@}
}
ssh_hst()
{
sshpass -p 'password' ssh neox@ppalsoc08 ${@}
}
## Power Management -----------------------------------------------------------
boot()
{
ssh_bmc /usr/local/bin/asus_power.sh on
}
force_shutdown()
{
ssh_bmc /usr/local/bin/asus_power.sh off
}
shutdown()
{
ssh_hst sudo shutdown now
}
## Logs Management ------------------------------------------------------------
get_logs()
{
ssh_bmc /usr/bin/microcom /dev/ttyS0 -s 115200
}
stop_logs()
{
ssh_bmc killall microcom
}
find_in_logs()
{
keyword=$@
while read line
do
echo -e "${greyblue}${line}${color_reset}" >&2
echo "$line" | grep "$keyword" &> /dev/null
if [ $? -eq 0 ]; then
echo "Found keyword : $line"
stop_logs
fi
done
}
wait_for_expression()
{
get_logs | find_in_logs $@
}