diff --git a/Dockerfile b/Dockerfile index 34a3a136983e820e49382b06e4f735fd366c14c7..31465b371aa31e98426427df74234b5d34d19d0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,15 +11,17 @@ WORKDIR /tmp/openwrt ENTRYPOINT [ "/entrypoint.sh" ] -RUN apk --no-cache add sudo rsync && \ +RUN set -x && \ + apk --no-cache add sudo rsync && \ 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 -COPY sync.sh /sync.sh -RUN chmod a+x /entrypoint.sh /sync.sh +RUN chmod a+x /entrypoint.sh + +USER openwrt:openwrt FROM runtime AS release diff --git a/entrypoint.sh b/entrypoint.sh index f89ab0041bbc96dd0c63975f68b25e49f5e946c4..167863bc1d955a21dcf54c763efedc5879e9efc7 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,7 @@ #!/usr/bin/env sh die() { - RED='\033[0;31m' - NC='\033[0m' # No Color - echo -e '\[ '"${RED}$1${NC}"' ]/' + echo -e "* $1" exit 1 } @@ -11,8 +9,20 @@ test -n "$OPENWRT_SSH_CONFIG" && echo "$OPENWRT_SSH_CONFIG" > /opt/c test -n "$OPENWRT_SSH_KEY_ED25519" && echo "$OPENWRT_SSH_KEY_ED25519" > /opt/id_ed25519 test -n "$OPENWRT_SSH_KNOWN_HOSTS" && echo "$OPENWRT_SSH_KNOWN_HOSTS" > /opt/known_hosts -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" +rsync -a -og --chown=openwrt:openwrt /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" -exec sudo -u openwrt -g openwrt -E -H /sync.sh || die "Couldn't run sync script as user" +#exec sudo -u openwrt -g openwrt -E -H /sync.sh || die "Couldn't run sync script as user" +rsync -acxv --delete-after --exclude '*-opkg' -e "ssh -p ${OPENWRT_SSH_PORT:-22}" "${OPENWRT_SSH_HOST:-root@192.168.1.1}:/overlay/upper/" overlay/ || die "Couldn't rsync router config" + +find overlay/ -type d -empty -exec touch {}/.gitkeep \; + +git config --global user.email "${OPENWRT_GIT_EMAIL:-openwrt@example.com}" || die "Couldn't set email" +git config --global user.name "${OPENWRT_GIT_NAME:-OpenWRT Git bot}" || die "Couldn't set name" + +git add -A > /dev/null || die "Couldn't add files" +if [ -n "$(git status -su)" ]; then + git commit -q -m "${OPENWRT_GIT_COMMIT:-OpenWRT}" || die "Couldn't commit changes" + git push -q --force origin HEAD:${OPENWRT_GIT_BRANCH:-remote} || die "Couldn't push changes" +fi diff --git a/sync.sh b/sync.sh deleted file mode 100644 index 7bec91d65253507fcbd2e44ffbdb42b079263020..0000000000000000000000000000000000000000 --- a/sync.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh - -die() { - echo -e "* $1" - exit 1 -} - -rsync -acxv --delete-after --exclude '*-opkg' -e "ssh -p ${OPENWRT_SSH_PORT:-22}" "${OPENWRT_SSH_HOST:-root@192.168.1.1}:/overlay/upper/" overlay/ || die "Couldn't rsync router config" - -find overlay/ -type d -empty -exec touch {}/.gitkeep \; - -git config --global user.email "${OPENWRT_GIT_EMAIL:-openwrt@example.com}" || die "Couldn't set email" -git config --global user.name "${OPENWRT_GIT_NAME:-OpenWRT Git bot}" || die "Couldn't set name" - -git add -A > /dev/null || die "Couldn't add files" -if [ -n "$(git status -su)" ]; then - git commit -q -m "${OPENWRT_GIT_COMMIT:-OpenWRT}" || die "Couldn't commit changes" - git push -q --force origin HEAD:${OPENWRT_GIT_BRANCH:-remote} || die "Couldn't push changes" -fi