-
Notifications
You must be signed in to change notification settings - Fork 28
/
update_ip
executable file
·81 lines (73 loc) · 2.24 KB
/
update_ip
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
#!/bin/bash
#
# This script updates all plutos it can find on the network
#
PASSWORD="analog"
github_api() {
ret=$(curl -s $1)
if [ "$(echo ${ret} | grep "API rate limit exceeded" | wc -c)" -gt "5" ] ; then
echo github API exceeded, wait at least an hour before trying again
exit
fi
echo ${ret}
}
get_release() {
if [ ! -z "${FRM}" ] ; then
FRM=${FIRMWARE}
if [ ! -f ${FIRMWARE} ] ; then
wget "${URL}"
fi
fi
FILE=$(unzip -l "${FIRMWARE}" | grep frm | sort -nr | head -1 | awk '{print $NF}')
if [ ! -f ${FILE} ] ; then
unzip "${FIRMWARE}" "${FILE}"
fi
}
scp_cmd() {
sshpass -p${PASSWORD} scp -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oCheckHostIP=no ${FILE} root@${plutos}:/root/ 2>/dev/null
if [ "$?" -ne "0" ] ; then
echo scp command failed
exit
fi
}
ssh_cmd() {
sshpass -p${PASSWORD} ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oCheckHostIP=no root@${plutos} "$1" 2>/dev/null
if [ "$?" -ne "0" ] ; then
echo ssh command $1 failed
exit
fi
}
command sshpass >/dev/null 2>&1
if [ "$?" -ne "0" ] ; then
echo sorry, your distribution needs to have 'sshpass' installed
echo try \'sudo apt-get install sshpass\' OR \'sudo yum install sshpass\'
exit
fi
API=$(github_api https://api.github.com/repos/analogdevicesinc/plutosdr-fw/releases/latest;)
VERSION=$(echo "${API}" | sed 's/",/"\n"/g' | grep "\"name\"" | head -1 | cut -d : -f 2,3 | tr -d \", | sed 's/^ //g')
FIRMWARE=$(echo "${API}" | sed 's/",/"\n"/g' | grep "name.*plutosdr-fw-" | cut -d : -f 2,3 | tr -d \", | sed 's/^ //g')
URL=$(echo "${API}" | sed -e 's/",/"\n"/g' -e 's/},/}\n/g' | grep "browser_download_url.*plutosdr-fw-" | cut -d : -f 2,3 | awk '{print $1}' | tr -d \")
if [ -f "${FIRMWARE}" ] ; then
FRM=${FIRMWARE}
else
FRM=""
fi
echo Found ${VERSION} online
FILE=""
for plutos in $(iio_info -S ip | grep pluto | awk '{print $2}')
do
ver=$(iio_attr -u ip:${plutos} -C fw_version | awk '{print $2}')
if [ ! "${ver}" = "${VERSION}" ] ; then
get_release
echo Found $plutos at ${ver}, will update
echo -e "\tcopy over file"
scp_cmd
echo -e "\tupdating"
ssh_cmd "update_frm.sh /root/${FILE}"
echo -e "\trebooting"
ssh_cmd "reboot"
echo ${plutos} up to date with ${VERSION}
else
echo ${plutos} up to date with ${VERSION}
fi
done