-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathquery.sh
More file actions
executable file
·45 lines (36 loc) · 857 Bytes
/
query.sh
File metadata and controls
executable file
·45 lines (36 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
cd /var/www/openprinting.org/openprinting/snap || exit
exec 2>>error.log
SNAP_DIR=/var/lib/snapd/snap/bin/
if [ ! -f printer-apps.txt ]; then
exit
fi
if [ ! -d cache ]; then
mkdir cache
fi
ARGS=()
DEVICE_ID=""
for ARG in "$@"; do
KEY=${ARG%%=*}
VALUE=${ARG#*=}
ARGS+=(-o "$KEY=\"$VALUE\"")
if [ "$KEY" = "device-id" ]; then
DEVICE_ID="$VALUE"
fi
done
# Fall back to snap if no cache
if [ ! -f "cache/$DEVICE_ID.out" ]; then
while read -r PAPP_LINE; do
PAPP=""
if [ "$(echo "$PAPP_LINE" | awk '{ print NF }')" -gt 1 ]
then
PAPP="$(echo "$PAPP_LINE" | awk '{ print $2 }')"
else
PAPP=$PAPP_LINE
fi
OUTPUT=$("$SNAP_DIR$PAPP" drivers "${ARGS[@]}")
echo "$PAPP: $OUTPUT" >> "cache/$DEVICE_ID.out"
done < printer-apps.txt
fi
# Write out cache contents
cat "cache/$DEVICE_ID.out"