-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcopy-config.sh
executable file
·89 lines (75 loc) · 1.98 KB
/
copy-config.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
#!/bin/ash
TARGET_IP="192.168.1.1"
configure_network () {
ip a d 192.168.1.1/24 dev br-setup
ip a a 192.168.1.2/24 dev br-setup
}
ping_target () {
ping -c1 $TARGET_IP
echo $?
}
wait_for_remote () {
result=$(ping_target)
while [[ "$result" == "1" ]]
do
echo "$TARGET_IP not reachable"
sleep 1s
result=$(ping_target)
done
}
get_remote_ipv6_prefix () {
echo $(ssh [email protected] "grep -A1 'local_node_route6' /etc/config/network | tail -n1")
}
parse_domain_number () {
remote_domain=$1
remote_domain=${remote_domain##*2a03:2260:115:}}
remote_domain=${remote_domain%%00:*}
if [[ ${#remote_domain} -gt 0 && ${#remote_domain} -le 2 && $remote_domain -gt 0 && $a $remote_domain -lt 256 ]]
then
echo $remote_domain
else
echo "Domain could not be determined. Is the source router part of Freifunk Münsterland? Aborting."
exit 1
fi
}
is_generic_firmware () {
firmware=$(cat /lib/gluon/release)
if [[ $(expr match $firmware "GenericFactoryImage*") != 0 ]]
then
return 0
else
return 1
fi
}
upgrade_firmware () {
wget -O /tmp/firmware.bin http://firmware.freifunk-muensterland.de/domaene$1/versions/v7.0.1/sysupgrade/gluon-ffmsd$1-v2020.2%2B7.0.1-tp-link-tl-wr841n-nd-mod-16m-$2-sysupgrade.bin
sysupgrade -n /tmp/firmware.bin
}
determine_revision () {
HWID=$(hexdump -s 0x0001FD00 -n8 /dev/mtd0 |cut -d' ' -f2-5 |tr -d ' '|head -n 1)
case ${HWID:6:2} in
"08")
echo "v8"
;;
"09")
echo "v9"
;;
"10")
echo "v10"
;;
"11")
echo "v11"
;;
esac
}
configure_network
wait_for_remote
if is_generic_firmware
then
prefix_slug=$(get_remote_ipv6_prefix)
domain_number=$(parse_domain_number "$prefix_slug")
revision=$(determine_revision)
upgrade_firmware $domain_number $revision
else
echo "not implemented yet"
fi