188 lines
7.4 KiB
Makefile
188 lines
7.4 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
|
|
|
|
# Define installation targets and options
|
|
.PHONY: enable install interactive dependencies uninstall default full-install spirilink-driver spirilink-software setup-webapp-service configure-spirilink
|
|
|
|
default: interactive install
|
|
|
|
interactive:
|
|
@clear
|
|
@echo "========================================="
|
|
@echo " SpiriBase Installer "
|
|
@echo "========================================="
|
|
@echo "Please choose an installation option:"
|
|
@echo "[1] Full Install"
|
|
@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
|
|
@read -p "Is SpiriLink using 8812EU or 8812AU? Enter EU/AU: " driver; \
|
|
if [ "$$driver" = "EU" ] || [ "$$driver" = "eu" ]; then \
|
|
$(MAKE) spirilink-driver DRIVER_TYPE=EU; \
|
|
elif [ "$$driver" = "AU" ] || [ "$$driver" = "au" ]; then \
|
|
$(MAKE) spirilink-driver DRIVER_TYPE=AU; \
|
|
else \
|
|
echo "Invalid input. Skipping SpiriLink driver installation."; \
|
|
fi;
|
|
$(MAKE) spirilink-software
|
|
$(MAKE) configure-spirilink
|
|
$(MAKE) setup-webapp-service
|
|
@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"
|
|
@echo "[3] Python Dependencies"
|
|
@echo "[4] SpiriLink Driver"
|
|
@echo "[5] SpiriLink Software"
|
|
@echo "[6] Configure SpiriLink"
|
|
@echo "[7] Setup WebApp Service"
|
|
@echo "[8] 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) python-deps; fi; \
|
|
if [ "$$choice" = "4" ]; then $(MAKE) spirilink-driver; fi; \
|
|
if [ "$$choice" = "5" ]; then $(MAKE) spirilink-software; fi; \
|
|
if [ "$$choice" = "6" ]; then $(MAKE) configure-spirilink; fi; \
|
|
if [ "$$choice" = "7" ]; then $(MAKE) setup-webapp-service; fi; \
|
|
if [ "$$choice" = "8" ]; then exit 0; fi; \
|
|
done;
|
|
|
|
install:
|
|
@echo "Starting installation..."
|
|
@echo "Installation complete."
|
|
|
|
# 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 SpiriLink driver
|
|
.PHONY: spirilink-driver
|
|
spirilink-driver:
|
|
$(SUDO) mkdir -p ~/tmp
|
|
@if [ "$(DRIVER_TYPE)" = "EU" ]; then \
|
|
echo "Installing SpiriLink 8812EU driver..."; \
|
|
git clone -b v5.15.0.1 https://github.com/svpcom/rtl8812eu.git ~/tmp/rtl8812eu && \
|
|
cd ~/tmp/rtl8812eu && $(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 ~/tmp/rtl8812au && \
|
|
cd ~/tmp/rtl8812au && $(SUDO) ./dkms-install.sh; \
|
|
else \
|
|
echo "Unknown driver type: $(DRIVER_TYPE). Skipping driver installation."; \
|
|
fi;
|
|
@echo "SpiriLink driver installation complete."
|
|
|
|
# Configure SpiriLink interface
|
|
.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; \
|
|
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; \
|
|
$(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 "Configuring wifibroadcast default interface..."
|
|
$(SUDO) bash -c 'echo "WFB_NICS=\"spir0\"" > /etc/default/wifibroadcast'
|
|
@echo "SpiriLink configuration complete."
|
|
|
|
# Install SpiriLink software
|
|
.PHONY: spirilink-software
|
|
spirilink-software:
|
|
@echo "\nInstalling SpiriLink software..."
|
|
@if [ -d ~/tmp/spirilink ]; then \
|
|
read -p "SpiriLink software source already exists. Reinstall? (Y/N): " reinstall; \
|
|
if [ "$$reinstall" = "Y" ] || [ "$$reinstall" = "y" ]; then \
|
|
cd ~/tmp/spirilink && git pull && \
|
|
$(SUDO) make deb && $(SUDO) dpkg -i ~/tmp/spirilink/deb_dist/wfb*.deb; \
|
|
else \
|
|
echo "Skipping SpiriLink software installation."; \
|
|
fi; \
|
|
else \
|
|
git clone https://git.spirirobotics.com/aepko/SpiriLink.git ~/tmp/spirilink && \
|
|
cd ~/tmp/spirilink && \
|
|
$(SUDO) make deb && $(SUDO) dpkg -i ~/tmp/spirilink/deb_dist/wfb*.deb; \
|
|
fi;
|
|
@echo "\nSpiriLink software installed."
|
|
|
|
# Set up web app service
|
|
.PHONY: setup-webapp-service
|
|
setup-webapp-service:
|
|
@echo "Setting up web app service..."
|
|
@if [ -d ~/spiri-base ]; then \
|
|
cd ~/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 ~/spiri-base || (echo "Error cloning repository. Check network and repository access." && exit 1); \
|
|
cd ~/spiri-base && git sparse-checkout init --cone && git sparse-checkout set .output; \
|
|
fi;
|
|
@if [ -d ~/spiri-base/.output ]; then \
|
|
$(SUDO) mkdir -p /var/www/webapp; \
|
|
$(SUDO) cp -r ~/spiri-base/.output/* /var/www/webapp/; \
|
|
else \
|
|
echo "Error: .output folder not found. Ensure the repository contains the necessary files."; \
|
|
exit 1; \
|
|
fi;
|
|
@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 "\nWeb app service 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."
|