#!/bin/bash

set -e

echo "=== Plymouth Theme Test Script ==="

# --- Запуск ---
echo "[1] Showing splash..."
sudo plymouth --show-splash

echo "[2] Setting boot mode..."
sudo plymouth change-mode --boot-up

echo "[3] Setting normal status..."
sudo plymouth update --status="normal"

# --- Тест паузы прогресса ---
echo "[4] Testing progress pause/resume..."
sudo plymouth pause-progress
sudo plymouth message --text="pausing boot - press 'c' or space bar to continue"
sleep 2
sudo plymouth message --text="resuming boot"
sudo plymouth unpause-progress

# --- Тест запроса пароля ---
echo "[5] Testing password prompt..."
sudo plymouth ask-for-password \
    --prompt "specify password: /dev/sda8: LABEL=\"Data\" UUID=\"2fd2a700-319b-41f2-853f-c57667d4081d\" UUID_SUB=\"62109da7-2b4b-4c2d-b590-1c0436c7c3a4\" PARTUUID=\"c05c942b-bd7e-487a-87a0-592df3334ff5\"" \
    | /usr/bin/tee || true

sleep 1

sudo plymouth ask-for-password \
    --prompt "specify password: /dev/sda8: LABEL=\"Data\" UUID=\"c57667d4081d-319b-41f2-853f-2fd2a700\" UUID_SUB=\"1c0436c7c3a4-2b4b-4c2d-b590-62109da7\" PARTUUID=\"592df3334ff5-bd7e-487a-87a0-c05c942b\"" \
    | /usr/bin/tee || true

# Возвращаемся к нормальному режиму после пароля
sudo plymouth update --status="normal"

# --- Тест FSCK прогресса ---
echo "[6] Testing fsck progress (0→100%)..."
for pct in 0 1 2 3 4 5 6 7 8 9 10 11 12 27 54 100; do
    sudo plymouth --update="fsck:sda1:$pct"
done

# --- Тест скроллящегося лога ---
END=50
echo "[7] Testing scroll log ($END lines)..."
for i in $(seq 1 $END); do
    sudo plymouth --update="$i длинная_строка_предлинная_строка_прямо_вот_такая"
    sudo plymouth --update="$i long_str_long_strlong_str_long_strlong_str_long_str"
done

# --- Ожидание и завершение ---
echo "[8] Waiting 5 seconds before quit..."
sleep 5

echo "[9] Quitting Plymouth..."
sudo plymouth --quit

echo ""
echo "=== Test complete ==="