Init
This commit is contained in:
commit
6e280b7ffe
182
Makefile
Normal file
182
Makefile
Normal file
@ -0,0 +1,182 @@
|
||||
.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
|
||||
|
||||
# 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 "\n========================================="
|
||||
@echo " Raspberry Pi Ground Station Installer "
|
||||
@echo "========================================="
|
||||
@echo "\nPlease 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 "\nStarting 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 "\nFull installation complete."
|
||||
|
||||
manual-select:
|
||||
@clear
|
||||
@echo "\nPlease 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 "\nStarting 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 "\nAll dependencies installed."
|
||||
|
||||
# Install SpiriLink driver
|
||||
.PHONY: spirilink-driver
|
||||
spirilink-driver:
|
||||
@if [ "$(DRIVER_TYPE)" = "EU" ]; then \
|
||||
echo "Installing SpiriLink 8812EU driver..."; \
|
||||
wget -O ~/tmp/8812eu.ko https://git.spirirobotics.com/aepko/SpiriLink-Drivers/raw/branch/main/Raspberry%20Pi/8812EU/8812eu.ko && \
|
||||
$(SUDO) cp ~/tmp/8812eu.ko /lib/modules/$(shell uname -r)/kernel/drivers/net/wireless/ && \
|
||||
$(SUDO) depmod -a; \
|
||||
elif [ "$(DRIVER_TYPE)" = "AU" ]; then \
|
||||
echo "Installing SpiriLink 8812AU driver..."; \
|
||||
wget -O ~/tmp/8812au.ko https://git.spirirobotics.com/aepko/SpiriLink-Drivers/raw/branch/main/Raspberry%20Pi/8812AU/8812au.ko && \
|
||||
$(SUDO) cp ~/tmp/8812au.ko /lib/modules/$(shell uname -r)/kernel/drivers/net/wireless/ && \
|
||||
$(SUDO) depmod -a; \
|
||||
else \
|
||||
echo "Unknown driver type: $(DRIVER_TYPE). Skipping driver installation."; \
|
||||
fi;
|
||||
@echo "\nSpiriLink driver installation complete."
|
||||
|
||||
# Configure SpiriLink interface
|
||||
.PHONY: configure-spirilink
|
||||
configure-spirilink:
|
||||
@echo "
|
||||
Configuring SpiriLink interface as spir0..."
|
||||
spirilink_iface=$(shell lsusb | grep "0bda:a81a" | awk '{print $$2"/"$$4}' | sed 's/://'); \
|
||||
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;
|
||||
@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 "\nSetting up web app service..."
|
||||
@if [ -d ~/tmp/spiri-base ]; then \
|
||||
cd ~/tmp/spiri-base && git pull; \
|
||||
else \
|
||||
git clone --depth=1 --filter=blob:none --sparse https://git.spirirobotics.com/aepko/Spiri-Base.git ~/tmp/spiri-base && \
|
||||
cd ~/tmp/spiri-base && git sparse-checkout init --cone && git sparse-checkout set .output; \
|
||||
fi;
|
||||
$(SUDO) cp -r ~/tmp/spiri-base/.output/* /var/www/webapp/
|
||||
@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 "\nUninstalling 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 "\nUninstallation complete."
|
15
webapp.service
Normal file
15
webapp.service
Normal file
@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=SpiriBase WebApp Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/var/www/webapp
|
||||
ExecStart=/usr/bin/node /var/www/webapp/.output/server/index.mjs
|
||||
Restart=on-failure
|
||||
Environment=NODE_ENV=production
|
||||
User=www-data
|
||||
Group=www-data
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue
Block a user