-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployer.sh
executable file
·60 lines (51 loc) · 1.41 KB
/
deployer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
COMMIT_FILE="last_commit"
NIKOLA_REPO="$HOME/github.io/"
PAGES_REPO="$HOME/mathbio.github.io/"
NIKOLA="$HOME/nikpy/bin/nikola"
check_new_posts(){
pushd $NIKOLA_REPO
for i in posts/*ipynb
do
if [ ! -e "${i%ipynb}meta" ]
then
TITLE=$(basename "$i" .ipynb)
# we need to take the file out of the posts/ folder
mv "$i" "${TITLE}.ipynb"
# some trickery to get the metadata file name
FNAME=$($NIKOLA new_post -f ipynb -t "$TITLE" | tail -n1 | rev | cut -d' ' -f1 | rev)
mv "${TITLE}.ipynb" "$i"
git mv -f "${TITLE}.ipynb" "${FNAME%meta}ipynb"
git add \*ipynb posts/*
git commit -m "AUTO: handling post ${TITLE}"
fi
done
popd
}
pushd $NIKOLA_REPO
git pull
CUR=$(git log -n1 | head -n1 | cut -d' ' -f2)
OLD=$(<$COMMIT_FILE)
if [ "$CUR" != "$OLD" ]
then
check_new_posts
$NIKOLA build
if [ $? -eq 0 ]
then
MESSAGE=$(git log --pretty=oneline "${OLD}..HEAD" | cut -d' ' -f 2- | xargs echo -n)
pushd $PAGES_REPO
git add --all .
git commit -a -m "AUTO: $MESSAGE"
if [ $? -eq 0 ]
then
git push
pushd $NIKOLA_REPO
NEWCUR=$(git log -n1 | head -n1 | cut -d' ' -f2)
echo "$NEWCUR" > $COMMIT_FILE
popd
fi
else
git checkout posts/
fi
fi
popd 2