Commit 5e8b37b2 authored by Dmitriy Safronov's avatar Dmitriy Safronov
Browse files

initial

parent 8a4fbc42
Loading
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+3 −0
Original line number Diff line number Diff line
/.gitlab-ci.yml
/.hadolint.yaml
/README.md

.gitlab-ci.yml

0 → 100644
+0 −0

Empty file added.

.hadolint.yaml

0 → 100644
+2 −0
Original line number Diff line number Diff line
ignored:
  - DL3008

Dockerfile

0 → 100644
+16 −0
Original line number Diff line number Diff line
FROM registry.cyberbrain.pw/docker/alpine:latest

WORKDIR /tmp/openwrt

ENTRYPOINT [ "sh", "/entrypoint.sh" ]

RUN set -ex && \
    apk --no-cache add git rsync openssh-client && \
    rm -rf /var/cache/apk/* && \
    addgroup -S openwrt && \
    adduser -S openwrt -G openwrt -h /home/openwrt && \
    chown -R openwrt:openwrt /tmp/openwrt

COPY entrypoint.sh /entrypoint.sh

USER openwrt:openwrt

entrypoint.sh

0 → 100644
+33 −0
Original line number Diff line number Diff line
#!/usr/bin/env sh

die() {
    RED='\033[0;31m'
    NC='\033[0m' # No Color
    echo -e '\[ '"${RED}$1${NC}"' ]/'
    exit 1
}

if [ -n "$OPENWRT_GIT_URL" ]; then

    git clone "$OPENWRT_GIT_URL" . || die "Couldn't clone repo"
    git config user.email "${OPENWRT_GIT_EMAIL:-openwrt@example.com}" || die "Couldn't set email"
    git config user.name "${OPENWRT_GIT_NAME:-OpenWRT Git bot}" || die "Couldn't set name"

    while true; do
        git reset --hard || die "Couldn't reset repo"
        git pull || die "Couldn't pull repo"

        ( LC_ALL=C.UTF-8 rsync -a --delete-after --exclude '*-opkg' -e "ssh -p ${OPENWRT_SSH_PORT:-22}" "${OPENWRT_SSH_HOST:-root@192.168.0.1}:/overlay/upper/" overlay/ | grep -v 'skipping' ) || die "Couldn't rsync config"
        git add -A || die "Couldn't add files"

        if [ -n "$(git status -su)" ]; then
            git commit -m OpenWRT 2> /dev/null || die "Couldn't commit changes"
            git push --force origin HEAD:${OPENWRT_GIT_BRANCH:-remote} 2> /dev/null || die "Couldn't push changes"
        fi

        sleep ${OPENWRT_SYNC_INTERVAL:-10} || die "Couldn't sleep correctly"
    done

else
    die "OPENWRT_GIT_URL is not configured"
fi