OpenWrt – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/bin/sh
2 #
3 # Copyright (C) 2018 Weijie Gao <hackpascal@gmail.com>
4 #
5 # Helper function to extract mac addresses from mtd part for Phicomm K2T
6 #
7  
8 . /lib/functions.sh
9 . /lib/functions/system.sh
10 . /usr/share/libubox/jshn.sh
11  
12 k2t_config_load() {
13 local mtd_blk=$(find_mtd_part config)
14  
15 if [ -z "$mtd_blk" ]; then
16 echo "k2t_config_load: no mtd part named config" >&2
17 exit 1
18 fi
19  
20 local json_size=$(dd if=$mtd_blk bs=1 count=8 2>/dev/null)
21  
22 json_size="0x$json_size"
23 json_size=$((json_size))
24  
25 if [ "$?" -ne 0 ]; then
26 echo "k2t_config_load: invalid json data size" >&2
27 exit 2
28 fi
29  
30 if [ "$json_size" -eq 0 ]; then
31 echo "k2t_config_load: empty json data" >&2
32 exit 3
33 fi
34  
35 local json_data=$(dd if=$mtd_blk bs=1 skip=8 count=$json_size 2>/dev/null)
36  
37 json_load "$json_data"
38 }
39  
40 k2t_get_mac() {
41 local old_ns
42  
43 json_set_namespace "k2t" old_ns
44  
45 if k2t_config_load; then
46 json_select "this_dev_info"
47 json_get_var val "$1"
48 json_select ..
49 fi
50  
51 json_set_namespace old_ns
52  
53 echo $val
54 }
55