| 1 | #!/bin/bash |
| 2 | # Test gardm without replacing your current display manager |
| 3 | # This script runs gardm on a different VT/display for testing |
| 4 | |
| 5 | set -e |
| 6 | |
| 7 | RED='\033[0;31m' |
| 8 | GREEN='\033[0;32m' |
| 9 | YELLOW='\033[1;33m' |
| 10 | NC='\033[0m' |
| 11 | |
| 12 | log_info() { |
| 13 | echo -e "${GREEN}[INFO]${NC} $1" |
| 14 | } |
| 15 | |
| 16 | log_warn() { |
| 17 | echo -e "${YELLOW}[WARN]${NC} $1" |
| 18 | } |
| 19 | |
| 20 | log_error() { |
| 21 | echo -e "${RED}[ERROR]${NC} $1" |
| 22 | } |
| 23 | |
| 24 | # Check if running as root |
| 25 | if [ "$EUID" -ne 0 ]; then |
| 26 | log_error "Please run as root (sudo ./test-gardm.sh)" |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | # Find an unused display |
| 31 | find_unused_display() { |
| 32 | for i in {1..9}; do |
| 33 | if [ ! -e "/tmp/.X$i-lock" ] && [ ! -S "/tmp/.X11-unix/X$i" ]; then |
| 34 | echo ":$i" |
| 35 | return |
| 36 | fi |
| 37 | done |
| 38 | echo ":99" |
| 39 | } |
| 40 | |
| 41 | # Find an unused VT (above the typical user range) |
| 42 | find_unused_vt() { |
| 43 | for vt in {7..12}; do |
| 44 | if ! fuser "/dev/tty$vt" >/dev/null 2>&1; then |
| 45 | echo "$vt" |
| 46 | return |
| 47 | fi |
| 48 | done |
| 49 | echo "8" |
| 50 | } |
| 51 | |
| 52 | DISPLAY_NUM=$(find_unused_display) |
| 53 | VT_NUM=$(find_unused_vt) |
| 54 | |
| 55 | log_info "Testing gardm on display $DISPLAY_NUM, VT $VT_NUM" |
| 56 | log_warn "Press Ctrl+C here (or switch back to your main VT) to stop the test" |
| 57 | echo "" |
| 58 | echo "To switch VTs:" |
| 59 | echo " - Ctrl+Alt+F1 through F7 (or F2-F8 depending on your setup)" |
| 60 | echo " - Your current session is likely on VT 1 or 2" |
| 61 | echo "" |
| 62 | echo "Press Enter to start test, or Ctrl+C to cancel..." |
| 63 | read |
| 64 | |
| 65 | # Check if binaries exist |
| 66 | if [ ! -x /usr/bin/gardmd ]; then |
| 67 | log_error "gardmd not installed. Run install.sh first." |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | if [ ! -x /usr/bin/gardm-greeter ]; then |
| 72 | log_error "gardm-greeter not installed. Run install.sh first." |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
| 76 | # Check PAM config |
| 77 | if [ ! -f /etc/pam.d/gardm ]; then |
| 78 | log_error "PAM config not installed. Run install.sh first." |
| 79 | exit 1 |
| 80 | fi |
| 81 | |
| 82 | log_info "Starting gardmd on display $DISPLAY_NUM, VT $VT_NUM..." |
| 83 | log_info "You will be switched to VT $VT_NUM" |
| 84 | |
| 85 | # Run gardmd directly (not via systemd, for testing) |
| 86 | # The daemon will start X on the specified display/VT |
| 87 | exec /usr/bin/gardmd --display "$DISPLAY_NUM" --vt "$VT_NUM" |