krata/_scripts/sh/sync_monitor.sh

39 lines
708 B
Bash
Raw Normal View History

2019-11-05 10:18:31 +01:00
#!/bin/bash
# Files sync monitoer
2020-01-02 14:17:49 +01:00
# v2.0
# https://github.com/cotes2020/jekyll-theme-chirpy
2019-11-05 10:18:31 +01:00
# © 2019 Cotes Chung
# MIT Licensed
2019-11-18 14:37:09 +01:00
# $1 -> the origin file with absolute path.
2019-11-05 10:18:31 +01:00
# $2 -> the origin sync directory
# $3 -> the destination sync direcotry
2019-11-18 14:37:09 +01:00
# Omit the system temp file
2019-11-05 10:18:31 +01:00
if [[ ! -f $1 ]]; then
exit 0
fi
src_dir=`dirname $(realpath $1)`
dir_prefix="$(realpath $2)/"
related_dir="${src_dir:${#dir_prefix}}"
dest="$(realpath $3)/${related_dir}"
if [[ ! -d "$dest" ]]; then
mkdir -p "$dest"
fi
if [[ -f "$1" ]]; then
cp $1 $dest
fi
if [[ $related_dir == "_posts" ]]; then
2019-11-18 14:37:09 +01:00
python $3/_scripts/py/init_all.py
python $3/_scripts/py/update_posts_lastmod.py -f "$dest/$(basename $1)" -t fs
2019-11-05 10:18:31 +01:00
fi