-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistinterfaces.sh
executable file
·88 lines (69 loc) · 2.15 KB
/
listinterfaces.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
cd $(dirname $(readlink -f $0))
[ -e web/drivers.json ] && rm web/drivers.json
[ -e web/drivers.json.tmp ] && rm web/drivers.json.tmp
declare -a arinput=()
declare -a arname=()
declare -a arformat=()
for d in $(ls /dev/video*) ; do
arinput+=($d)
while read -r line
do
if [[ "$line" == *"Card type"* ]]; then
nametemp=$(echo $line | cut -d: -f2 | xargs)
nametemp="${nametemp// /_}"
arname+=($nametemp)
fi
if [[ "$line" == *"Driver Info"* ]]; then
addcaptureline=false
vformat="_"
fi
if [[ $addcaptureline = true ]]; then
linetemp=$(echo $line | cut -d: -f2 | cut -d\( -f1 | xargs)
vformat=$(echo $vformat $linetemp)
vformat="${vformat// /_}"
fi
if [[ "$line" == "Type: Video Capture" ]]; then
addcaptureline=true
fi
done <<< $(v4l2-ctl --device=$d -D --list-formats)
if [[ "$vformat" != "_" ]]; then
vformat="${vformat:1}"
fi
arformat+=($vformat)
done
lastline=$(echo "${#arformat[@]}"-1 | bc)
echo "{" > web/drivers.json.tmp
echo " \"video\": {" >> web/drivers.json.tmp
for i in "${!arformat[@]}"; do
vformat=$(printf "%s" "${arformat[i]}")
vformat="${vformat:1}"
name=$(printf "\"%s\":\"%s(%s)\"" "${arinput[i]}" "${arname[i]}" "$vformat")
name="${name//_/ }"
if [[ ! $i = $lastline ]]; then
name="$name,"
fi
echo " $name" >> web/drivers.json.tmp
done
echo " }," >> web/drivers.json.tmp
lastline=$(arecord -l | grep card | wc -l)
lastline=$(echo "$lastline"-1 | bc)
echo " \"audio\": {" >> web/drivers.json.tmp
i=0
while read -r line
do
driver=$(echo $line | cut -d: -f1)
name=$(echo $line | cut -d: -f2 | cut -d, -f1)
driver=$(echo $driver | sed 's/card //')
name="${name:1}"
snd=$(echo "\"$driver\":\"$name\"")
if [[ ! $i = $lastline ]]; then
snd="$snd,"
fi
i=$(expr $i + 1)
echo " $snd" >> web/drivers.json.tmp
done <<< $(arecord -l | grep card)
echo " }" >> web/drivers.json.tmp
echo "}" >> web/drivers.json.tmp
mv web/drivers.json.tmp web/drivers.json
cat web/drivers.json