-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_sync
53 lines (49 loc) · 1.64 KB
/
git_sync
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
#!/bin/bash
LOGPATH=/var/log/s3_pepe_docs_sync.log
DOCPATH=/var/www/pepe-docs-stage
STATICPATH=/var/www/pepe-docs-static
LOGMRK=0
force=0
[ ! -z $1 ] && [ $1 == '-f' ] && force=1
# check for repo changes
cd $DOCPATH
if /usr/bin/git checkout main &&
/usr/bin/git fetch origin main &&
[ `/usr/bin/git rev-list HEAD...origin/main --count` != 0 ] ||
[ $force == 1 ]
then
LOGMRK=1
echo . >>$LOGPATH
echo +++ $(date +%F' '%H:%M:%S) - Pulling changes from mkdocs repo... >>$LOGPATH
# pull changes
/usr/bin/git merge origin/main &>>$LOGPATH
# rebuild all sites to apply latest mkdocs changes
force=1
fi
cd $DOCPATH/pepe-docs
if /usr/bin/git checkout main &&
/usr/bin/git fetch origin main &&
[ `/usr/bin/git rev-list HEAD...origin/main --count` != 0 ] ||
[ $force == 1 ]
then
LOGMRK=1
echo . >>$LOGPATH
echo +++ $(date +%F' '%H:%M:%S) - Pulling changes from docs repo... >>$LOGPATH
# pull changes
/usr/bin/git merge origin/main &>>$LOGPATH
# build mkdoc
echo 'Docs updated, building en site' >>$LOGPATH
cd ..
/usr/local/bin/mkdocs build --clean &>>$LOGPATH
# copy robots.txt
cp $DOCPATH/robots.txt /var/www/pepe-docs-static/robots.txt
fi
[ $LOGMRK -eq 1 ] && echo +++ Finished at $(date +%F' '%H:%M:%S) +++++++++++++++++++ >>$LOGPATH
# reset file and directory permissions
chown root:users -R $DOCPATH
find $DOCPATH/ -type d -exec chmod 775 {} \;
find $DOCPATH/ -type f -exec chmod 664 {} \;
find $DOCPATH/ -type f -name 'git_sync*' -exec chmod 774 {} \;
chown root:users -R $STATICPATH
find $STATICPATH/ -type d -exec chmod 775 {} \;
find $STATICPATH/ -type f -exec chmod 664 {} \;