90 lines
2.5 KiB
Bash
Executable File
90 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Brother QL Bridge - Raspberry Pi Deployment Script
|
|
# Run this from within the cloned repository
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
|
|
echo "=== Brother QL Bridge Deployment ==="
|
|
echo "Project directory: $PROJECT_DIR"
|
|
echo ""
|
|
|
|
# Check if running on Raspberry Pi
|
|
if [[ ! -f /proc/device-tree/model ]] || ! grep -q "Raspberry Pi" /proc/device-tree/model 2>/dev/null; then
|
|
echo "Warning: This doesn't appear to be a Raspberry Pi"
|
|
read -p "Continue anyway? [y/N] " -n 1 -r
|
|
echo
|
|
[[ $REPLY =~ ^[Yy]$ ]] || exit 1
|
|
fi
|
|
|
|
# Step 1: Install system dependencies
|
|
echo "[1/4] Installing system dependencies..."
|
|
sudo apt update
|
|
sudo apt install -y python3 python3-pip python3-venv libusb-1.0-0-dev
|
|
|
|
# Step 2: Install uv if not present
|
|
echo "[2/4] Setting up Python package manager..."
|
|
if ! command -v uv &> /dev/null; then
|
|
echo "Installing uv..."
|
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
export PATH="$HOME/.local/bin:$PATH"
|
|
fi
|
|
|
|
# Step 3: Setup Python environment
|
|
echo "[3/4] Installing Python dependencies..."
|
|
cd "$PROJECT_DIR"
|
|
uv venv
|
|
uv pip install -r requirements.txt
|
|
|
|
# Step 4: Setup udev rules
|
|
echo "[4/4] Configuring USB permissions..."
|
|
if [[ ! -f /etc/udev/rules.d/99-brother-ql.rules ]]; then
|
|
sudo tee /etc/udev/rules.d/99-brother-ql.rules > /dev/null << 'EOF'
|
|
# Brother QL label printers
|
|
SUBSYSTEM=="usb", ATTR{idVendor}=="04f9", MODE="0666"
|
|
EOF
|
|
sudo udevadm control --reload-rules
|
|
sudo udevadm trigger
|
|
echo "USB permissions configured. You may need to unplug and replug the printer."
|
|
else
|
|
echo "USB permissions already configured."
|
|
fi
|
|
|
|
# Step 5: Install systemd service
|
|
echo "Installing systemd service..."
|
|
sudo tee /etc/systemd/system/brother-ql-bridge.service > /dev/null << EOF
|
|
[Unit]
|
|
Description=Brother QL USB-to-Network Bridge
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=$USER
|
|
WorkingDirectory=$PROJECT_DIR
|
|
ExecStart=$PROJECT_DIR/.venv/bin/python bridge.py
|
|
Restart=always
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable brother-ql-bridge
|
|
|
|
echo ""
|
|
echo "=== Deployment Complete ==="
|
|
echo ""
|
|
echo "To start the service:"
|
|
echo " sudo systemctl start brother-ql-bridge"
|
|
echo ""
|
|
echo "To check status:"
|
|
echo " sudo systemctl status brother-ql-bridge"
|
|
echo ""
|
|
echo "To view logs:"
|
|
echo " sudo journalctl -u brother-ql-bridge -f"
|
|
echo ""
|
|
echo "To test manually:"
|
|
echo " cd $PROJECT_DIR && source .venv/bin/activate && python bridge.py -v"
|