Fix files r/w permissions under Linux Docker (#145)

also improve the scripts
This commit is contained in:
Cotes Chung 2020-10-09 23:46:28 +08:00
parent 049b486f82
commit e806a8556b
2 changed files with 35 additions and 32 deletions

View file

@ -31,7 +31,7 @@ _help() {
} }
_install_tools() { _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 echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
apk update apk update
apk add yq apk add yq

View file

@ -14,10 +14,11 @@ set -eu
WORK_DIR="$(dirname "$(dirname "$(realpath "$0")")")" WORK_DIR="$(dirname "$(dirname "$(realpath "$0")")")"
CONTAINER=.container CONTAINER="${WORK_DIR}/.container"
SYNC_TOOL=_scripts/sh/sync_monitor.sh SYNC_TOOL=_scripts/sh/sync_monitor.sh
cmd="bundle exec jekyll s -l" cmd="bundle exec jekyll s"
realtime=false realtime=false
docker=false docker=false
@ -37,27 +38,32 @@ _help() {
} }
_cleanup() { _cleanup() {
if [[ -d _site || -d .jekyll-cache ]]; then rm -rf "$CONTAINER"
jekyll clean
fi
rm -rf "${WORK_DIR}/${CONTAINER}"
ps aux | grep fswatch | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1 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() { _init() {
if [[ -f Gemfile.lock ]]; then if [[ -f Gemfile.lock ]]; then
rm -f Gemfile.lock rm -f Gemfile.lock
fi fi
if [[ -d "${WORK_DIR}/${CONTAINER}" ]]; then if [[ -d $CONTAINER ]]; then
rm -rf "${WORK_DIR}/${CONTAINER}" rm -rf "$CONTAINER"
fi fi
temp="$(mktemp -d)" local temp="$(mktemp -d)"
cp -r "$WORK_DIR"/* "$temp" cp -r ./* "$temp"
cp -r "${WORK_DIR}/.git" "$temp" cp -r ./.git "$temp"
mv "$temp" "${WORK_DIR}/${CONTAINER}" mv "$temp" "$CONTAINER"
trap _cleanup INT trap _cleanup INT
} }
@ -77,21 +83,8 @@ _check_command() {
fi fi
} }
_install_tools() { _run() {
# docker image `jekyll/jekyll` based on Apline Linux cd "$CONTAINER"
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}"
bash _scripts/sh/create_pages.sh bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh bash _scripts/sh/dump_lastmod.sh
@ -110,16 +103,26 @@ main() {
"$WORK_DIR" | xargs -0 -I {} bash "./${SYNC_TOOL}" {} "$WORK_DIR" . & "$WORK_DIR" | xargs -0 -I {} bash "./${SYNC_TOOL}" {} "$WORK_DIR" . &
fi fi
if ! $docker; then if $docker; then
cmd+=" -o"
else
cmd+=" -H 0.0.0.0" cmd+=" -H 0.0.0.0"
else
cmd+=" -l -o"
fi fi
echo "\$ $cmd" echo "\$ $cmd"
eval "$cmd" eval "$cmd"
} }
main() {
_init
if $docker; then
_setup_docker
fi
_run
}
while (($#)); do while (($#)); do
opt="$1" opt="$1"
case $opt in case $opt in