#!/bin/bash

# Path to the file that stores the current item
STAT_FILE="/usr/share/plymouth/.current"

# Ordered list of items
items=("crashoverride" "acidburn" "cerealkiller" "lordnikon")

# ------------------------------------------------------------------
# 1. Read the current item (if the file is missing, start with the first)
# ------------------------------------------------------------------
if [[ -f "$STAT_FILE" ]]; then
    current=$(<"$STAT_FILE")
else
    current="${items[0]}"
fi

# ------------------------------------------------------------------
# 2. Find the index of the current item in the array
# ------------------------------------------------------------------
idx=-1
for i in "${!items[@]}"; do
    if [[ "${items[i]}" == "$current" ]]; then
        idx=$i
        break
    fi
done

# If the current value isn’t in the list, start from the beginning
if (( idx == -1 )); then
    idx=0
fi

# ------------------------------------------------------------------
# 3. Determine the next item (wrap around to the start)
# ------------------------------------------------------------------
next_idx=$(( (idx + 1) % ${#items[@]} ))
next_item="${items[next_idx]}"

# ------------------------------------------------------------------
# 4. Run the set‑item command
# ------------------------------------------------------------------
plymouth-set-default-theme "$next_item"
update-initramfs -u

# ------------------------------------------------------------------
# 5. Update the stat file with the new item
# ------------------------------------------------------------------
echo "$next_item" > "$STAT_FILE"
