FROM alpine:3.7 AS downloader

ARG HTTP_PROXY=""
ARG HTTPS_PROXY=""
ARG http_proxy=""
ARG https_proxy=""
ARG OPENWRT_VERSION=18.06.1

RUN apk add --no-cache wget tar
RUN wget -O openwrt.tar.gz https://downloads.openwrt.org/releases/${OPENWRT_VERSION}/targets/x86/generic/openwrt-${OPENWRT_VERSION}-x86-generic-generic-rootfs.tar.gz\
  && mkdir /openwrt \
  && tar -C /openwrt -xzf openwrt.tar.gz

FROM scratch

COPY --from=downloader /openwrt /

RUN mkdir -p /var/lock \
  && mkdir -p /var/run

USER root

# Install and enable Luci
RUN opkg update\
  && opkg install luci luci-mod-rpc\
  && /etc/init.d/uhttpd enable

RUN rm /lib/preinit/* &&\
    echo > /lib/preinit/00_empty_dummy_script &&\
    /etc/init.d/cron disable &&\
    /etc/init.d/gpio_switch disable &&\
    /etc/init.d/led disable &&\
    /etc/init.d/dropbear disable &&\
    /etc/init.d/network disable &&\
    /etc/init.d/odhcpd disable &&\
    /etc/init.d/sysctl disable &&\
    /etc/init.d/sysfixtime disable &&\
    /etc/init.d/sysntpd disable

CMD /sbin/init