#!/bin/bash # Installation script for VizionStreamer systemd service set -e RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' SERVICE_NAME="vizionstreamer.service" SERVICE_FILE="$(pwd)/vizionstreamer.service" SYSTEMD_DIR="/etc/systemd/system" echo -e "${GREEN}=== VizionStreamer Service Installation ===${NC}\n" # Check if running as root if [ "$EUID" -ne 0 ]; then echo -e "${RED}Error: This script must be run as root (use sudo)${NC}" exit 1 fi # Check if service file exists if [ ! -f "$SERVICE_FILE" ]; then echo -e "${RED}Error: Service file not found: $SERVICE_FILE${NC}" exit 1 fi # Check if vizionStreamer executable exists if [ ! -f "/home/maik/CLionProjects/vizionStreamer/build/vizionStreamer" ]; then echo -e "${YELLOW}Warning: vizionStreamer executable not found!${NC}" echo "Please build the project first: cmake --build build" read -p "Continue anyway? (y/N) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi # Stop service if already running if systemctl is-active --quiet $SERVICE_NAME; then echo "Stopping existing service..." systemctl stop $SERVICE_NAME fi # Copy service file echo "Installing service file to $SYSTEMD_DIR..." cp "$SERVICE_FILE" "$SYSTEMD_DIR/" # Reload systemd echo "Reloading systemd daemon..." systemctl daemon-reload # Enable service echo "Enabling service to start on boot..." systemctl enable $SERVICE_NAME # Start service echo "Starting service..." systemctl start $SERVICE_NAME # Show status echo -e "\n${GREEN}Installation complete!${NC}\n" systemctl status $SERVICE_NAME --no-pager echo -e "\n${GREEN}=== Useful Commands ===${NC}" echo " Start: sudo systemctl start $SERVICE_NAME" echo " Stop: sudo systemctl stop $SERVICE_NAME" echo " Restart: sudo systemctl restart $SERVICE_NAME" echo " Status: sudo systemctl status $SERVICE_NAME" echo " Logs: sudo journalctl -u $SERVICE_NAME -f" echo " Disable: sudo systemctl disable $SERVICE_NAME"