-
Notifications
You must be signed in to change notification settings - Fork 212
/
change-checker.sh
41 lines (32 loc) · 1022 Bytes
/
change-checker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/env bash
# Starts deployment if change is detected
# Cron cycles this script
# Exit immediately if an error occurs, or if an undeclared variable is used
set -o errexit
set -o nounset
[ "$OSTYPE" != "win"* ] || die "Install Cygwin to use on Windows"
# Set directory vars
. "vars.cfg"
GENERATOR_FILE_PATH="${PROJECT_DIR}/generator.sh"
# Cron cycle period in minutes
CRON_CYCLE='30'
START_DEPLOY=""
# Pull request
echo "git pull base coin"
cd $BASE_COIN_PATH
git reset --hard origin/master
git pull
cd $PROJECT_DIR
# Check if file is changed in _posts folder in the cron cycle
CURRENT_TIMESTAMP="$( date +%s )"
if [[ "$OSTYPE" == "darwin"* ]]; then
LAST_EDITED_TIMESTAMP="$( stat -f "%m" ${BASE_COIN_PATH} )"
else
LAST_EDITED_TIMESTAMP="$( stat -c "%Y" ${BASE_COIN_PATH} )"
fi
let TARGET_TIME=${LAST_EDITED_TIMESTAMP}+${CRON_CYCLE}*60
if [[ ${TARGET_TIME} -ge ${CURRENT_TIMESTAMP} ]]; then
echo "Freshly edited"
${START_GENERATOR}="$( exec bash "${GENERATOR_FILE_PATH}" )"
fi
echo ${START_GENERATOR}