# Dockerfile to test bootstrap.sh and setup.sh scripts in different environments
# This allows testing the setup process in isolated containers

# Ubuntu test environment
FROM ubuntu:24.04 as ubuntu-test
LABEL description="Ubuntu test environment for shell setup scripts"

# Install minimal dependencies needed to run the test
ENV TZ=America/New_York
ENV DEBIAN_FRONTEND=noninteractive
ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
    && apt-get update && apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -y \
    curl git sudo wget

# Pre-install essential packages from packages.list for faster testing
RUN apt-get update && apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -y \
    python3 \
    bat \
    cowsay \
    lolcat \
    fzf \
    zsh \
    nala \
    fd-find \
    eza

# Create logs directory with proper permissions
RUN mkdir -p /logs && chmod -R 777 /logs

# Create a test user with sudo permissions
RUN useradd -ms /bin/bash testuser && \
    echo "testuser ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/testuser

USER testuser
WORKDIR /home/testuser

# Create directory structure for shell setup
RUN mkdir -p /home/testuser/shell/setup
RUN mkdir -p /home/testuser/shell/dotfiles

# Copy all necessary setup files
COPY --chown=testuser:testuser test-setup.sh /home/testuser/shell/setup/
COPY --chown=testuser:testuser startup.sh /home/testuser/
COPY --chown=testuser:testuser setup.sh /home/testuser/shell/setup/
COPY --chown=testuser:testuser bootstrap.sh /home/testuser/shell/setup/
COPY --chown=testuser:testuser packages.list /home/testuser/shell/setup/
COPY --chown=testuser:testuser my-aliases.zsh.template /home/testuser/shell/dotfiles/

# Make scripts executable
RUN chmod +x /home/testuser/shell/setup/test-setup.sh
RUN chmod +x /home/testuser/startup.sh
RUN chmod +x /home/testuser/shell/setup/setup.sh
RUN chmod +x /home/testuser/shell/setup/bootstrap.sh

CMD ["/bin/bash", "-c", "./startup.sh"]

# Debian test environment
FROM debian:12 as debian-test
LABEL description="Debian test environment for shell setup scripts"

# Install minimal dependencies needed to run the test
ENV TZ=America/New_York
ENV DEBIAN_FRONTEND=noninteractive
ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
    && apt-get update && apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -y curl git sudo wget

# Pre-install cowsay and lolcat packages for testing
RUN apt-get update && apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" -y cowsay lolcat

# Create logs directory with proper permissions
RUN mkdir -p /logs && chmod -R 777 /logs

# Create a test user with sudo permissions
RUN useradd -ms /bin/bash testuser && \
    echo "testuser ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/testuser

USER testuser
WORKDIR /home/testuser

# Create directory structure for shell setup
RUN mkdir -p /home/testuser/shell/setup
RUN mkdir -p /home/testuser/shell/dotfiles

# Copy all necessary setup files
COPY --chown=testuser:testuser test-setup.sh /home/testuser/shell/setup/
COPY --chown=testuser:testuser startup.sh /home/testuser/
COPY --chown=testuser:testuser setup.sh /home/testuser/shell/setup/
COPY --chown=testuser:testuser bootstrap.sh /home/testuser/shell/setup/
COPY --chown=testuser:testuser packages.list /home/testuser/shell/setup/
COPY --chown=testuser:testuser my-aliases.zsh.template /home/testuser/shell/dotfiles/

# Make scripts executable
RUN chmod +x /home/testuser/shell/setup/test-setup.sh
RUN chmod +x /home/testuser/startup.sh
RUN chmod +x /home/testuser/shell/setup/setup.sh
RUN chmod +x /home/testuser/shell/setup/bootstrap.sh

CMD ["/bin/bash", "-c", "./startup.sh"]
