238 lines
9.5 KiB
Makefile
238 lines
9.5 KiB
Makefile
.DEFAULT_GOAL := default
|
|
SHELL := /bin/bash
|
|
SUDO := $(shell test $${EUID} -ne 0 && echo "sudo")
|
|
.EXPORT_ALL_VARIABLES:
|
|
CURDIR := $(shell pwd)
|
|
DRY_RUN=false
|
|
|
|
# Define dependencies
|
|
DEPENDENCIES := nano htop nload sshpass python3-pip git ninja-build pkg-config gcc g++ systemd dkms python3-all python3-all-dev libpcap-dev libsodium-dev libevent-dev python3-pip python3-pyroute2 python3-msgpack \
|
|
python3-future python3-twisted python3-serial python3-jinja2 iw virtualenv debhelper dh-python fakeroot build-essential python3-autobahn python3-websockets nodejs npm gstreamer1.0-tools gstreamer1.0-plugins-base \
|
|
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-rtsp libgstrtspserver-1.0-0 python3-gi gstreamer1.0-gl libfuse2 libxcb-xinerama0 libxkbcommon-x11-0 \
|
|
libxcb-cursor-dev python3-gi python3-gst-1.0
|
|
|
|
|
|
# Define installation targets and options
|
|
.PHONY: enable install interactive dependencies uninstall default full-install spirilink-driver spirilink-software setup-webapp-service configure-spirilink install-key setup-rtsp-service install-QGC
|
|
|
|
default: interactive install
|
|
|
|
interactive:
|
|
@clear
|
|
@echo "========================================="
|
|
@echo " SpiriBase Installer "
|
|
@echo "========================================="
|
|
@echo "Please choose an installation option:"
|
|
@echo "[1] Full Install - BROKEN ATM"
|
|
@echo "[2] Manually Select Components"
|
|
@echo "[3] Exit"
|
|
@read -p "Enter your choice: " choice; \
|
|
if [ "$$choice" = "1" ]; then $(MAKE) full-install; fi; \
|
|
if [ "$$choice" = "2" ]; then $(MAKE) manual-select; fi; \
|
|
if [ "$$choice" = "3" ]; then exit 0; fi;
|
|
|
|
full-install:
|
|
@clear
|
|
@echo "Starting full installation..."
|
|
$(MAKE) dependencies
|
|
$(MAKE) spirilink-driver
|
|
$(MAKE) configure-spirilink
|
|
$(MAKE) spirilink-software
|
|
$(MAKE) setup-webapp-service
|
|
$(MAKE) install-key
|
|
$(MAKE) setup-rtsp-service
|
|
$(MAKE) install-QGC
|
|
@echo "Full installation complete."
|
|
|
|
manual-select:
|
|
@clear
|
|
@echo "Please select the components to install:"
|
|
@echo "[1] Basic Tools (nano, htop, etc.)"
|
|
@echo "[2] MAVLink Router -TBD"
|
|
@echo "[3] QGroundControl"
|
|
@echo "[4] SpiriLink Driver"
|
|
@echo "[5] Configure SpiriLink"
|
|
@echo "[6] SpiriLink Software"
|
|
@echo "[7] Setup WebApp Service"
|
|
@echo "[8] Install gs.key"
|
|
@echo "[9] Setup RTSP Service"
|
|
@echo "[0] Exit"
|
|
@read -p "Enter your choices separated by spaces (e.g., 1 2 3): " choices; \
|
|
selected="$$choices"; \
|
|
for choice in $$selected; do \
|
|
if [ "$$choice" = "1" ]; then $(MAKE) dependencies; fi; \
|
|
if [ "$$choice" = "2" ]; then $(MAKE) mavlink-router; fi; \
|
|
if [ "$$choice" = "3" ]; then $(MAKE) install-QGC; fi; \
|
|
if [ "$$choice" = "4" ]; then $(MAKE) spirilink-driver; fi; \
|
|
if [ "$$choice" = "5" ]; then $(MAKE) configure-spirilink; fi; \
|
|
if [ "$$choice" = "6" ]; then $(MAKE) spirilink-software; fi; \
|
|
if [ "$$choice" = "7" ]; then $(MAKE) setup-webapp-service; fi; \
|
|
if [ "$$choice" = "8" ]; then $(MAKE) install-key; fi; \
|
|
if [ "$$choice" = "9" ]; then $(MAKE) setup-rtsp-service; fi; \
|
|
if [ "$$choice" = "0" ]; then exit 0; fi; \
|
|
done;
|
|
|
|
install:
|
|
@echo "Starting installation..."
|
|
@echo "Installation complete."
|
|
|
|
# Install gs.key
|
|
.PHONY: install-key
|
|
install-key:
|
|
@echo "Installing gs.key"
|
|
@if [ -f $(CURDIR)/gs.key ]; then \
|
|
$(SUDO) cp $(CURDIR)/gs.key /etc/; \
|
|
else \
|
|
echo "Error: gs.key not found in deployment folder."; \
|
|
fi;
|
|
|
|
# Install dependencies from the array
|
|
.PHONY: dependencies
|
|
dependencies:
|
|
$(SUDO) apt update
|
|
@count=0; total=$(words $(DEPENDENCIES)); \
|
|
for pkg in $(DEPENDENCIES); do \
|
|
count=$$((count + 1)); \
|
|
echo "Installing $$pkg ($$count of $$total)..."; \
|
|
$(SUDO) apt install -y $$pkg; \
|
|
done;
|
|
@echo "All dependencies installed."
|
|
|
|
# Install QGC
|
|
.PHONY: install-QGC
|
|
install-QGC:
|
|
@echo "Installing QGroundControl..."
|
|
$(SUDO) usermod -a -G dialout $(USER);
|
|
$(SUDO) mkdir -p /home/spiri/QGC;
|
|
$(SUDO) wget -O /home/spiri/QGC/QGroundControl.AppImage https://d176tv9ibo4jno.cloudfront.net/latest/QGroundControl.AppImage;
|
|
$(SUDO) chmod +x /home/spiri/QGC/QGroundControl.AppImage;
|
|
@echo "QGroundControl installation complete. Run it with ./home/spiri/QGC/QGroundControl.AppImage"
|
|
|
|
# Install SpiriLink driver
|
|
.PHONY: spirilink-driver
|
|
spirilink-driver:
|
|
@read -p "Is SpiriLink using 8812EU or 8812AU? Enter EU/AU: " driver; \
|
|
if [ "$$driver" = "EU" ] || [ "$$driver" = "eu" ]; then \
|
|
export DRIVER_TYPE=EU; \
|
|
elif [ "$$driver" = "AU" ] || [ "$$driver" = "au" ]; then \
|
|
export DRIVER_TYPE=AU; \
|
|
else \
|
|
echo "Invalid input. Skipping SpiriLink driver installation."; \
|
|
exit 1; \
|
|
fi; \
|
|
$(SUDO) mkdir -p /home/spiri/tmp; \
|
|
if [ "$$DRIVER_TYPE" = "EU" ]; then \
|
|
echo "Installing SpiriLink 8812EU driver..."; \
|
|
git clone -b v5.15.0.1 https://github.com/libc0607/rtl88x2eu-20230815 /home/spiri/tmp/rtl8812eu && \
|
|
cd ~/tmp/rtl8812eu && $(SUDO) sed -i 's/CONFIG_PLATFORM_I386_PC = y/CONFIG_PLATFORM_I386_PC = n/g' Makefile && \
|
|
$(SUDO) sed -i 's/CONFIG_PLATFORM_ARM64_RPI = n/CONFIG_PLATFORM_ARM64_RPI = y/g' Makefile && $(SUDO) ./dkms-install.sh; \
|
|
elif [ "$$DRIVER_TYPE" = "AU" ]; then \
|
|
echo "Installing SpiriLink 8812AU driver..."; \
|
|
git clone -b v5.2.20 https://github.com/svpcom/rtl8812au.git /home/spiri/rtl8812au && \
|
|
cd ~/tmp/rtl8812au && $(SUDO) ./dkms-install.sh; \
|
|
else \
|
|
echo "Unknown driver type: $$DRIVER_TYPE. Skipping driver installation."; \
|
|
fi;
|
|
@echo "SpiriLink driver installation complete."
|
|
|
|
|
|
.PHONY: configure-spirilink
|
|
configure-spirilink:
|
|
@echo "Configuring SpiriLink interface as spir0..."
|
|
@spirilink_iface=$$(iw dev | awk '$$1=="Interface"{print $$2}' | head -n 1); \
|
|
if [ -z "$$spirilink_iface" ]; then \
|
|
echo "Error: SpiriLink interface not detected."; \
|
|
exit 1; \
|
|
fi; \
|
|
if [ "$$spirilink_iface" = "wlan0" ]; then \
|
|
echo "Error: SpiriLink not detected"; \
|
|
echo "Please reboot the system and run the script again."; \
|
|
exit 1; \
|
|
fi; \
|
|
echo "Detected SpiriLink interface: $$spirilink_iface"; \
|
|
mac_address=$$(cat /sys/class/net/$$spirilink_iface/address); \
|
|
echo "Detected MAC address: $$mac_address"; \
|
|
echo 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="'$$mac_address'", NAME="spir0"' | $(SUDO) tee /etc/udev/rules.d/99-spirilink.rules > /dev/null; \
|
|
$(SUDO) udevadm control --reload-rules; \
|
|
$(SUDO) udevadm trigger;
|
|
@echo "Adding spir0 to unmanaged devices in NetworkManager..."
|
|
@$(SUDO) mkdir -p /etc/NetworkManager
|
|
@$(SUDO) touch /etc/NetworkManager/NetworkManager.conf
|
|
@if ! grep -q "\[keyfile\]" /etc/NetworkManager/NetworkManager.conf; then \
|
|
echo "[keyfile]" | $(SUDO) tee -a /etc/NetworkManager/NetworkManager.conf > /dev/null; \
|
|
fi
|
|
@if ! grep -q "unmanaged-devices=interface-name:spir0" /etc/NetworkManager/NetworkManager.conf; then \
|
|
echo "unmanaged-devices=interface-name:spir0" | $(SUDO) tee -a /etc/NetworkManager/NetworkManager.conf > /dev/null; \
|
|
fi
|
|
@$(SUDO) systemctl restart NetworkManager
|
|
@echo "SpiriLink configuration complete."
|
|
|
|
# Install SpiriLink software
|
|
.PHONY: spirilink-software
|
|
spirilink-software:
|
|
@echo "Installing SpiriLink software..."
|
|
@if [ -d ~/home/spiri/spirilink ]; then \
|
|
read -p "SpiriLink software source already exists. Reinstall? (Y/N): " reinstall; \
|
|
if [ "$$reinstall" = "Y" ] || [ "$$reinstall" = "y" ]; then \
|
|
cd ~/home/spiri/spirilink && git pull && \
|
|
$(SUDO) chmod +x ./scripts/install_gs.sh; \
|
|
$(SUDO) ./scripts/install_gs.sh spir0; \
|
|
$(SUDO) cp $(CURDIR)/wifibroadcast.cfg /etc/; \
|
|
else \
|
|
echo "Skipping SpiriLink software installation."; \
|
|
fi; \
|
|
else \
|
|
git clone https://github.com/svpcom/wfb-ng.git ~/home/spiri/spirilink && \
|
|
cd ~/home/spiri/spirilink && \
|
|
$(SUDO) chmod +x ./scripts/install_gs.sh; \
|
|
$(SUDO) ./scripts/install_gs.sh spir0; \
|
|
$(SUDO) cp $(CURDIR)/wifibroadcast.cfg /etc/; \
|
|
fi;
|
|
@echo "SpiriLink software installed."
|
|
|
|
|
|
# Set up web app service
|
|
.PHONY: setup-webapp-service
|
|
setup-webapp-service:
|
|
@echo "Setting up web app service..."
|
|
@if [ -d /home/spiri/Spiri-Base ]; then \
|
|
cd /home/spiri/Spiri-Base && git pull || (echo "Error updating repository. Check network and repository access." && exit 1); \
|
|
else \
|
|
git clone https://git.spirirobotics.com/aepko/Spiri-Base.git /home/spiri/Spiri-Base || (echo "Error cloning repository. Check network and repository access." && exit 1); \
|
|
cd /home/spiri/Spiri-Base && git sparse-checkout init --cone && git sparse-checkout set .output; \
|
|
fi;
|
|
@cd /home/spiri/Spiri-Base && $(SUDO) npm install;
|
|
@if [ -f $(CURDIR)/webapp.service ]; then \
|
|
$(SUDO) cp $(CURDIR)/webapp.service /etc/systemd/system/webapp.service; \
|
|
$(SUDO) systemctl enable webapp.service; \
|
|
$(SUDO) systemctl start webapp.service; \
|
|
else \
|
|
echo "Error: webapp.service not found in deployment folder."; \
|
|
fi;
|
|
@echo "Web app service set up and running."
|
|
|
|
# Set up RTSP service
|
|
.PHONY: setup-rtsp-service
|
|
setup-rtsp-service:
|
|
@echo "Setting up RTSP server..."
|
|
$(SUDO) mkdir -p /home/spiri/rtsp
|
|
$(SUDO) cp $(CURDIR)/rtsp_server.py /home/spiri/rtsp/
|
|
@if [ -f $(CURDIR)/rtsp-server.service ]; then \
|
|
$(SUDO) cp $(CURDIR)/rtsp-server.service /etc/systemd/system/rtsp-server.service; \
|
|
$(SUDO) systemctl enable rtsp-server.service; \
|
|
$(SUDO) systemctl start rtsp-server.service; \
|
|
else \
|
|
echo "Error: rtsp-server.service not found in folder."; \
|
|
fi;
|
|
@echo "RTSP server set up and running."
|
|
|
|
# Uninstall all installed components
|
|
.PHONY: uninstall
|
|
uninstall:
|
|
@echo "Uninstalling all components..."
|
|
$(SUDO) apt remove -y $(DEPENDENCIES)
|
|
$(SUDO) rm -rf ~/tmp/mavlink-router-source ~/tmp/8812eu.ko ~/tmp/8812au.ko ~/tmp/spirilink ~/tmp/spiri-base /var/www/webapp
|
|
$(SUDO) systemctl disable webapp.service
|
|
$(SUDO) rm -f /etc/systemd/system/webapp.service
|
|
@echo "Uninstallation complete."
|