-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.in
64 lines (55 loc) · 1.53 KB
/
profile.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
#
# YADRO OpenBMC Command Line Interface
# Default profile
# Copyright (C) 2020-2021 YADRO
#
# SPDX-License-Identifier: Apache-2.0
#
# greeting
cat << EOF
Welcome to BMC Command Line Interface for $(sed -n 's/OPENBMC_TARGET_MACHINE="\(.*\)"/\1/p' /etc/os-release)!
Copyright (C) 2020-2021 YADRO
EOF
# Watchdog status 0x20 shows us that we are booted from the golden side
WDIOF_CARDRESET=0x20
WDSTATUS=$(cat /sys/class/watchdog/watchdog1/status)
if (( WDSTATUS & WDIOF_CARDRESET )); then
cat << EOF
WARNING: BMC is booted up in recovery mode (from golden flash)!
EOF
fi
cat << EOF
Type 'help' to print the list of available CLI commands.
EOF
# replace built-in help command
alias helpsh="builtin help"
function help {
local fmt="%-12s %s\n"
local cmd desc
local role
role=$(user myrole)
if [[ -z "${role}" ]]; then
echo "Your system role is unknown, can't help you"
return
fi
while read cmd desc; do
printf "${fmt}" "${cmd}" "${desc}"
done < "/usr/share/cli/help.${role}"
# static help lines
printf "${fmt}" "helpsh" "Print shell help"
printf "${fmt}" "help" "Print this help"
}
# callback function for bash autocomplete
function _cli_completion {
local cmd="${COMP_WORDS[0]}"
local subcmd
local words
subcmd="$(echo "${COMP_WORDS[*]:1}" | sed 's/\w\+$//')"
words="$(${cmd} autocomplete ${subcmd})"
if [[ -z "${words}" ]] && [[ ${COMP_CWORD} -gt 2 ]]; then
COMPREPLY=($(compgen -f -- ${COMP_WORDS[COMP_CWORD]}))
else
COMPREPLY=($(compgen -W "${words}" -- ${COMP_WORDS[COMP_CWORD]}))
fi
}