testsAndMisc/python_pkg/screen_locker/install_autostart.sh

74 lines
2.2 KiB
Bash
Raw Normal View History

2025-11-18 18:07:15 +01:00
#!/bin/bash
# Script to add screen locker to i3 autostart
# This will run the workout screen locker on system startup
2026-03-08 21:39:39 +01:00
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2025-11-18 18:07:15 +01:00
SCREEN_LOCK_PATH="$SCRIPT_DIR/screen_lock.py"
I3_CONFIG="$HOME/.config/i3/config"
# Check if screen_lock.py exists
if [ ! -f "$SCREEN_LOCK_PATH" ]; then
2026-03-08 21:39:39 +01:00
echo "Error: screen_lock.py not found at $SCREEN_LOCK_PATH"
exit 1
2025-11-18 18:07:15 +01:00
fi
# Make sure screen_lock.py is executable
chmod +x "$SCREEN_LOCK_PATH"
# Check if i3 config exists
if [ ! -f "$I3_CONFIG" ]; then
2026-03-08 21:39:39 +01:00
echo "Error: i3 config not found at $I3_CONFIG"
echo "Please create i3 config first or specify correct path"
exit 1
2025-11-18 18:07:15 +01:00
fi
# Check if autostart line already exists
if grep -q "exec.*screen_lock.py" "$I3_CONFIG"; then
2026-03-08 21:39:39 +01:00
echo "Screen locker autostart already configured in i3 config"
echo "Current line:"
grep "exec.*screen_lock.py" "$I3_CONFIG"
read -p "Do you want to replace it? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Remove old line
sed -i '/exec.*screen_lock\.py/d' "$I3_CONFIG"
else
echo "Keeping existing configuration"
exit 0
fi
2025-11-18 18:07:15 +01:00
fi
# Add autostart line to i3 config
2026-03-08 21:39:39 +01:00
echo "" >>"$I3_CONFIG"
echo "# Workout screen locker on startup (production mode)" >>"$I3_CONFIG"
echo "exec --no-startup-id python3 $SCREEN_LOCK_PATH --production" >>"$I3_CONFIG"
2025-11-18 18:07:15 +01:00
2026-01-02 19:11:54 +01:00
echo "✓ Screen locker added to i3 autostart (production mode)"
2025-11-18 18:07:15 +01:00
echo "✓ Configuration added to: $I3_CONFIG"
echo ""
echo "The screen locker will run on next i3 restart/login"
echo ""
echo "To test now, run: i3-msg restart"
2026-01-02 19:11:54 +01:00
echo "To run in demo mode, remove --production flag from $I3_CONFIG"
2026-03-08 21:39:39 +01:00
# Check autostart installation status
echo ""
echo "=== Autostart Status ==="
if grep -q "exec.*screen_lock.py" "$I3_CONFIG"; then
echo "✓ i3 autostart: INSTALLED"
grep "exec.*screen_lock.py" "$I3_CONFIG"
else
echo "✗ i3 autostart: NOT INSTALLED"
fi
if systemctl --user is-enabled workout-locker.service &>/dev/null; then
echo "✓ systemd service: INSTALLED and enabled"
else
echo " systemd service: not installed"
fi
# Immediately check if today's workout is done; block if not
echo ""
echo "=== Checking today's workout status ==="
python3 "$SCREEN_LOCK_PATH" --production