FROM ubuntu:22.04

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8

# Install official OpenWrt build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    ca-certificates \
    clang \
    cpio \
    curl \
    file \
    gawk \
    gettext \
    git \
    libelf-dev \
    libglib2.0-dev \
    libncurses5-dev \
    libncursesw5-dev \
    libssl-dev \
    python3 \
    python3-dev \
    python3-pip \
    python3-ply \
    python3-pyelftools \
    python3-setuptools \
    rsync \
    subversion \
    swig \
    time \
    unzip \
    wget \
    zlib1g-dev \
    sudo \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root build user (OpenWrt requires building as non-root)
RUN useradd -m -s /bin/bash builduser && \
    echo "builduser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

USER builduser
WORKDIR /home/builduser

# Clone target OpenWrt release (change branch as needed)
ARG OPENWRT_BRANCH=openwrt-25.12
RUN git clone --depth 1 -b ${OPENWRT_BRANCH} https://git.openwrt.org/openwrt/openwrt.git openwrt

WORKDIR /home/builduser/openwrt

#RUN echo "src-git ha_cluster https://github.com/pgaufillet/openwrt-ha-feed.git" >> feeds.conf.default

## Update and install default package feeds
#RUN ./scripts/feeds update -a && \
#    ./scripts/feeds install -a

#RUN echo "CONFIG_TARGET_x86=y" > .config && \
#    echo "CONFIG_TARGET_x86_64=y" >> .config && \
#    echo "CONFIG_PACKAGE_dnsmasq-ha=y" >> .config && \
#    echo "CONFIG_PACKAGE_lease-sync=y" >> .config && \
#    echo "CONFIG_PACKAGE_owsync=y" >> .config && \
#    echo "CONFIG_PACKAGE_ha-cluster=y" >> .config && \
#    echo "CONFIG_PACKAGE_luci-app-ha-cluster=y" >> .config && \
#    sed -i 's/CONFIG_PACKAGE_dnsmasq=y/# CONFIG_PACKAGE_dnsmasq is not set/' .config && \
#    make defconfig

#RUN make -j$(nproc) download
#RUN make -j$(nproc) V=s

#CMD ["/bin/bash"]
