Last active
October 20, 2024 18:23
-
-
Save kala13x/c51569d9f0cb1087a0a6143c040e6dbb to your computer and use it in GitHub Desktop.
SDR++ and tetra-demodulator setup script for DNF-based systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# SDR++ and tetra-demodulator setup script for DNF-based systems | |
# Sandro Kalatozishvili (c) 2024 (For scientific purposes only) | |
BASE_PATH=$(pwd -P)/$(dirname "$0") | |
WORK_PATH="$BASE_PATH/sdrpp_setup" | |
WORK_OS=$(uname) | |
SDRPLUSPLUS_REPO="https://github.com/AlexandreRouma/SDRPlusPlus" | |
TETRA_DEMOD_REPO="https://github.com/cropinghigh/sdrpp-tetra-demodulator" | |
LIBADIIO_REPO="https://github.com/analogdevicesinc/libad9361-iio" | |
BLADERF_REPO="https://github.com/Nuand/bladeRF" | |
AIRSPY_REPO="https://github.com/airspy/airspyhf" | |
SDRPLUSPLUS_VER="nightly" | |
TETRA_DEMOD_VER="master" | |
LIBADIIO_VER="v0.3" | |
BLADERF_VER="2024.05" | |
AIRSPY_VER="1.6.8" | |
SDRPP_OPTS="-DOPT_BUILD_M17_DECODER=ON" | |
BLADERF_PATCH=$(cat <<'EOF' | |
diff -ruN bladeRF.orig/host/utilities/bladeRF-fsk/c/src/fir_filter.c bladeRF.kala/host/utilities/bladeRF-fsk/c/src/fir_filter.c | |
--- bladeRF.orig/host/utilities/bladeRF-fsk/c/src/fir_filter.c 2024-09-18 03:04:07.512932127 +0400 | |
+++ bladeRF.kala/host/utilities/bladeRF-fsk/c/src/fir_filter.c 2024-09-18 02:43:51.510259022 +0400 | |
@@ -224,7 +224,8 @@ | |
goto out; | |
} | |
- outbuf = calloc(sizeof(struct complex_sample), chunk_size); | |
+ size_t why_the_fuck_am_i_fixing_it = sizeof(struct complex_sample); | |
+ outbuf = calloc(why_the_fuck_am_i_fixing_it, chunk_size); | |
if (!outbuf) { | |
perror("calloc"); | |
goto out; | |
EOF | |
) | |
SDRPP_PATCH=$(cat <<'EOF' | |
diff -ruN SDRPlusPlus.orig/misc_modules/recorder/src/main.cpp SDRPlusPlus.kala/misc_modules/recorder/src/main.cpp | |
--- SDRPlusPlus.orig/misc_modules/recorder/src/main.cpp 2024-10-19 14:38:59.713171250 +0400 | |
+++ SDRPlusPlus.kala/misc_modules/recorder/src/main.cpp 2024-10-19 14:40:20.366253254 +0400 | |
@@ -476,9 +476,10 @@ | |
sprintf(monStr, "%02d", ltm->tm_mon + 1); | |
sprintf(yearStr, "%02d", ltm->tm_year + 1900); | |
if (core::modComManager.getModuleName(name) == "radio") { | |
- int mode; | |
+ int mode = -1; | |
core::modComManager.callInterface(name, RADIO_IFACE_CMD_GET_MODE, NULL, &mode); | |
- modeStr = radioModeToString[mode]; | |
+ // S.K. >> Fix segfault when mode is not in radioModeToString or it is out of bounds | |
+ if (mode >= 0 && mode < radioModeToString.size()) modeStr = radioModeToString[mode]; | |
} | |
// Replace in template | |
EOF | |
) | |
install_deps() { | |
sudo dnf install -y gcc gcc-c++ make cmake ccache \ | |
glfw-devel fftw3-devel rtl-sdr-devel volk-devel \ | |
rtaudio-devel airspyone_host-devel hackrf-devel \ | |
libzstd-devel libiio-devel portaudio-devel codec2-devel | |
} | |
git_clone() { | |
cd $WORK_PATH | |
local DST_DIR=${3:-$(basename $1 .git)} | |
git clone --recursive $1 $DST_DIR || exit 1 | |
cd $DST_DIR && git checkout $2 || exit 1 | |
git submodule update --init --recursive | |
cd $WORK_PATH | |
} | |
build_project() { | |
cd "$WORK_PATH/$@" || exit 1 | |
[ -d ./build ] && rm -rf ./build | |
mkdir build && cd build || exit 1 | |
if [ "$1" == "SDRPlusPlus" ]; then | |
cmake .. $SDRPP_OPTS || exit 1 | |
else | |
cmake .. || exit 1 | |
fi | |
make -j $(nproc) || exit 1 | |
sudo make install && sudo ldconfig | |
if [ $@ == "SDRPlusPlus" ]; then | |
cd "$WORK_PATH/SDRPlusPlus" | |
sh ./create_root.sh | |
fi | |
} | |
patch_bladerf() { | |
cd "$WORK_PATH/bladeRF" || exit 1 | |
echo "$BLADERF_PATCH" | patch -p1 | |
} | |
patch_sdrpp() { | |
cd "$WORK_PATH/SDRPlusPlus" || exit 1 | |
echo "$SDRPP_PATCH" | patch -p1 | |
} | |
patch_etsi_codec() { | |
cd "$WORK_PATH/sdrpp-tetra-demodulator/src/decoder/etsi_codec-patches" | |
./download_and_patch.sh | |
} | |
install_sdrpp_devel() { | |
cd "$WORK_PATH/SDRPlusPlus/core/src" || exit 1 | |
sudo mkdir -p "/usr/include/sdrpp_core/src" | |
sudo mkdir -p "/usr/share/cmake/Modules/" | |
sudo find . -regex ".*\.\(h\|hpp\)" -exec cp --parents \{\} "/usr/include/sdrpp_core/src" \; | |
[ -f /usr/share/cmake/Modules/sdrpp_module.cmake ] && sudo rm -f /usr/share/cmake/Modules/sdrpp_module.cmake | |
sudo tee /usr/share/cmake/Modules/sdrpp_module.cmake > /dev/null << 'EOF' | |
if (NOT SDRPP_CORE_ROOT) | |
set(SDRPP_CORE_ROOT "/usr/include/sdrpp_core") | |
endif () | |
if (NOT SDRPP_MODULE_COMPILER_FLAGS) | |
# Compiler flags | |
if (${CMAKE_BUILD_TYPE} MATCHES "Debug") | |
# Debug Flags | |
if (MSVC) | |
set(SDRPP_MODULE_COMPILER_FLAGS /std:c++17 /EHsc) | |
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
set(SDRPP_MODULE_COMPILER_FLAGS -g -Og -std=c++17 -Wno-unused-command-line-argument -undefined dynamic_lookup) | |
else () | |
set(SDRPP_MODULE_COMPILER_FLAGS -g -Og -std=c++17) | |
endif () | |
else() | |
# Normal Flags | |
if (MSVC) | |
set(SDRPP_MODULE_COMPILER_FLAGS /O2 /Ob2 /std:c++17 /EHsc) | |
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
set(SDRPP_MODULE_COMPILER_FLAGS -O3 -std=c++17 -Wno-unused-command-line-argument -undefined dynamic_lookup) | |
else () | |
set(SDRPP_MODULE_COMPILER_FLAGS -O3 -std=c++17) | |
endif () | |
endif() | |
endif () | |
# Created shared lib and link to core | |
add_library(${PROJECT_NAME} SHARED ${SRC}) | |
target_link_libraries(${PROJECT_NAME} PRIVATE sdrpp_core) | |
target_include_directories(${PROJECT_NAME} PRIVATE "${SDRPP_CORE_ROOT}/src/" "${SDRPP_CORE_ROOT}/src/imgui/") | |
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "") | |
# Set compile arguments | |
target_compile_options(${PROJECT_NAME} PRIVATE ${SDRPP_MODULE_COMPILER_FLAGS}) | |
# Install directives | |
install(TARGETS ${PROJECT_NAME} DESTINATION lib/sdrpp/plugins) | |
EOF | |
echo "File created: /usr/share/cmake/Modules/sdrpp_module.cmake" | |
} | |
[ -d $WORK_PATH ] && rm -rf $WORK_PATH | |
mkdir -p $WORK_PATH | |
# Configure PKG_CONFIG path (might be required for some dependency resolving) | |
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH | |
git_clone $SDRPLUSPLUS_REPO $SDRPLUSPLUS_VER | |
git_clone $TETRA_DEMOD_REPO $TETRA_DEMOD_VER | |
git_clone $LIBADIIO_REPO $LIBADIIO_VER | |
git_clone $BLADERF_REPO $BLADERF_VER | |
git_clone $AIRSPY_REPO $AIRSPY_VER | |
install_deps | |
patch_sdrpp | |
patch_bladerf | |
patch_etsi_codec | |
install_sdrpp_devel | |
build_project airspyhf | |
build_project bladeRF | |
build_project libad9361-iio | |
build_project SDRPlusPlus | |
build_project sdrpp-tetra-demodulator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment