From e806a8556b061ad762b6d9c851e6fae2cf8d5a69 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Fri, 9 Oct 2020 23:46:28 +0800 Subject: [PATCH] Fix files r/w permissions under Linux Docker (#145) also improve the scripts --- tools/build.sh | 2 +- tools/run.sh | 65 ++++++++++++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/tools/build.sh b/tools/build.sh index 8b7a5c2..68b6ca7 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -31,7 +31,7 @@ _help() { } _install_tools() { - # docker image `jekyll/jekyll` based on Apline Linux + # docker image `jekyll/jekyll` based on Alpine Linux echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories apk update apk add yq diff --git a/tools/run.sh b/tools/run.sh index 31c16f5..88492aa 100755 --- a/tools/run.sh +++ b/tools/run.sh @@ -14,10 +14,11 @@ set -eu WORK_DIR="$(dirname "$(dirname "$(realpath "$0")")")" -CONTAINER=.container +CONTAINER="${WORK_DIR}/.container" SYNC_TOOL=_scripts/sh/sync_monitor.sh -cmd="bundle exec jekyll s -l" +cmd="bundle exec jekyll s" + realtime=false docker=false @@ -37,27 +38,32 @@ _help() { } _cleanup() { - if [[ -d _site || -d .jekyll-cache ]]; then - jekyll clean - fi - - rm -rf "${WORK_DIR}/${CONTAINER}" + rm -rf "$CONTAINER" ps aux | grep fswatch | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1 } +_setup_docker() { + # docker image `jekyll/jekyll` based on Alpine Linux + echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories + apk update + apk add yq + + chown -R jekyll:jekyll "$CONTAINER" +} + _init() { if [[ -f Gemfile.lock ]]; then rm -f Gemfile.lock fi - if [[ -d "${WORK_DIR}/${CONTAINER}" ]]; then - rm -rf "${WORK_DIR}/${CONTAINER}" + if [[ -d $CONTAINER ]]; then + rm -rf "$CONTAINER" fi - temp="$(mktemp -d)" - cp -r "$WORK_DIR"/* "$temp" - cp -r "${WORK_DIR}/.git" "$temp" - mv "$temp" "${WORK_DIR}/${CONTAINER}" + local temp="$(mktemp -d)" + cp -r ./* "$temp" + cp -r ./.git "$temp" + mv "$temp" "$CONTAINER" trap _cleanup INT } @@ -77,21 +83,8 @@ _check_command() { fi } -_install_tools() { - # docker image `jekyll/jekyll` based on Apline Linux - echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories - apk update - apk add yq -} - -main() { - _init - - if $docker; then - _install_tools - fi - - cd "${WORK_DIR}/${CONTAINER}" +_run() { + cd "$CONTAINER" bash _scripts/sh/create_pages.sh bash _scripts/sh/dump_lastmod.sh @@ -110,16 +103,26 @@ main() { "$WORK_DIR" | xargs -0 -I {} bash "./${SYNC_TOOL}" {} "$WORK_DIR" . & fi - if ! $docker; then - cmd+=" -o" - else + if $docker; then cmd+=" -H 0.0.0.0" + else + cmd+=" -l -o" fi echo "\$ $cmd" eval "$cmd" } +main() { + _init + + if $docker; then + _setup_docker + fi + + _run +} + while (($#)); do opt="$1" case $opt in