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
|
#!/bin/bash
function custom_get_state ()
{
bootname=$1
ret=$(grep "STATE_${bootname}" "$CUSTOM_STATE_PATH"| sed 's/.*=\(.*\)/\1/')
echo "$ret"
}
function custom_set_state ()
{
bootname=$1
good=$2
sed -i "s/\(STATE_${bootname}=\).*/\1${good}/" "${CUSTOM_STATE_PATH}"
}
function custom_get_primary ()
{
bootname=$(grep PRIMARY "$CUSTOM_STATE_PATH" | sed 's/.*=\(.*\)/\1/')
# Found primary. Checking whether the primary is valid
ret=$(grep "STATE_${bootname}" "$CUSTOM_STATE_PATH" | sed 's/.*=\(.*\)/\1/')
if [ "x${ret}" = "xgood" ]; then
echo "$bootname"
fi
}
function custom_set_primary ()
{
bootname=$1
sed -i "s/\(PRIMARY=\).*/\1${bootname}/" "${CUSTOM_STATE_PATH}"
}
function custom_get_current ()
{
echo $(grep CURRENT "$CUSTOM_STATE_PATH" | sed 's/.*=\(.*\)/\1/')
}
if [ "$1" = "get-state" ]; then
shift
custom_get_state "$@"
elif [ "$1" = "set-state" ]; then
shift
custom_set_state "$@"
elif [ "$1" = "get-primary" ]; then
shift
custom_get_primary "$@"
elif [ "$1" = "set-primary" ]; then
shift
custom_set_primary "$@"
elif [ "$1" = "get-current" ]; then
shift
custom_get_current "$@"
fi
|