shimboot/bootloader/opt/crossystem

79 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/bash
#a much cleaner implemenation of fakemurk's crossystem.sh
crossystem_old=/tmp/crossystem_old
2023-11-11 01:49:59 -06:00
declare -A crossystem_dict=(
["cros_debug"]="1"
["dev_boot_legacy"]="0"
["dev_boot_signed_only"]="1"
["devsw_boot"]="0"
["devsw_cur"]="0"
["block_devmode"]="1"
["mainfw_act"]="A"
["mainfw_type"]="normal"
["recovery_reason"]="0"
["recovery_request"]="0"
["recoverysw_boot"]="0"
["recoverysw_cur"]="0"
)
dict_get() {
2023-11-11 01:49:59 -06:00
echo "${crossystem_dict[$1]}"
}
parse_arg() {
local arg="$1"
#set values mode - pass this through without changes
if [[ "$arg" =~ "=" ]]; then
$crossystem_old "$@"
#search value mode
elif [[ "$arg" =~ "?" ]]; then
key=$(echo $arg | cut -d "?" -f 1)
query=$(echo $arg | cut -d "?" -f 2)
2023-11-11 01:49:59 -06:00
if ! [ "${crossystem_dict[$key]}" = "$query" ]; then
exit 1
fi
#get value mode
2023-11-11 01:49:59 -06:00
elif [ "${crossystem_dict[$arg]}" ]; then
printf "${crossystem_dict[$arg]}"
#value not found - print help and exit
else
$crossystem_old --help
exit 1
fi
}
crossystem_out="$($crossystem_old)"
#crossystem_out=$(cat data/crossystem.txt)
#add crossystem output to the dict
while IFS= read -r line; do
line=$(echo $line | cut -d "#" -f 1)
key=$(echo $line | cut -d "=" -f 1 | xargs)
value=$(echo $line | cut -d "=" -f 2 | xargs)
2023-11-11 01:49:59 -06:00
if [ -z "${crossystem_dict[$key]}" ]; then
crossystem_dict["$key"]="$value"
fi
done <<< "$crossystem_out"
#crossystem called with no arguments, print out all properties
if [ -z "$1" ] || [ "$1" = "--all" ]; then
2023-11-11 01:49:59 -06:00
keys="${!crossystem_dict[@]}"
keys="$(echo "$keys" | tr " " "\n" | sort)"
for key in $keys; do
value="${crossystem_dict[$key]}"
echo "$key = $value"
2023-11-11 01:49:59 -06:00
done
exit 0
fi
for arg in "$@"; do
parse_arg $arg
done