#!/bin/bash
set -e

echo "Pulling latest code..."
cd ~/mission-control
git fetch
git reset --hard origin/main
git pull

echo "Deploying to /opt/mission-control..."
rsync -a --exclude='.git' --exclude='.venv' --exclude='__pycache__' --exclude='*.pyc' ~/mission-control/ /opt/mission-control/

echo "Configuring sudoers..."
echo 'Tu77ceu2zzvx!' | sudo -S bash -c "echo 'hitonabi ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart mission-control, /usr/bin/systemctl restart llama-swap, /usr/bin/journalctl' > /etc/sudoers.d/mission-control && chmod 440 /etc/sudoers.d/mission-control"

echo "Restarting service..."
echo 'Tu77ceu2zzvx!' | sudo -S systemctl restart mission-control

echo "Deployment complete."
