SpiriBase-Deploy/Makefile

205 lines
8.1 KiB
Makefile
Raw Normal View History

2024-12-12 16:29:31 -04:00
.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 \
2024-12-12 16:57:28 -04:00
python3-future python3-twisted python3-serial python3-jinja2 iw virtualenv debhelper dh-python fakeroot build-essential python3-autobahn
2024-12-12 16:29:31 -04:00
# 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
2024-12-12 16:57:28 -04:00
@echo "========================================="
2024-12-12 16:37:31 -04:00
@echo " SpiriBase Installer "
2024-12-12 16:29:31 -04:00
@echo "========================================="
2024-12-12 16:57:28 -04:00
@echo "Please choose an installation option:"
2024-12-12 16:29:31 -04:00
@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
2024-12-12 16:57:28 -04:00
@echo "Starting full installation..."
2024-12-12 16:29:31 -04:00
$(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
2024-12-12 16:57:28 -04:00
@echo "Full installation complete."
2024-12-12 16:29:31 -04:00
manual-select:
@clear
2024-12-12 16:57:28 -04:00
@echo "Please select the components to install:"
2024-12-12 16:29:31 -04:00
@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:
2024-12-12 16:57:28 -04:00
@echo "Starting installation..."
2024-12-12 16:29:31 -04:00
@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;
2024-12-12 16:57:28 -04:00
@echo "All dependencies installed."
2024-12-12 16:29:31 -04:00
2024-12-12 16:37:31 -04:00
# Install SpiriLink driver
2024-12-12 16:29:31 -04:00
.PHONY: spirilink-driver
spirilink-driver:
2024-12-12 17:05:42 -04:00
@$(SUDO) mkdir -p /tmp/spirilink
2024-12-12 16:29:31 -04:00
@if [ "$(DRIVER_TYPE)" = "EU" ]; then \
echo "Installing SpiriLink 8812EU driver..."; \
2024-12-12 17:05:42 -04:00
$(SUDO) wget -O /tmp/spirilink/8812eu.ko https://git.spirirobotics.com/aepko/SpiriLink-Drivers/raw/branch/main/Raspberry%20Pi/8812EU/8812eu.ko && \
$(SUDO) cp /tmp/spirilink/8812eu.ko /lib/modules/$(shell uname -r)/kernel/drivers/net/wireless/ && \
2024-12-12 16:29:31 -04:00
$(SUDO) depmod -a; \
elif [ "$(DRIVER_TYPE)" = "AU" ]; then \
echo "Installing SpiriLink 8812AU driver..."; \
2024-12-12 17:05:42 -04:00
$(SUDO) wget -O /tmp/spirilink/8812au.ko https://git.spirirobotics.com/aepko/SpiriLink-Drivers/raw/branch/main/Raspberry%20Pi/8812AU/8812au.ko && \
$(SUDO) cp /tmp/spirilink/8812au.ko /lib/modules/$(shell uname -r)/kernel/drivers/net/wireless/ && \
2024-12-12 16:29:31 -04:00
$(SUDO) depmod -a; \
else \
echo "Unknown driver type: $(DRIVER_TYPE). Skipping driver installation."; \
fi;
2024-12-12 17:05:42 -04:00
@echo "\nSpiriLink driver installation complete."
2024-12-12 16:29:31 -04:00
# Configure SpiriLink interface
.PHONY: configure-spirilink
configure-spirilink:
2024-12-12 17:03:44 -04:00
@echo "\nConfiguring SpiriLink interface as spir0..."
2024-12-12 17:00:10 -04:00
@if [ "$(DRIVER_TYPE)" = "EU" ]; then \
echo "Loading 8812EU module..."; \
2024-12-12 17:03:44 -04:00
$(SUDO) modprobe 8812eu || (echo "Error loading 8812EU module" && exit 1); \
2024-12-12 17:00:10 -04:00
elif [ "$(DRIVER_TYPE)" = "AU" ]; then \
echo "Loading 8812AU module..."; \
2024-12-12 17:03:44 -04:00
$(SUDO) modprobe 8812au || (echo "Error loading 8812AU module" && exit 1); \
2024-12-12 17:00:10 -04:00
else \
2024-12-12 17:03:44 -04:00
echo "Error: Unknown driver type. Ensure DRIVER_TYPE is set to EU or AU."; \
2024-12-12 17:00:10 -04:00
exit 1; \
fi;
2024-12-12 17:03:44 -04:00
# Identify the wireless interface
spirilink_iface=$$(iw dev | awk '$$1=="Interface"{print $$2}' | head -n 1); \
2024-12-12 16:29:31 -04:00
if [ -z "$$spirilink_iface" ]; then \
echo "Error: SpiriLink interface not detected."; \
exit 1; \
fi; \
echo "Detected SpiriLink interface: $$spirilink_iface"; \
$(SUDO) ip link set $$spirilink_iface down; \
$(SUDO) ip link set $$spirilink_iface name spir0; \
$(SUDO) ip link set spir0 up;
2024-12-12 17:00:10 -04:00
# Add spir0 to unmanaged devices in NetworkManager
2024-12-12 16:29:31 -04:00
@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
2024-12-12 17:00:10 -04:00
# Configure wifibroadcast to use spir0
2024-12-12 16:29:31 -04:00
@echo "Configuring wifibroadcast default interface..."
$(SUDO) bash -c 'echo "WFB_NICS=\"spir0\"" > /etc/default/wifibroadcast'
2024-12-12 17:00:10 -04:00
2024-12-12 16:57:28 -04:00
@echo "\nSpiriLink configuration complete."
2024-12-12 16:29:31 -04:00
# 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:
2024-12-12 17:12:43 -04:00
@echo "\nSetting up web app service..."
2024-12-12 16:29:31 -04:00
@if [ -d ~/tmp/spiri-base ]; then \
2024-12-12 17:12:43 -04:00
cd ~/tmp/spiri-base && git pull || (echo "Error updating repository. Check network and repository access." && exit 1); \
2024-12-12 16:29:31 -04:00
else \
2024-12-12 17:12:43 -04:00
git clone https://git.spirirobotics.com/aepko/Spiri-Base.git ~/tmp/spiri-base || (echo "Error cloning repository. Check network and repository access." && exit 1); \
2024-12-12 16:29:31 -04:00
cd ~/tmp/spiri-base && git sparse-checkout init --cone && git sparse-checkout set .output; \
fi;
2024-12-12 17:12:43 -04:00
@if [ -d ~/tmp/spiri-base/.output ]; then \
$(SUDO) mkdir -p /var/www/webapp; \
$(SUDO) cp -r ~/tmp/spiri-base/.output/* /var/www/webapp/; \
else \
echo "Error: .output folder not found. Ensure the repository contains the necessary files."; \
exit 1; \
fi;
2024-12-12 16:29:31 -04:00
@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;
2024-12-12 17:12:43 -04:00
@echo "\nWeb app service set up and running."
2024-12-12 16:29:31 -04:00
# Uninstall all installed components
.PHONY: uninstall
uninstall:
2024-12-12 16:57:28 -04:00
@echo "Uninstalling all components..."
2024-12-12 16:29:31 -04:00
$(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
2024-12-12 16:57:28 -04:00
@echo "Uninstallation complete."