Files
MIXBOX-ARCHIVE/apps/mixbox/bin/mbdb
2018-12-31 23:47:47 +08:00

65 lines
2.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
#copyright by monlor
mbroot="/etc/mixbox"
#${appname}.main.$key=$value 通过uci更轻松的存储数据
#采用了keyvalue对形式储存数据调用前设置appname和uciname值uciname默认值为info
method="$1"
[ -z "$method" ] && method="help"
appname="$(echo "$2" | awk -F '\.|\=' '{print$1}')"
uciname="$(echo "$2" | awk -F '\.|\=' '{print$2}')"
key="$(echo "$2" | awk -F '\.|\=' '{print$3}')"
value="$(echo "$2" | awk -F '=' '{print$2}')"
configdir=${mbroot}/mbdb
alias uci="uci -c ${configdir}"
case "$method" in
get)
uci -q get ${appname}.${uciname}.${key}
;;
set)
[ ! -f ${configdir}/${appname} ] && touch ${configdir}/${appname}
uci -q get ${appname}.${uciname} &> /dev/null || uci -q set ${appname}.${uciname}=config
uci -q set ${appname}.${uciname}.${key}="${value}"
uci commit ${appname}.${uciname}
;;
del)
uci -q del ${appname}.${uciname}.${key}
;;
keys)
uci -q show ${appname}.${uciname} | sed 1d | sed -e "s/${appname}.${uciname}.//g" | awk -F '=' '{print$1}'
;;
values)
uci -q show ${appname}.${uciname} | sed 1d | sed -e "s/${appname}.${uciname}.//g" | awk -F '=' '{print$2}'
;;
show)
if [ -z "${uciname}" ]; then
uci -q show ${appname}
else
uci -q get ${appname}.${uciname} &> /dev/null && uci -q show ${appname}.${uciname}
fi
;;
clear)
uci -q del ${appname}.${uciname}
;;
export)
[ -z "${uciname}" ] && uciname="main"
uci -q show ${appname}.${uciname} | sed 1d | sed -e "s/${appname}.${uciname}.//g" | awk -F '=' '{print$1"=\""$2"\""}' | tr "\n" ";"
;;
*)
echo "\`mbdb $@\` error!"
echo -e "Usage: $0 {get|set|del|export|show|clean} [key] [value]"
echo -e "Options:"
echo -e "\tget\tGet value by key"
echo -e "\tset\tSet key and value"
echo -e "\tdel\tDelete info by key"
echo -e "\tkeys\tShow all key"
echo -e "\tvalues\tShow all value"
echo -e "\tshow\tShow all key and value"
echo -e "\tclear\tClear all info"
echo -e "\texport\tGet app configure"
exit 1
;;
esac
exit $?