forked from rrobinett/wsprdaemon
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwd_setup.sh
More file actions
executable file
·579 lines (530 loc) · 27.4 KB
/
wd_setup.sh
File metadata and controls
executable file
·579 lines (530 loc) · 27.4 KB
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
180
181
182
183
184
185
186
187
188
10000
div>
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
#!/bin/bash
declare -i verbosity=${verbosity:-1}
declare -r WSPRDAEMON_ROOT_PATH="${WSPRDAEMON_ROOT_DIR}/${0##*/}"
declare -r WSPRDAEMON_CONFIG_FILE=${WSPRDAEMON_ROOT_DIR}/wsprdaemon.conf
declare -r WSPRDAEMON_CONFIG_TEMPLATE_FILE=${WSPRDAEMON_ROOT_DIR}/wd_template.conf
### This is used by two .sh files, so it need to be declared here
declare NOISE_GRAPHS_REPORTER_INDEX_TEMPLATE_FILE=${WSPRDAEMON_ROOT_DIR}/noise_graphs_reporter_index_template.html ### This is put into each reporter's www/html/graphs/REPORTER directory
################# Check that our recordings go to a tmpfs (i.e. RAM disk) file system ################
declare WSPRDAEMON_TMP_DIR=/dev/shm/wsprdaemon
mkdir -p /dev/shm/wsprdaemon
if [[ -n "${WSPRDAEMON_TMP_DIR-}" && -d ${WSPRDAEMON_TMP_DIR} ]] ; then
### The user has configured a TMP dir
wd_logger 2 "Using user configured TMP dir ${WSPRDAEMON_TMP_DIR}"
elif df /tmp/wspr-captures > /dev/null 2>&1; then
### Legacy name for /tmp file system. Leave it alone
WSPRDAEMON_TMP_DIR=/tmp/wspr-captures
elif df /tmp/wsprdaemon > /dev/null 2>&1; then
WSPRDAEMON_TMP_DIR=/tmp/wsprdaemon
fi
declare WD_TIME_FMT=${WD_TIME_FMT-%(%a %d %b %Y %H:%M:%S %Z)T} ### Used by printf "${WD_TIME}: ..." in lieu of $(date)
### If the user has enabled a remote proxy connection in the conf file, then start up that connection now.
declare -r WSPRDAEMON_PROXY_UTILS_FILE=${WSPRDAEMON_ROOT_DIR}/proxy_utils.sh
source ${WSPRDAEMON_PROXY_UTILS_FILE}
proxy_connection_manager
declare -r CPU_ARCH=$(uname -m)
case ${CPU_ARCH} in
armv7l)
### Add code to support installation on Pi's bullseye OS
declare QT5_PACKAGE=qt5-default:armhf
if [[ "${OSTYPE}" == "linux-gnueabihf" ]] ; then
QT5_PACKAGE=libqt5core5a:armhf ### on Pi's bullseye
fi
declare -r PACKAGE_NEEDED_LIST=( at bc curl ntp postgresql sox zstd libgfortran5:armhf ${QT5_PACKAGE})
;;
aarch64)
### This is a 64 bit bullseye Pi4
declare -r PACKAGE_NEEDED_LIST=( at bc curl ntp postgresql sox zstd libgfortran5:arm64 libqt5core5a:arm64 )
;;
x86_64)
declare os_release ### We are not in a function, so it can't be local
get_file_variable os_release "VERSION_ID" /etc/os-release
wd_logger 2 "Installing on Ubuntu ${os_release}"
if [[ "${os_release}" =~ 22.04 ]]; then
### Ubuntu 22.04 doesn't use qt5-default
declare -r PACKAGE_NEEDED_LIST=( at bc curl ntp postgresql sox zstd libgfortran5:amd64 libqt5core5a:amd64 )
else
declare -r PACKAGE_NEEDED_LIST=( at bc curl ntp postgresql sox zstd libgfortran5:amd64 qt5-default:amd64 )
fi
;;
*)
wd_logger 1 "ERROR: wsrpdaemon doesn't know what libraries are needed when running on CPU_ARCH=${CPU_ARCH}"
exit 1
;;
esac
###################### Check OS ###################
if [[ "${OSTYPE}" == "linux-gnueabihf" ]] || [[ "${OSTYPE}" == "linux-gnu" ]] ; then
### We are running on a Raspberry Pi or generic Debian server
declare -r GET_FILE_SIZE_CMD="stat --format=%s"
declare -r GET_FILE_MOD_TIME_CMD="stat -c %Y"
elif [[ "${OSTYPE}" == "darwin18" ]]; then
### We are running on a Mac, but as of 3/21/19 this code has not been verified to run on these systems
declare -r GET_FILE_SIZE_CMD="stat -f %z"
declare -r GET_FILE_MOD_TIME_CMD="stat -f %m"
else
### TODO:
echo "ERROR: We are running on a OS '${OSTYPE}' which is not yet supported"
exit 1
fi
declare -r DPKG_CMD="/usr/bin/dpkg"
declare -r GREP_CMD="/bin/grep"
### Check that there is a conf file
if [[ ! -f ${WSPRDAEMON_CONFIG_FILE} ]]; then
echo "WARNING: The configuration file '${WSPRDAEMON_CONFIG_FILE}' is missing, so it is being created from a template."
echo " Edit that file to match your Receiver(s) and the WSPR band(s) you wish to scan on it (them). Then run this again"
cp -p ${WSPRDAEMON_CONFIG_TEMPLATE_FILE} ${WSPRDAEMON_CONFIG_FILE}
exit
fi
### Check that the conf file differs from the prototype conf file
if diff -q ${WSPRDAEMON_CONFIG_TEMPLATE_FILE} ${WSPRDAEMON_CONFIG_FILE} > /dev/null; then
echo "WARNING: The configuration file '${WSPRDAEMON_CONFIG_FILE}' is the same as the template."
echo " Edit that file to match your Receiver(s) and the WSPR band(s) you wish to scan on it (them). Then run this again"
exit
fi
### Validate the config file so the user sees any errors on the command line
declare -r WSPRDAEMON_CONFIG_UTILS_FILE=${WSPRDAEMON_ROOT_DIR}/config_utils.sh
source ${WSPRDAEMON_CONFIG_UTILS_FILE}
if ! validate_configuration_file; then
exit 1
fi
### Read the variables defined in the conf file
source ${WSPRDAEMON_CONFIG_FILE}
### Additional bands can be defined in the conf file (i.e. WWV, CHU,...)
WSPR_BAND_LIST+=( ${EXTRA_BAND_LIST[@]- } )
WSPR_BAND_CENTERS_IN_MHZ+=( ${EXTRA_BAND_CENTERS_IN_MHZ[@]- } )
### Check the variables which should (or might) be defined in the wsprdaemon.conf file
SIGNAL_LEVEL_UPLOAD=${SIGNAL_LEVEL_UPLOAD-no} ### This forces SIGNAL_LEVEL_UPLOAD to default to "no"
if [[ ${SIGNAL_LEVEL_UPLOAD} != "no" ]]; then
if [[ ${SIGNAL_LEVEL_UPLOAD_ID-none} == "none" ]]; then
wd_logger -1 "ERROR: in wsprdaemon.conf, SIGNAL_LEVEL_UPLOAD=\"${SIGNAL_LEVEL_UPLOAD}\" is set to upload to wsprdaemon.org, but no SIGNAL_LEVEL_UPLOAD_ID has been defined"
exit 1
fi
if [[ ${SIGNAL_LEVEL_UPLOAD_ID} == "AI6VN" ]]; then
wd_logger -1 "ERROR: please change SIGNAL_LEVEL_UPLOAD_ID in your wsprdaemon.conf file from the value \"AI6VN\" which was included in the wd_template.conf file"
exit 2
fi
if [[ ${SIGNAL_LEVEL_UPLOAD_ID} =~ "/" ]]; then
wd_logger -1 "ERROR: SIGNAL_LEVEL_UPLOAD_ID=\"${SIGNAL_LEVEL_UPLOAD_ID}\" defined in your wsprdaemon.conf file cannot include the \"/\". Please change it to \"_\""
exit 3
fi
fi
function check_tmp_filesystem()
{
if [[ ! -d ${WSPRDAEMON_TMP_DIR} ]]; then
[[ $verbosity -ge 0 ]] && echo "The directory system for WSPR recordings does not exist. Creating it"
if ! mkdir -p ${WSPRDAEMON_TMP_DIR} ; then
"ERROR: Can't create the directory system for WSPR recordings '${WSPRDAEMON_TMP_DIR}'"
exit 1
fi
fi
if df ${WSPRDAEMON_TMP_DIR} | grep -q tmpfs ; then
wd_logger 2 "Found '${WSPRDAEMON_TMP_DIR}' is a tmpfs file system"
else
if [[ "${USE_TMPFS_FILE_SYSTEM-yes}" != "yes" ]]; then
echo "WARNING: configured to record to a non-ram file system"
else
echo "WARNING: This server is not configured so that '${WSPRDAEMON_TMP_DIR}' is a 300 MB RAM file system."
echo " Every 2 minutes this program can write more than 200 Mbps to that file system which will prematurely wear out a microSD or SSD"
read -p "So do you want to modify your /etc/fstab to add that new file system? [Y/n]> "
REPLY=${REPLY:-Y} ### blank or no response change to 'Y'
if [[ ${REPLY^} != "Y" ]]; then
echo "WARNING: you have chosen to use a non-ram file system"
else
if ! grep -q ${WSPRDAEMON_TMP_DIR} /etc/fstab; then
sudo cp -p /etc/fstab /etc/fstab.save
echo "Modifying /etc/fstab. Original has been saved to /etc/fstab.save"
echo "tmpfs ${WSPRDAEMON_TMP_DIR} tmpfs defaults,noatime,nosuid,size=300m 0 0" | sudo tee -a /etc/fstab > /dev/null
fi
mkdir ${WSPRDAEMON_TMP_DIR}
if ! sudo mount -a ${WSPRDAEMON_TMP_DIR}; then
echo "ERROR: failed to mount ${WSPRDAEMON_TMP_DIR}"
exit
fi
echo "Your server has been configured so that '${WSPRDAEMON_TMP_DIR}' is a tmpfs (RAM disk)"
fi
fi
fi
}
check_tmp_filesystem
################## Check that kiwirecorder is installed and running #######################
declare KIWI_RECORD_DIR="${WSPRDAEMON_ROOT_DIR}/kiwiclient"
declare KIWI_RECORD_COMMAND="${KIWI_RECORD_DIR}/kiwirecorder.py"
declare KIWI_RECORD_TMP_LOG_FILE="./kiwiclient.log"
function check_for_kiwirecorder_cmd() {
local get_kiwirecorder="no"
local apt_update_done="no"
if [[ ! -x ${KIWI_RECORD_COMMAND} ]]; then
[[ ${verbosity} -ge 1 ]] && echo "$(date): check_for_kiwirecorder_cmd() found no ${KIWI_RECORD_COMMAND}"
get_kiwirecorder="yes"
else
## kiwirecorder.py has been installed. Check to see if kwr is missing some needed modules
[[ ${verbosity} -ge 2 ]] && echo "$(date): check_for_kiwirecorder_cmd() found ${KIWI_RECORD_COMMAND}"
local log_file=/tmp/${KIWI_RECORD_TMP_LOG_FILE}
if ! python3 ${KIWI_RECORD_COMMAND} --help >& ${log_file} ; then
echo "Currently installed version of kiwirecorder.py fails to run:"
cat ${log_file}
if ! ${GREP_CMD} "No module named 'numpy'" ${log_file}; then
echo "Found unknown error in ${log_file} when running 'python3 ${KIWI_RECORD_COMMAND}'"
exit 1
fi
if sudo apt install python3-numpy ; then
echo "Successfully installed numpy"
else
echo "'sudo apt install python3-numpy' failed to install numpy"
if ! pip3 install numpy; then
echo "Installation command 'pip3 install numpy' failed"
exit 1
fi
echo "Installation command 'pip3 install numpy' was successful"
if ! python3 ${KIWI_RECORD_COMMAND} --help >& ${log_file} ; then
echo "Currently installed version of kiwirecorder.py fails to run even after installing module numpy"
exit 1
fi
fi
fi
### kwirecorder.py ran successfully
if ! ${GREP_CMD} "ADC OV" ${log_file} > /dev/null 2>&1 ; then
get_kiwirecorder="yes"
echo "Currently installed version of kiwirecorder.py does not support overload reporting, so getting new version"
rm -rf ${KIWI_RECORD_DIR}.old
mv ${KIWI_RECORD_DIR} ${KIWI_RECORD_DIR}.old
else
[[ ${verbosity} -ge 2 ]] && echo "$(date): check_for_kiwirecorder_cmd() found ${KIWI_RECORD_COMMAND} supports 'ADC OV', so newest version is loaded"
fi
fi
if [[ ${get_kiwirecorder} == "yes" ]]; then
cd ${WSPRDAEMON_ROOT_DIR}
echo "Installing kiwirecorder in $PWD"
if ! ${DPKG_CMD} -l | ${GREP_CMD} -wq git ; then
[[ ${apt_update_done} == "no" ]] && sudo apt-get --yes update && apt_update_done="yes"
sudo apt-get --yes install git
fi
git clone https://github.com/jks-prv/kiwiclient
echo "Downloading the kiwirecorder SW from Github..."
if [[ ! -x ${KIWI_RECORD_COMMAND} ]]; then
echo "ERROR: can't find the kiwirecorder.py command needed to communicate with a KiwiSDR. Download it from https://github.com/jks-prv/kiwiclient/tree/jks-v0.1"
echo " You may also need to install the Python library 'numpy' with: sudo apt-get install python-numpy"
exit 1
fi
if ! ${DPKG_CMD} -l | ${GREP_CMD} -wq python-numpy ; then
[[ ${apt_update_done} == "no" ]] && sudo apt-get --yes update && apt_update_done="yes"
sudo apt --yes install python-numpy
fi
echo "Successfully installed kiwirecorder.py"
cd - >& /dev/null
fi
}
if ! check_for_kiwirecorder_cmd ; then
echo "ERROR: failed to find or load Kiwi recording utility '${KIWI_RECORD_COMMAND}'"
exit 1
fi
function ask_user_to_install_sw() {
local prompt_string=$1
local is_requried_by_wd=${2:-}
echo ${prompt_string}
read -p "Do you want to proceed with the installation of this software? [Yn] > "
REPLY=${REPLY:-Y}
REPLY=${REPLY:0:1}
if [[ ${REPLY^} != "Y" ]]; then
if [[ -n "${is_requried_by_wd}" ]]; then
echo "${is_requried_by_wd} is a software utility required by wsprdaemon and must be installed for it to run"
else
echo "WARNING: change wsprdaemon.conf to avoid installation of this software"
fi
exit
fi
}
### To avoid conflicts with wsprd from WSJT-x which may be also installed on this PC, run a WD copy of wsprd
declare WSPRD_BIN_DIR=${WSPRDAEMON_ROOT_DIR}/bin
mkdir -p ${WSPRD_BIN_DIR}
declare WSPRD_CMD=${WSPRD_BIN_DIR}/wsprd
declare WSPRD_VERSION_CMD=${WSPRD_BIN_DIR}/wsprd.version
declare WSPRD_CMD_FLAGS="${WSPRD_CMD_FLAGS--C 500 -o 4 -d}"
### Only WSJT-x version 2.6.x runs on Pi Bullseye and Ubuntu 22.04 LTS. On Pi Buster and Ubuntu 20.04 LTS only WSJT-x 2.5.4 runs
declare os_release ### We are not in a function, so it can't be local
get_file_variable os_release "VERSION_ID" /etc/os-release
declare os_codename
get_file_variable os_codename "VERSION_CODENAME" /etc/os-release
wd_logger 2 "Installing on Linux '${os_codename}', OS version = '${os_release}'"
if [[ "${os_codename}" == "buster" && "${os_release}" == "10" ]]; then
### Running wsprd and jt9 on Pi "buster" requires WSJT-x 2.5.4
wd_logger 2 "Installing on a Raspberry Pi running '${os_codename}', so install WSJT-x version 2.5.4"
declare WSJTX_REQUIRED_VERSION="${WSJTX_REQUIRED_VERSION:-2.5.4}"
else
### The Debian ID is 10 or 11 on a Raspberry Pi and 20.05 or 18.04 on older Ubuntus. All those are supported by WSJT-x 2.5.4
declare WSJTX_REQUIRED_VERSION="${WSJTX_REQUIRED_VERSION:-2.6.1}"
fi
wd_logger 2 "Running WSJT-x ${WSJTX_REQUIRED_VERSION} on Ubuntu ${os_release}"
### 10/14/20 RR: Always install the 'jt9', but only execute it if 'JT9_CMD_EANABLED="yes"' is added to wsprdaemon.conf
declare JT9_CMD=${WSPRD_BIN_DIR}/jt9
declare JT9_CMD_FLAGS="${JT9_CMD_FLAGS:---fst4w -p 120 -L 1400 -H 1600 -d 3}"
declare JT9_DECODE_ENABLED=${JT9_DECODE_ENABLED:-no}
declare INSTALLED_DEBIAN_PACKAGES=$(${DPKG_CMD} -l)
declare APT_GET_UPDATE_HAS_RUN="no"
function install_debian_package(){
local package_name=$1
local ret_code
if [[ " ${INSTALLED_DEBIAN_PACKAGES} " =~ " ${package_name} " ]]; then
wd_logger 2 "Package ${package_name} has already been installed"
return 0
fi
wd_logger 1 "Package ${package_name} needs to be installed"
if [[ ${APT_GET_UPDATE_HAS_RUN} == "no" ]]; then
wd_logger 1 "'apt-get update' needs to be run"
sudo apt-get update --allow-releaseinfo-change
ret_code=$?
if [[ ${ret_code} -ne 0 ]]; then
wd_logger 1 "ERROR: 'sudo apt-get update' => ${ret_code}"
return ${ret_code}
fi
APT_GET_UPDATE_HAS_RUN="yes"
fi
sudo apt-get install ${package_name} --assume-yes
ret_code=$?
if [[ ${ret_code} -ne 0 ]]; then
wd_logger 1 "ERROR: 'sudo apt-get install ${package_name}' => ${ret_code}"
return ${ret_code}
fi
wd_logger 1 "Installed ${package_name}"
return 0
}
function install_python_package()
{
local pip_package=$1
wd_logger 2 "Verifying or Installing package ${pip_package}"
if python3 -c "import ${pip_package}" 2> /dev/null; then
wd_logger 2 "Found that package ${pip_package} is installed"
return 0
fi
wd_logger 1 "Package ${pip_package} is not installed. Checking that pip3 is insta
8000
lled"
if ! pip3 -V > /dev/null 2>&1 ; then
wd_logger 1 "Installing pip3"
if ! sudo apt install python3-pip -y ; then
wd_logger 1 "ERROR: can't install pip3: 'sudo apt install python3-pip -y' => $?"
exit 1
fi
fi
wd_logger 1 "Having pip3 install package ${pip_package} "
if [[ ${pip_package} == "psycopg2" ]]; then
wd_logger 1 "'pip3 install ${pip_package}' requires 'apt install python3-dev libpq-dev'"
sudo apt install python3-dev libpq-dev
local rc=$?
if [[ ${rc} -ne 0 ]]; then
wd_logger 1 "ERROR: 'sudo apt install python3-dev libpq-dev' => ${rc}"
exit ${rc}
fi
fi
if ! sudo pip3 install ${pip_package} ; then
wd_logger 1 "ERROR: 'sudo pip3 ${pip_package}' => $?"
exit 2
fi
wd_logger 1 "Installed Python package ${pip_package}"
return 0
}
############### Timescale database #######################
#### For writing and reading spots scraped from the Wsprnet.org spot database: TimeScale (TS) Wsprnet (WN) Write Only (WO) and Read Only (RO) defines
declare TS_WN_DB=wsprnet
declare TS_WN_TABLE=spots
declare TS_WN_BATCH_INSERT_SPOTS_SQL_FILE=${WSPRDAEMON_ROOT_DIR}/ts_insert_wn_spots.sql ### Defines the format of the spot lines of the csv file obtained from wsprnet.org
### For the WN table to be accessed, valid usenames and passwords must be defined in the WD.conf file
declare TS_WN_WO_USER=${TS_WN_WO_USER-need_user} ### For writes to work, a valid user name must be declared in WD.conf
declare TS_WN_WO_PASSWORD=${TS_WN_WO_PASSWORD-need_password} ### For writes to work, the valid password must be declared in WD.conf
declare TS_WN_RO_USER=${TS_WN_RO_USER-wdread} ### This user is already public, so it can be the default value and shown here
declare TS_WN_RO_PASSWORD=${TS_WN_RO_PASSWORD-JTWSPR2008} ### This password is already public, no it can be the deault value and shown here
### TimeScale (TS) Wsprdaemon (WD) Write Only (WO) and Read Only (RO) defines
declare TS_WD_DB=tutorial ### The TS database (DB) which contains the tables of WD spots and noise
declare TS_WD_SPOTS_TABLE=wsprdaemon_spots_s
declare TS_WD_NOISE_TABLE=wsprdaemon_noise_s
declare TS_WD_WO_USER=${TS_WD_WO_USER-need_user} ### For writes to work, a valid user name must be declared in WD.conf
declare TS_WD_WO_PASSWORD=${TS_WD_WO_PASSWORD-need_password} ### For writes to work, the valid password must be declared in WD.conf
declare TS_WD_RO_USER=${TS_WD_RO_USER-wdread} ### This user is already public, so it can be the default value and shown here
declare TS_WD_RO_PASSWORD=${TS_WD_RO_PASSWORD-JTWSPR2008} ### This password is already public, no it can be the default value and shown her
declare TS_WD_BATCH_INSERT_SPOTS_SQL_FILE=${WSPRDAEMON_ROOT_DIR}/ts_insert_wd_spots.sql
declare TS_WD_BATCH_INSERT_NOISE_SQL_FILE=${WSPRDAEMON_ROOT_DIR}/ts_insert_wd_noise.sql
### This python command is used by both the scraper daemon to record a csv file with a block of WN spots, and by the tgz servicing daemon to record WD_spots and WD_noise csv files
### usage: python3 ${TS_BATCH_UPLOAD_PYTHON_CMD} --input ${csv_file} --sql ${insert_sql_file} --address localhost --ip_port ${TS_IP_PORT-5432} --database ${TS_DB} --username ${TS_USER} --password ${TS_PASSWORD}
declare TS_BATCH_UPLOAD_PYTHON_CMD=${WSPRDAEMON_ROOT_DIR}/ts_batch_upload.py
function install_ts_recording_packages()
{
### Get the Python packages needed to create the graphs.png
local package
for package in psycopg2 ; do
wd_logger 2 "Install Python package ${package}"
install_python_package ${package}
local ret_code=$?
if [[ ${ret_code} -ne 0 ]]; then
wd_logger 1 "ERROR: failed to install Python package ${package}"
return ${ret_code}
fi
done
}
if ! install_ts_recording_packages ; then
wd_logger 1 "ERROR: failed to install Python package ${package} needed by the server to record spots and noise to TS"
exit 1
fi
### WD uses the 'wsprd' and 'jt9' binaries from the WSJT-x package.
### 9/16/20 RR - WSJT-x doesn't yet install on Ubuntu 20.04, so special case that.
### 'wsprd' doesn't report its version number (e.g. with wsprd -V), so on most systems we learn the version from 'dpkt -l'.
### On Ubuntu 20.04 we can't install the package, so we can't learn the version number from dpkg.
### So on Ubuntu 20.04 we assume that if wsprd is installed it is the correct version
### Perhaps I will save the version number of wsprd and use this process on all OSs
declare WSPRD_VERSION_CMD=${WSPRD_CMD}.version ### Since WSJT-x wsprd doesn't have a '-V' to identify its version, save the version here
function load_wsjtx_commands()
{
local wsprd_version=""
if [[ -x ${WSPRD_VERSION_CMD} ]]; then
wsprd_version=$( ${WSPRD_VERSION_CMD} )
elif false; then
wsprd_version=$(awk '/wsjtx /{print $3}' <<< "${dpkg_list}")
if [[ -n "${wsprd_version}" ]] && [[ -x ${WSPRD_CMD} ]] && [[ ! -x ${WSPRD_VERSION_CMD} ]]; then
sudo sh -c "echo 'echo ${wsprd_version}' > ${WSPRD_VERSION_CMD}"
sudo chmod +x ${WSPRD_VERSION_CMD}
fi
fi
### Now install wsprd if it doesn't exist or if it is the wrong version
if [[ ! -x ${WSPRD_CMD} ]] || [[ -z "${wsprd_version}" ]] || [[ ${wsprd_version} != ${WSJTX_REQUIRED_VERSION} ]]; then
local os_name=""
if [[ -f /etc/os-release ]]; then
### See if we are running on Ubuntu 20.04
### can't use 'source /etc/os-release' since the variable names in that conflict with variables in WD
os_name=$(awk -F = '/^VERSION_CODENAME=/{print $2}' /etc/os-release | sed 's/"//g')
fi
if [[ "${os_name}" == "bullseye" && "${CPU_ARCH}" == "aarch64" ]]; then
if [[ "${wsprd_version}" == "${PI_64BIT_BULLSEYE_WSJTX_REQUIRED_VERSION-2.3.0}" ]]; then
wd_logger 2 "Found the expected wsprd version '${wsprd_version}' on 64 bit Pi bulleye"
return 0
fi
wd_logger 1 "Installing wsjtx on a 64 bit Pi bullseye from 'apt'"
sudo apt install wsjtx -y
local rc=$?
if [[ ${rc} -ne 0 ]]; then
wd_logger 1 "ERROR: 'sudo apt install wsjtx' failed on 64 bit Pi 'bullseye'"
exit 1
fi
wsjtx_version=$( /usr/bin/wsjtx_app_version -v | awk '{print $2}' )
if [[ "${wsjtx_version}" != "${PI_64BIT_BULLSEYE_WSJTX_REQUIRED_VERSION-2.6.1}" ]]; then
wd_logger 1 "ERROR: wrong wsjtx version '${wsjtx_version}' on 64 bit Pi bulleye"
exit
fi
mkdir -p ${WSPRD_BIN_DIR}
cp /usr/bin/{wsprd,jt9} ${WSPRD_BIN_DIR}
echo "echo ${wsjtx_version}" > ${WSPRD_VERSION_CMD}
chmod +x ${WSPRD_VERSION_CMD}
wd_logger 1 "Installed WSJT-x version ${wsjtx_version} on this 64 bit Pi bullseye"
return 0
fi
local wsjtx_pkg=""
case ${CPU_ARCH} in
x86_64)
wsjtx_pkg=wsjtx_${WSJTX_REQUIRED_VERSION}_amd64.deb
;;
armv7l)
wsjtx_pkg=wsjtx_${WSJTX_REQUIRED_VERSION}_armhf.deb
;;
aarch64)
wsjtx_pkg=wsjtx_${WSJTX_REQUIRED_VERSION}_arm64.deb
;;
*)
wd_logger 1 "ERROR: CPU architecture '${CPU_ARCH}' is not supported by this program"
exit 1
;;
esac
### Download WSJT-x and extract its files and copy wsprd to /usr/bin/
local wsjtx_dpkg_file=${WSPRDAEMON_TMP_DIR}/${wsjtx_pkg}
WSJTX_SERVER_URL="${WSJTX_SERVER_URL-https://sourceforge.net/projects/wsjt/files}"
wget ${WSJTX_SERVER_URL}/${wsjtx_pkg} -O ${wsjtx_dpkg_file}
local rc=$?
if [[ ${rc} -ne 0 || ! -f ${wsjtx_dpkg_file} ]] ; then
wd_logger 1 "ERROR: failed to download ${WSJTX_SERVER_URL}/${wsjtx_pkg}"
exit 1
fi
local dpkg_tmp_dir=${WSPRDAEMON_TMP_DIR}/dpkg_wsjt
mkdir -p ${dpkg_tmp_dir}
dpkg-deb -x ${wsjtx_dpkg_file} ${dpkg_tmp_dir}
ret_code=$?
if [[ ${ret_code} -ne 0 ]] ; then
wd_logger 1 "ERROR: on ${os_name} failed to extract files from package file ${wsjtx_pkg_file}"
exit 1
fi
local dpkg_wsprd_file=${dpkg_tmp_dir}/usr/bin/wsprd
if [[ ! -x ${dpkg_wsprd_file} ]]; then
wd_logger 1 "ERROR: failed to find executable '${dpkg_wsprd_file}' in the downloaded WSJT-x package"
exit 1
fi
cp -p ${dpkg_wsprd_file} ${WSPRD_CMD}
echo "echo ${WSJTX_REQUIRED_VERSION}" > ${WSPRD_VERSION_CMD}
chmod +x ${WSPRD_VERSION_CMD}
wd_logger 1 "Installed ${WSPRD_CMD} version ${WSJTX_REQUIRED_VERSION}"
local dpkg_jt9_file=${dpkg_tmp_dir}/usr/bin/jt9
if [[ ! -x ${dpkg_jt9_file} ]]; then
wd_logger 1 "ERROR: failed to find executable '${dpkg_jt9_file}' in the downloaded WSJT-x package"
exit 1
fi
sudo apt install libboost-log1.67.0 ### Needed by jt9
cp -p ${dpkg_jt9_file} ${JT9_CMD}
wd_logger 1 "Installed ${JT9_CMD} version ${WSJTX_REQUIRED_VERSION}"
fi
local wsjtx_dpkg_file_list=( $(find ${WSPRDAEMON_TMP_DIR} -name wsjtx_*.deb ) )
if [[ ${#wsjtx_dpkg_file_list[@]} -gt 0 ]]; then
wd_logger 1 "Flushing files: '${wsjtx_dpkg_file_list[*]}'"
wd_rm ${wsjtx_dpkg_file_list[@]}
fi
local dpkg_tmp_dir=${WSPRDAEMON_TMP_DIR}/dpkg_wsjt
if [[ -d ${dpkg_tmp_dir} ]]; then
wd_logger 1 "Flushing ${dpkg_tmp_dir}"
rm -r ${dpkg_tmp_dir}
fi
}
### 11/1/22 - It appears that last summer a bug was introduced into Ubuntu 20.04 which casues kiwiwrecorder.py to crash if there are no active ssh sessions
### To get around that bug, have WD spawn a ssh session to itself
function setup_wd_auto_ssh()
{
if [[ ${WD_NEEDS_SSH-no} =~ [Nn][Oo] ]]; then ### Matches 'no', 'No', 'NO', and 'nO'
wd_logger 2 "WD_NEEDS_SSH=\"${WD_NEEDS_SSH-no}\", so not configured to start the Linux bug patch which runs an auto-ssh session"
return 0
fi
if [[ ! -d ~/.ssh ]]; then
wd_logger 1 "ERROR: 'WD_NEEDS_SSH=\"${WD_NEEDS_SSH}\" in WD.conf configures WD to start the Linux bug patch which runs an auto-ssh session, but there is no '~/.ssh' directory. Run 'ssh-keygen' to create and populate it"
return 1
fi
if [[ ! -f ~/.ssh/id_rsa.pub ]]; then
wd_logger 1 "ERROR: 'WD_NEEDS_SSH=\"${WD_NEEDS_SSH}\" in WD.conf configures WD to start the Linux bug patch which runs an auto-ssh session, but there is no '~/.ssh/id_rsa.pub' file. Run 'ssh-keygen' to create it"
return 2
fi
local my_ssh_pub_key=$(< ~/.ssh/id_rsa.pub)
if [[ ! -f ~/.ssh/authorized_keys ]] || ! grep -q "${my_ssh_pub_key}" ~/.ssh/authorized_keys; then
wd_logger 1 "Adding my ssh public key to my ~/.ssh/authorized_keys file"
echo "${my_ssh_pub_key}" >> ~/.ssh/authorized_keys
fi
local wd_auto_ssh_pid=$(ps aux | grep "ssh \-fN" | awk '{print $2}')
if [[ -n "${wd_auto_ssh_pid}" ]]; then
wd_logger 2 "Auto ssh session is running with PID ${wd_auto_ssh_pid}"
else
wd_logger 1 "Spawning a new auto ssh session by running 'ssh -fN localhost'"
ssh -fN localhost
fi
return 0
}
### This is called once at startup
function check_for_needed_utilities()
{
setup_wd_auto_ssh
local package_needed
for package_needed in ${PACKAGE_NEEDED_LIST[@]}; do
wd_logger 2 "Checking for package ${package_needed}"
if ! install_debian_package ${package_needed} ; then
wd_logger 1 "ERROR: 'install_debian_package ${package_needed}' => $?"
exit 1
fi
done
wd_logger 2 "Checking for Python's astral library"
if ! install_python_package astral; then
wd_logger 1 "ERROR: failed to install Python package 'astral'"
exit 1
fi
wd_logger 2 "Checking for WSJT-x utilities 'wsprd' and 'jt9'"
load_wsjtx_commands
wd_logger 2 "Setting up noise graphing"
setup_noise_graphs
}
### The configuration may determine which utilities are needed at run time, so now we can check for needed utilities