Enhance setup and testing scripts for improved package management and logging

- Updated setup.sh to check for Nala installation and provide alternative installation methods based on Ubuntu version.
- Added error handling for package installation, allowing fallback to apt if Nala fails.
- Introduced startup.sh to perform container startup checks, including system info and permissions for logs directory.
- Created test-setup.sh to validate bootstrap and setup scripts, including detailed logging of package availability and installation results.
- Implemented checks for missing packages and provided recommendations for manual installation.
- Enhanced logging for better traceability of actions and errors during setup and testing processes.
This commit is contained in:
Peter Wood
2025-05-12 13:59:15 -04:00
parent 78d64d5ee5
commit 9a941d1752
11 changed files with 1901 additions and 16 deletions

80
Dockerfile Normal file
View File

@@ -0,0 +1,80 @@
# 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 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
# Copy test script, startup script, and packages.list
COPY --chown=testuser:testuser test-setup.sh /home/testuser/
COPY --chown=testuser:testuser startup.sh /home/testuser/
COPY --chown=testuser:testuser setup/packages.list /home/testuser/shell/setup/
# Make scripts executable
RUN chmod +x /home/testuser/test-setup.sh
RUN chmod +x /home/testuser/startup.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
# Copy test script, startup script, and packages.list
COPY --chown=testuser:testuser test-setup.sh /home/testuser/
COPY --chown=testuser:testuser startup.sh /home/testuser/
COPY --chown=testuser:testuser setup/packages.list /home/testuser/shell/setup/
# Make scripts executable
RUN chmod +x /home/testuser/test-setup.sh
RUN chmod +x /home/testuser/startup.sh
CMD ["/bin/bash", "-c", "./startup.sh"]