-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinstall-rtl_433-app
executable file
·180 lines (152 loc) · 3.81 KB
/
install-rtl_433-app
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
# https://serverfault.com/a/670812 # github.com/gdbtek
# some function credits here go to Nam Nguyen for clean
# bash support functions. The functions here are under MIT license
function have_command()
{
info "checking for command: $1"
which $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "\e[32mfound command: $1 \e[39m" && return 0
else
echo -e "\e[36missing command $1 \e[39m" && return 1
fi
}
function info()
{
local -r message="${1}"
echo -e "\033[1;36m${message}\033[0m" 2>&1
}
function trimString()
{
local -r string="${1}"
sed 's,^[[:blank:]]*,,' <<< "${string}" | sed 's,[[:blank:]]*$,,'
}
function isEmptyString()
{
local -r string="${1}"
if [[ "$(trimString "${string}")" = '' ]]
then
echo 'true' && return 0
fi
echo 'false' && return 1
}
function getLastAptGetUpdate()
{
local aptDate="$(stat -c %Y '/var/cache/apt')"
local nowDate="$(date +'%s')"
echo $((nowDate - aptDate))
}
function runAptGetUpdate()
{
local updateInterval="${1}"
local lastAptGetUpdate="$(getLastAptGetUpdate)"
if [[ "$(isEmptyString "${updateInterval}")" = 'true' ]]
then
# Default To 24 hours
updateInterval="$((24 * 60 * 60))"
fi
if [[ "${lastAptGetUpdate}" -gt "${updateInterval}" ]]
then
info "apt-get update"
sudo apt-get update -m
else
local lastUpdate="$(date -u -d @"${lastAptGetUpdate}" +'%-Hh %-Mm %-Ss')"
info "\nSkip apt-get update because its last run was '${lastUpdate}' ago"
fi
}
function checkAptPackage()
{
local -r package="${1}"
dpkg -s ${package} > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "${package} already installed"
return 0
else
echo "${package} not installed"
return 1
fi
}
function installAptPackage()
{
local -r package="${1}"
checkAptPackage ${package}
if [ $? -eq 1 ]; then
sudo apt install ${package}
fi
}
function installAptPackages()
{
local -r requested_packages=${@}
local install_packages=()
for pkg in $requested_packages; do
checkAptPackage ${pkg}
if [ $? -eq 1 ]; then
install_packages+=($pkg)
fi
done
if [[ ${#install_packages} > 0 ]]; then
packages=$(IFS=" " eval 'echo "${install_packages[*]}"')
echo "packages that need installing: ${packages}"
sudo apt install ${packages}
fi
}
function install_rtl_433() {
echo "installing build dependancies"
runAptGetUpdate
installAptPackages libtool libusb-1.0-0-dev librtlsdr-dev rtl-sdr build-essential autoconf cmake pkg-config git
if [ ! -d apps ]; then
echo "creating an apps dir for rtl_433 application clone"
mkdir apps
else
cd apps
fi
if [ ! -d rtl_433 ]; then
echo "cloning latest merbanan/rtl_433"
git clone https://github.com/merbanan/rtl_433.git
cd rtl_433
else
echo "found existing clone fo rtl_433 -- updating with: git pull"
cd rtl_433
git pull
fi
if [ ! -d build ]; then
mkdir build
fi
pushd .
cd build
cmake ../
if [ $? -eq 1 ]; then
echo "cmake failed - debug that"
exit 1
fi
make
if [ $? -eq 1 ]; then
echo "make failed - debug that"
exit 1
fi
sudo make install
if [ $? -eq 1 ]; then
echo "make install failed - debug that"
exit 1
else
echo "rtl_433 tools installed into /usr/local/"
fi
popd
}
if [ ! -f /etc/modprobe.d/blacklist-rtl.conf ]; then
echo "blacklist dvb_usb_rtl28xxu" | sudo tee -a /etc/modprobe.d/blacklist-rtl.conf
echo "blacklist file added - you need to reboot later"
fi
if [ "${1}" == "force" ]; then
echo "forcing install"
install_rtl_433 force
elif have_command rtl_433; then
echo "rtl_433 detected - skipping install - add the 'force' option like so:"
echo " ./install-rtl_433-app force"
exit
else
echo "rtl_433 not detected - attempting to install"
install_rtl_433
echo "install completed"
fi