-
Notifications
You must be signed in to change notification settings - Fork 3
/
git_sync_ml
executable file
·53 lines (50 loc) · 2.57 KB
/
git_sync_ml
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
# default language cn
lang=cn
# force build without repo changes
force=0
[ ! -z $1 ] && lang=$1
[ ! -z $2 ] && [ $2 == '-f' ] && force=1
LOGPATH=/var/log/s3_moonbeam_docs_sync.log
DOCPATH=/var/www/mkdocs-multi-lang/moonbeam-docs-$lang-stage
STATICPATH=/var/www/mkdocs-multi-lang/moonbeam-docs-$lang-static
# check/create symlinks
[ ! -L $DOCPATH/material-overrides ] && cp -Rs /var/www/moonbeam-docs-stage/material-overrides/ $DOCPATH
# symlinks to specific mkdocs-$lang options to overwrite
cp -Rsf /var/www/moonbeam-docs-stage/mkdocs-$lang/* $DOCPATH
[ ! -L $DOCPATH/moonbeam-docs-$lang/variables.yml ] && ln -s /var/www/moonbeam-docs-stage/moonbeam-docs/variables.yml $DOCPATH/moonbeam-docs-$lang/variables.yml
[ ! -L $DOCPATH/moonbeam-docs-$lang/images ] && ln -s /var/www/moonbeam-docs-stage/moonbeam-docs/images $DOCPATH/moonbeam-docs-$lang/images
[ ! -L $DOCPATH/moonbeam-docs-$lang/js ] && ln -s /var/www/moonbeam-docs-stage/moonbeam-docs/js $DOCPATH/moonbeam-docs-$lang/js
[ ! -L $DOCPATH/moonbeam-docs-$lang/.snippets/code ] && ln -s /var/www/moonbeam-docs-stage/moonbeam-docs/.snippets/code $DOCPATH/moonbeam-docs-$lang/.snippets/code
# check for repo changes
cd $DOCPATH/moonbeam-docs-$lang
if /usr/bin/git checkout master &&
/usr/bin/git fetch origin master &&
[ `/usr/bin/git rev-list HEAD...origin/master --count` != 0 ] ||
[ $force == 1 ]
then
echo . >>$LOGPATH
echo +++ $(date +%F' '%H:%M:%S) - Pulling Changes from Github... >>$LOGPATH
# pull changes
/usr/bin/git merge origin/master &>>$LOGPATH
# build mkdoc
echo docs updated, building $lang site >>$LOGPATH
cd ..
/usr/local/bin/mkdocs build --clean &>>$LOGPATH
# temporary patch to fix relative path of the assets to
# an absolute path in multi language folders
find $STATICPATH -type f -name index.html -exec sed -i "s|href=\"\/$lang\/assets\/|href=\"\/assets\/|g" '{}' \;
# remove images folder of the static sites as they are not necessary
rm -rf $STATICPATH/images/
### Making all external source links HTTPS
find $STATICPATH -type f -name "*.html" -exec sed -i "s|href=\"\/\/|href=\"https:\/\/|g" '{}' \;
find $STATICPATH -type f -name "*.html" -exec sed -i "s|src=\"\/\/|src=\"https:\/\/|g" '{}' \;
echo +++ Finished at $(date +%F' '%H:%M:%S) +++++++++++++++++++ >>$LOGPATH
fi
# reset file and directory permissions
chown root:users -R $DOCPATH
find $DOCPATH/ -type d -exec chmod 775 {} \;
find $DOCPATH/ -type f -exec chmod 664 {} \;
chown root:users -R $STATICPATH
find $STATICPATH/ -type d -exec chmod 775 {} \;
find $STATICPATH/ -type f -exec chmod 664 {} \;