
function _get() {
  local FILE
  for SD in etc etc.defaults; do
    FILE="/${SD}/synoinfo.conf"
    VALUE=`grep "${2}" ${FILE} | sed "s|^${2}=\"\(.*\)\"$|\1|g"`
    printf "%30s -- %20s -- %s\n" ${FILE} ${2} ${VALUE} 
  done
}


function _set() {
  local FILE
  for SD in etc etc.defaults; do
    FILE="/${SD}/synoinfo.conf"
    # Replace
    if grep -q "^$2=" ${FILE}; then
      printf "[D] mod %30s $2 to $3\n" ${FILE} 
      sed -i -e "s\"^$2=.*\"$2=\\\"$3\\\"\"" ${FILE}
    else
      printf "[D] add %30s $2 to $3\n" ${FILE}
      echo "$2=\"$3\"" >> ${FILE}
    fi
  done
}

function _usage() {
    cat << EOF
Usage: 
   $0 get [KEY]
   $0 set [KEY] [VALUE]

By:
  此脚本由 淘宝 Tank电玩[http://mi-d.cn] 提供, 感谢您的支持.
EOF
}

echo '### 本工具由 淘宝 Tank电玩[http://mi-d.cn] 维护 (v1.0.0) ###'
if [ "${1}" = "get" -a $# -eq 2 ]; then
  _get $@
elif [ "${1}" = "set" -a $# -eq 3 ]; then
  _set $@
else
  _usage
  exit 1
fi