Merge pull request #431 from rogerpueyo/p4u/luci-app-bmx7/refactory
Fix bmx7-info indentation and "$info" call
This commit is contained in:
commit
3264d15492
1 changed files with 13 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright © 2011 Pau Escrich
|
# Copyright © 2011 Pau Escrich
|
||||||
# Contributors Jo-Philipp Wich <xm@subsignal.org>
|
# Contributors Jo-Philipp Wich <xm@subsignal.org>
|
||||||
# Roger Pueyo Centelles <roger.pueyo@guifi.net>
|
# Roger Pueyo Centelles <roger.pueyo@guifi.net>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -34,13 +34,12 @@ else
|
||||||
QUERY="${QUERY_STRING%%=*}"
|
QUERY="${QUERY_STRING%%=*}"
|
||||||
echo "Content-type: application/json"
|
echo "Content-type: application/json"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
check_path() {
|
check_path() {
|
||||||
[ -d "$1" ] && path=$(cd $1; pwd)
|
[ -d "$1" ] && path=$(cd $1; pwd)
|
||||||
[ -f "$1" ] && path=$(cd $1/..; pwd)
|
[ -f "$1" ] && path=$(cd $1/..; pwd)
|
||||||
[ $(echo "$path" | grep -c "^$BMX7_DIR") -ne 1 ] && exit 1
|
[ $(echo "$path" | grep -c "^$BMX7_DIR") -ne 1 ] && exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
print_mem() {
|
print_mem() {
|
||||||
|
@ -52,19 +51,19 @@ print_mem() {
|
||||||
print_query() {
|
print_query() {
|
||||||
# If the query is a directory
|
# If the query is a directory
|
||||||
[ -d "$BMX7_DIR/$1" ] &&
|
[ -d "$BMX7_DIR/$1" ] &&
|
||||||
{
|
{
|
||||||
# If /all has not been specified
|
# If /all has not been specified
|
||||||
[ -z "$QALL" ] &&
|
[ -z "$QALL" ] &&
|
||||||
{
|
{
|
||||||
total=$(ls $BMX7_DIR/$1 | wc -w)
|
total=$(ls $BMX7_DIR/$1 | wc -w)
|
||||||
i=1
|
i=1
|
||||||
echo -n "{ \"$1\": [ "
|
echo -n "{ \"$1\": [ "
|
||||||
for f in $(ls $BMX7_DIR/$1); do
|
for f in $(ls $BMX7_DIR/$1); do
|
||||||
echo -n "{ \"name\": \"$f\" }"
|
echo -n "{ \"name\": \"$f\" }"
|
||||||
[ $i -lt $total ] && echo -n ','
|
[ $i -lt $total ] && echo -n ','
|
||||||
i=$(( $i + 1 ))
|
i=$(( $i + 1 ))
|
||||||
done
|
done
|
||||||
echo -n " ] }"
|
echo -n " ] }"
|
||||||
|
|
||||||
# If /all has been specified, printing all the files together
|
# If /all has been specified, printing all the files together
|
||||||
} || {
|
} || {
|
||||||
|
@ -80,10 +79,10 @@ print_query() {
|
||||||
done
|
done
|
||||||
echo -n " ]"
|
echo -n " ]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# If the query is a file, just printing the file
|
# If the query is a file, just printing the file
|
||||||
[ -f "$BMX7_DIR/$1" ] && cat "$BMX7_DIR/$1";
|
[ -f "$BMX7_DIR/$1" ] && [ -s "$BMX7_DIR/$1" ] && cat "$BMX7_DIR/$1" && return 0 || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "${QUERY##*/}" == "all" ]; then
|
if [ "${QUERY##*/}" == "all" ]; then
|
||||||
|
@ -95,10 +94,8 @@ if [ "$QUERY" == '$info' ]; then
|
||||||
echo '{ "info": [ '
|
echo '{ "info": [ '
|
||||||
print_query status
|
print_query status
|
||||||
echo -n ","
|
echo -n ","
|
||||||
print_query interfaces
|
print_query interfaces && echo -n "," || echo -n '{ "interfaces": "" },'
|
||||||
echo -n ","
|
print_query links && echo -n "," || echo -n '{ "links": "" },'
|
||||||
print_query links
|
|
||||||
echo -n ","
|
|
||||||
print_mem
|
print_mem
|
||||||
echo "] }"
|
echo "] }"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue