Commit 701926ef authored by Dmitriy Safronov's avatar Dmitriy Safronov
Browse files

fix

parent 6605e8f5
Loading
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -5,12 +5,11 @@ WORKDIR /tmp/openwrt
ENTRYPOINT [ "sh", "/entrypoint.sh" ]

RUN set -ex && \
    apk --no-cache add git rsync openssh-client && \
    apk --no-cache add sudo 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
COPY sync.sh /sync.sh
+4 −25
Original line number Diff line number Diff line
@@ -7,29 +7,8 @@ die() {
    exit 1
}

rm -rf * || die "Couldn't remove files"
rsync -a /opt/ /home/openwrt/.ssh/ || die "Couldn't rsync user ssh settings"
chown -R openwrt:openwrt /home/openwrt/.ssh || die "Couldn't change ownership for user ssh settings"
chmod -R a-rwx,u+rwX /home/openwrt/.ssh || die "Couldn't change access rights for user ssh settings"

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
sudo -u openwrt -g openwrt -E sh /sync.sh

sync.sh

0 → 100644
+35 −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
}

rm -rf * || die "Couldn't remove files"

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