<repo_name>tjorim/addon-sqlite-web<file_sep>/sqlite-web/rootfs/etc/cont-init.d/30-nginx.sh
#!/usr/bin/with-contenv bash
# ==============================================================================
# Community Hass.io Add-ons: SQLite Web
# Configures NGINX for use with SQLite Web
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

declare certfile
declare keyfile

# Enable SSL
if hass.config.true 'ssl'; then
    rm /etc/nginx/nginx.conf
    mv /etc/nginx/nginx-ssl.conf /etc/nginx/nginx.conf

    certfile=$(hass.config.get 'certfile')
    keyfile=$(hass.config.get 'keyfile')

    sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx.conf
    sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx.conf
fi

# Disables IPv6 in case its disabled by the user
if ! hass.config.true 'ipv6'; then
    sed -i '/listen \[::\].*/ d' /etc/nginx/nginx.conf
fi

# Handles the HTTP auth part
if ! hass.config.has_value 'username'; then
    hass.log.warning "Username/password protection is disabled!"
    sed -i '/auth_basic.*/d' /etc/nginx/nginx.conf
else
    username=$(hass.config.get 'username')
    password=$(hass.config.get 'password')
    htpasswd -bc /etc/nginx/.htpasswd "${username}" "${password}"
fi
<file_sep>/sqlite-web/rootfs/etc/cont-init.d/20-patches.sh
#!/usr/bin/with-contenv bash
# ==============================================================================
# Community Hass.io Add-ons: SQLite Web
# This files adds some patches to the add-on
# ==============================================================================

# Adds favicon
mv /www/favicon.png /usr/lib/python3.6/site-packages/sqlite_web/static/img/
patch /usr/lib/python3.6/site-packages/sqlite_web/templates/base.html /patches/favicon

# Adds buymeacoffe link
patch /usr/lib/python3.6/site-packages/sqlite_web/templates/base_tables.html /patches/buymeacoffee
<file_sep>/sqlite-web/Dockerfile
ARG BUILD_FROM=hassioaddons/base:2.3.0
# hadolint ignore=DL3006
FROM ${BUILD_FROM}

# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Setup base
RUN \
  apk add --no-cache --virtual .build-dependencies \
    g++=6.4.0-r9 \
    gcc=6.4.0-r9 \
    make=4.2.1-r2 \
    python3-dev=3.6.6-r0 \
  && apk add --no-cache \
    apache2-utils=2.4.35-r0 \
    nginx=1.14.1-r0 \
    python3=3.6.6-r0 \
    cython=0.28.2-r0 \
  && pip3 install --no-cache-dir  \
    flask==1.0.2 \
    peewee==3.7.1 \
    sqlite-web==0.3.5 \
    datasette==0.25.1 \
  && apk del --purge .build-dependencies \
  && find /usr/lib/python3.6/ -type d -name test -depth -exec rm -rf {} \; \
  && find /usr/lib/python3.6/ -type d -name tests -depth -exec rm -rf {} \; \
  && find /usr/lib/python3.6/ -name __pycache__ -depth -exec rm -rf {} \;

# Copy root filesystem
COPY rootfs /

# Build arugments
ARG BUILD_ARCH
ARG BUILD_DATE
ARG BUILD_REF
ARG BUILD_VERSION

# Labels
LABEL \
    io.hass.name="Sqlite-web" \
    io.hass.description="Explore your SQLite database" \
    io.hass.arch="${BUILD_ARCH}" \
    io.hass.type="addon" \
    io.hass.version=${BUILD_VERSION} \
    maintainer="<NAME> @ludeeus <<EMAIL>>" \
    org.label-schema.description="Explore your SQLite database" \
    org.label-schema.build-date=${BUILD_DATE} \
    org.label-schema.name="Sqlite-web" \
    org.label-schema.schema-version="1.0" \
    org.label-schema.url="https://community.home-assistant.io/t/community-hass-io-add-on-sqlite-web/68912" \
    org.label-schema.usage="https://github.com/hassio-addons/addon-sqlite-web/tree/master/README.md" \
    org.label-schema.vcs-ref=${BUILD_REF} \
    org.label-schema.vcs-url="https://github.com/hassio-addons/addon-sqlite-web" \
    org.label-schema.vendor="Community Hass.io Add-ons"
<file_sep>/sqlite-web/rootfs/etc/cont-init.d/10-requirements.sh
#!/usr/bin/with-contenv bash
# ==============================================================================
# Community Hass.io Add-ons: SQLite Web
# This files check if all user configuration requirements are met
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

# Require username / password
if ! hass.config.has_value 'username' \
    && ! ( \
        hass.config.exists 'leave_front_door_open' \
        && hass.config.true 'leave_front_door_open' \
    );
then
    hass.die 'You need to set a username!'
fi

if ! hass.config.has_value 'password' \
    && ! ( \
        hass.config.exists 'leave_front_door_open' \
        && hass.config.true 'leave_front_door_open' \
    );
then
    hass.die 'You need to set a password!';
fi

# Require a secure password
if hass.config.has_value 'password' \
    && ! hass.config.is_safe_password '<PASSWORD>'; then
    hass.die "Please choose a different password, this one is unsafe!"
fi

# Check SSL requirements, if enabled
if hass.config.true 'ssl'; then
    if ! hass.config.has_value 'certfile'; then
        hass.die 'SSL is enabled, but no certfile was specified'
    fi

    if ! hass.config.has_value 'keyfile'; then
        hass.die 'SSL is enabled, but no keyfile was specified'
    fi

    if ! hass.file_exists "/ssl/$(hass.config.get 'certfile')"; then
        hass.die 'The configured certfile is not found'
    fi

    if ! hass.file_exists "/ssl/$(hass.config.get 'keyfile')"; then
        hass.die 'The configured keyfile is not found'
    fi
fi

# Check if database file exist
if ! hass.file_exists "/config/$(hass.config.get 'database_path')"; then
    hass.die 'The configured database file is not found'
fi
