Signed-off-by: Roger Pueyo Centelles <roger.pueyo@guifi.net>
#!/bin/sh
# Copyright © 2011 Pau Escrich
# Contributors Jo-Philipp Wich <xm@subsignal.org>
#!/bin/sh
# Copyright © 2011 Pau Escrich
# 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
# it under the terms of the GNU General Public License as published by
#
# 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
QUERY="${QUERY_STRING%%=*}"
echo "Content-type: application/json"
echo ""
QUERY="${QUERY_STRING%%=*}"
echo "Content-type: application/json"
echo ""
- [ -d "$1" ] && path=$(cd $1; pwd)
- [ -f "$1" ] && path=$(cd $1/..; pwd)
- [ $(echo "$path" | grep -c "^$BMX7_DIR") -ne 1 ] && exit 1
+ [ -d "$1" ] && path=$(cd $1; pwd)
+ [ -f "$1" ] && path=$(cd $1/..; pwd)
+ [ $(echo "$path" | grep -c "^$BMX7_DIR") -ne 1 ] && exit 1
print_query() {
# If the query is a directory
[ -d "$BMX7_DIR/$1" ] &&
print_query() {
# If the query is a directory
[ -d "$BMX7_DIR/$1" ] &&
# If /all has not been specified
[ -z "$QALL" ] &&
{
total=$(ls $BMX7_DIR/$1 | wc -w)
i=1
# If /all has not been specified
[ -z "$QALL" ] &&
{
total=$(ls $BMX7_DIR/$1 | wc -w)
i=1
- echo -n "{ \"$1\": [ "
- for f in $(ls $BMX7_DIR/$1); do
+ echo -n "{ \"$1\": [ "
+ for f in $(ls $BMX7_DIR/$1); do
echo -n "{ \"name\": \"$f\" }"
[ $i -lt $total ] && echo -n ','
i=$(( $i + 1 ))
echo -n "{ \"name\": \"$f\" }"
[ $i -lt $total ] && echo -n ','
i=$(( $i + 1 ))
# If /all has been specified, printing all the files together
} || {
# If /all has been specified, printing all the files together
} || {
# If the query is a file, just printing the file
[ -f "$BMX7_DIR/$1" ] && cat "$BMX7_DIR/$1";
# If the query is a file, just printing the file
[ -f "$BMX7_DIR/$1" ] && cat "$BMX7_DIR/$1";