forked from carpentries-i18n/i18n
-
Notifications
You must be signed in to change notification settings - Fork 14
/
wrapper.sh
771 lines (693 loc) · 26.1 KB
/
wrapper.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
#! /bin/bash
### example
# sh wrapper.sh --repo make-novice --locale ja --create
# sh wrapper.sh --repo make-novice --locale ja --import
# sh wrapper.sh --repo make-novice --locale ja --account GitHubUser --import
# sh wrapper.sh --repo r-novice-gapminder --locale ja --account swcarpentry-ja --import --webpages
# create (implemented): subroutine to create new PO files from an English lesson not currently being translated
# import (testing): subroutine to pull a lesson being translated from remote to make changes locally
# webpages (testing): subroutine to render webpages from current PO files and export Japanese lessons to remote repos
# update (to-do later): subroutine to pull updates from remote English lesson and merge based on archived ancestor (only new sections need to be translated)
pc_user=`whoami`
echo $pc_user account for pc `hostname`
git_user=`git config user.name`
remote_user=$git_user
git_email=`git config user.email`
remote_account=$git_user
echo $git_user \<${git_email}\> account detected for git
next=false
create=false
import=false
render=false
locale="default"
for op in "$@"; do
if $next; then
next=false;
continue;
fi
case "$op" in
-u|--user)
shift
if [[ $1 != "" ]]; then
# pass different git user name to local account
git_user="${1/%\//}"
# keep username case-sensitive
# git_user=`echo "$git_user" | tr '[:upper:]' '[:lower:]'`
next=true
shift
else
git_user=`git config user.name`
next=true
fi
;;
-c|--create)
shift
create=true
;;
-i|--import)
shift
import=true
;;
-a|--account)
shift
if [[ $1 != "" ]]; then
remote_user="${1/%\//}"
next=true
else
echo "specify remote account for: $git_user"
remote_user=$git_user
next=true
fi
shift
;;
-r|--repo)
shift
if [[ $1 != "" ]]; then
repo="${1/%\//}"
next=true
else
all_repo=true
next=true
fi
shift
;;
-l|--locale)
shift
if [[ $1 != "" ]]; then
locale="${1/%\//}"
next=true
shift
else
next=true
fi
;;
-w|--webpages)
shift
render=true
;;
-u|--update)
shift
update=true
;;
-*)
echo "Error: Invalid option: $op"
exit 1
;;
esac
done
if [[ $import == true ]]; then
if [[ $create == true ]]; then
echo "Warning: it is not recommended to --create and --import at the same time"
fi
create=$create
fi
if [[ -z $locale ]] || [[ ! ${#locale} -eq 2 ]] && [[ ! ${#locale} -eq 5 && $locale==*"_"* ]]; then
echo "must specify locale with \"--locale xx\" or \"--locale xx_YY\" for example:
English(Great Britain) (en_GB),
Deutsche (de),
Español (es),
Français (fr),
हिन्द(hi_IN),
한국어(ko_KR),
日本語 (ja),
Nederlands (nl)
Português(Brasil) (pt_BR)
中文(中华人民共和国) (zh_CN)
中文(中華民國) (zh_TW)
See here for a full list: http://docs.wp-event-organiser.com/i18n/locale-codes/
Note that Endonyms are often used (not English names)."
exit 1
else
lang=$(echo $locale | cut -d"_" -f1 | tr '[:upper:]' '[:lower:]')
if [[ ${#locale} -eq 5 && $locale==*"_"* ]]; then
country=$(echo $locale | cut -d"_" -f2 | tr '[:lower:]' '[:upper:]')
locale=${lang}_${country}
else
locale=${lang}
fi
if [[ $locale == "ja_JP" ]]; then
locale="ja"
fi
if [[ $locale == "en_US" ]]; then
locale="en"
fi
if [[ $locale == "es_LA" || $locale == "es_419" ]]; then
locale="es"
fi
if [[ $locale == "nl_NL" ]]; then
locale="nl"
fi
echo "locale: $locale"
fi
if [[ $import == true ]] || [[ $create == true ]]; then
if [[ -z $repo ]]; then
echo all available repos to import: $all_repos
else
echo repo to create or import: $repo
fi
fi
echo create ${repo} : $create
echo import ${repo} : $import
echo render webpages : $render
#check if remote i18n repo exists
echo https://github.com/${remote_user}/i18n.git
root_dir=`git ls-remote https://github.com/${remote_user}/i18n.git | grep "${locale}$" | wc -l`
echo i18n repo: $root_dir
if [ $root_dir -eq 1 ]; then
echo "remote found: https://github.com/${remote_user}/i18n.git"
elif [ $root_dir -eq 0 ]; then
echo remote not found for user repo: https://github.com/${remote_user}/i18n.git \n please create a fork and ${locale} branch
exit 1
else
echo ambiguous repo:
git ls-remote https://github.com/${remote_user}/i18n.git
exit 1
fi
#check if remote repo exists
root_dir=`git ls-remote https://github.com/${remote_user}/${repo}.git | grep "gh-pages$" | wc -l`
echo $repo repo: $root_dir
if [ $root_dir -eq 1 ]; then
echo "remote found: https://github.com/${remote_user}/${repo}.git"
elif [ $root_dir -eq 0 ]; then
echo remote not found for user repo: https://github.com/${remote_user}/${repo}.git \n please create a fork
exit 1
else
echo ambiguous repo:
git ls-remote https://github.com/${remote_user}/${repo}.git
exit 1
fi
if [[ $create == true ]]; then
echo "runnning"
if [[ -d i18n ]]; then
cd i18n
fi
#check if current working directory is i18n
wd="${PWD##*/}"
echo $wd
if [[ $wd != "i18n" ]]; then
echo "create i18n directory"
git clone https://github.com/${remote_user}/i18n.git
cd i18n
fi
git pull origin ${locale}
#checkout Japanese branch
git checkout ${locale}
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]; then
git remote remove remote-repo
fi
if [[ -z $GITHUB_TOKEN ]]; then
url=https://github.com/${remote_user}/i18n.git
else
url="https://${git_user}:${GITHUB_TOKEN}@github.com/${git_user}/i18n.git"
fi
git remote add remote-repo $url
git pull remote-repo ${locale}
#import submodules
git submodule init
git submodule add [email protected]:${remote_user}/${repo}
echo "update local submodules"
git submodule update -f --recursive $repo
#remove _locale directory (only translate English lessons)
for dir in `git submodule | grep "^+" | cut -d" " -f2`
do
if [ -d $dir ]
then
cd $dir
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]
then
git remote remove remote-repo
fi
#reset all repos to remote
if [[ -z $GITHUB_TOKEN ]]; then
url=https://github.com/${remote_user}/${dir}.git
else
url="https://${git_user}:${GITHUB_TOKEN}@github.com/${remote_user}/${dir}.git"
fi
git remote add remote-repo $url
if [[ `git branch -v | grep "master" | wc -l` -ge 1 ]]
then
git pull master -f
fi
git remote add remote-repo $url
if [[ `git branch -v | grep "gh-pages" | wc -l` -ge 1 ]]
then
git branch -D gh-pages
fi
git checkout -b gh-pages `git rev-list HEAD | tail -n 1`
git pull remote-repo gh-pages -f
git add -u
git commit -m "reset branch"
git checkout HEAD
rm -rf _locale
cd ..
fi
done
if [[ ! -z $repo ]]; then
if [[ -d $repo ]]; then
echo submodule $repo found
else
git submodule add [email protected]:${remote_user}-${locale}/{repo}.git
fi
fi
if [[ -z $repo ]];then
echo "warning $repo not found, specify --repo <lesson name> --create"
exit 1
fi
echo "run import on po4gitbook"
po4gitbook/update.sh > /dev/null 2>&1
echo "upated PO files exported"
if [[ -f po/${repo}.${locale}.po ]]; then
echo "Warning: file po/${repo}.${locale}.po already exists: check for conflicts and import"
exit 1
else
echo "creating PO file for $repo"
cp po/${repo}.pot po/${repo}.${locale}.po
git add po/${repo}.${locale}.po
#archive PO file from English lessons for merging updates
if [[ -f po/.ancestors/.${repo}.jp.po.ancestor ]]; then
echo "Warning file po/${repo}.${locale}.po already archived in po/.ancestors"
else
echo "archiving PO file for $repo"
mkdir -p po/.ancestors
cp po/${repo}.pot po/.ancestors/.${repo}.${locale}.po.ancestor
git add po/.ancestors/.${repo}.${locale}.po.ancestor
fi
#fill in missing information for Japanese
year=`date +%Y`
sed -i '1s/# SOME DESCRIPTIVE TITLE./# Japanese translation of the Software Carpentry ${repo} Lesson/g' po/${repo}.${locale}.po
sed -i "2s/# Copyright \(C\) YEAR THE PACKAGE\'S COPYRIGHT HOLDER/# Copyright \(C\) ${year} Software Carpentry Foundation; Japanese Translation Team/g" po/${repo}.${locale}.po
sed -i '3s/# This file is distributed under the same license as the PACKAGE package./# This file is distributed under the same license as the git4pobook package./g' po/${repo}.${locale}.po
sed -i '4s/# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./# ${git_user} <${git_email}>, ${year}./g' po/${repo}.${locale}.po
sed -i '12s/"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"/"Last-Translator: ${git_user} <${git_email}>\n"/g' po/${repo}.${locale}.po
sed -i '13s/Language-Team: LANGUAGE <[email protected]>\n/Language-Team: Japanese <[email protected]>\n/g' po/${repo}.${locale}.po
sed -i '14 i "Language: ${locale}\n"' po/${repo}.${locale}.po
#remove Japanese from LINGUAS if already exists
sed -i '1s/ ${locale}//g' po/LINGUAS
#add Japanese to LINGUAS
sed -i '1s/$/ ${locale}/g' po/LINGUAS
fi
git add po/${repo}.${locale}.po
echo "removing extraneous PO files"
rm po/*.pot
echo "run compile on po4gitbook to create new lessson"
po4gitbook/compile.sh > /dev/null 2>&1
echo lesson $repo created in _locale/${locale}/$repo
#restore _locale directory (only translate English lessons)
for dir in `git submodule | grep "^+" | cut -d" " -f2`
do
if [ -d $dir ]
then
cd $dir
git reset --hard
cd ..
fi
done
fi
if [[ $import == true ]]; then
echo "runnning"
if [[ -d i18n ]]; then
cd i18n
fi
#check if current working directory is i18n
wd="${PWD##*/}"
echo $wd
if [[ $wd != "i18n" ]]; then
echo "create i18n directory"
git clone https://github.com/${remote_user}/i18n.git
cd i18n
fi
#checkout Japanese branch
git checkout ${locale}
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]
then
git remote remove remote-repo
fi
git remote add remote-repo https://github.com/${remote_user}/i18n.git
git pull remote-repo ${locale}
#import submodules
git submodule init
git submodule foreach 'git pull remote-repo'
git submodule add https://github.com/${remote_user}/${repo}.git
echo "update local submodules"
git submodule update -f --recursive
#remove _locale directory (only translate English lessons)
for dir in `git submodule | grep "^+" | cut -d" " -f2`
do
if [ -d $dir ]
then
cd $dir
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]
then
git remote remove remote-repo
fi
#reset all repos to remote
if [[ -z $GITHUB_TOKEN ]]; then
url=https://github.com/${remote_user}/${dir}.git
else
url="https://${git_user}:${GITHUB_TOKEN}@github.com/${remote_user}/i18n.git"
fi
git remote add remote-repo $url
if [[ `git branch -v | grep "master" | wc -l` -ge 1 ]]
then
git pull master -f
fi
git remote add remote-repo $url
if [[ `git branch -v | grep "gh-pages" | wc -l` -ge 1 ]]
then
git branch -D gh-pages
fi
git checkout -b gh-pages `git rev-list HEAD | tail -n 1`
git pull remote-repo gh-pages -f
git add -u
git commit -m "reset branch"
git checkout HEAD
rm -rf _locale
cd ..
fi
done
if [[ ! -z $repo ]]; then
if [[ -d $repo ]]; then
echo "lesson repo found: ${repo} found"
else
echo "lesson repo ${repo} not found, run:\n sh wrapper.sh --repo ${repo} --create"
fi
fi
if [[ -z $repo ]];then
echo "warning $repo not found, specify --repo <lesson name> --import"
exit 1
fi
if [[ -f po/${repo}.${locale}.po ]]; then
echo "Warning: file po/${repo}.${locale}.po exists: please edit file and submit pull request"
exit 0
else
echo "Warning: file po/${repo}.${locale}.po not found, run:\n sh wrapper.sh --repo ${repo} --create"
exit 1
fi
fi
if [[ $render == true ]]; then
echo "runnning"
if [[ -d i18n ]]; then
cd i18n
fi
#check if current working directory is i18n
wd="${PWD##*/}"
echo $wd
if [[ $wd != "i18n" ]]; then
echo "create i18n directory"
git clone https://github.com/${remote_user}/i18n.git
cd i18n
fi
#checkout Japanese branch
git checkout ${locale}
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]
then
git remote remove remote-repo
fi
if [[ -z $GITHUB_TOKEN ]]; then
url=https://github.com/${remote_user}/i18n.git
else
url="https://${git_user}:${GITHUB_TOKEN}@github.com/${remote_user}/i18n.git"
fi
git remote add remote-repo $url
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -ge 1 ]]; then
git pull remote-repo ${locale}
fi
#import submodules
git submodule init
git submodule add https://github.com/${remote_user}/${repo}.git
echo "import local submodules"
git submodule update -f --recursive
if [[ ! -z $repo ]]; then
if [[ -d $repo ]]; then
echo "lesson repo found: ${repo} found"
else
echo "lesson repo ${repo} not found, run:\n sh wrapper.sh --repo ${repo} --create"
fi
fi
if [[ -z $repo ]];then
echo "warning $repo not found, specify --repo <lesson name> --import"
exit 1
fi
if [[ -d ${repo}/_locale ]]; then
rm -rf ${repo}/_locale
fi
if [[ -f po/${repo}.${locale}.po ]]; then
echo "File po/${repo}.${locale}.po exists: exporting translated lesson"
else
echo "Warning: file po/${repo}.${locale}.po not found, run:\n sh wrapper.sh --repo ${repo} --create"
exit 1
fi
#correct dates in headers
year=`date +%Y`
past_year=$(( $year-1 ))
#replace past year with current year
sed -i "2s/$past_year/$year/g" po/*.po
# append current year if different to previous year
sed -i "4s/, ${past_year}\./, ${past_year}, ${year}./g" po/*po
#create all Japanese lessons
mkdir -p locale
mkdir -p locale/${locale}
echo "run compile on po4gitbook"
po4gitbook/compile.sh > /dev/null 2>&1
#commit updates to source PO files
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -ge 1 ]]; then
git pull remote-repo ${locale}
fi
git add -u po/*${locale}.po
git commit -m "update PO files"
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -ge 1 ]]; then
git push remote-repo ${locale}
fi
echo "translated lessons from po/${repo}.${locale}.po exported to _locale/${locale}/$repo"
#check if remote translated lesson exists
lesson_dir=`git ls-remote https://github.com/${remote_user}/${repo}-${locale}.git | grep "master" | wc -l`
echo ${repo}-${locale} repo: $lesson_dir
if [ $lesson_dir -eq 1 ]; then
echo "remote found: https://github.com/${remote_user}/${repo}-${locale}.git"
elif [ $root_dir -eq 0 ]; then
echo remote not found for user repo: https://github.com/${remote_user}/${repo}-${locale}.git please create a new empty repo
exit 1
else
echo ambiguous repo:
git ls-remote https://github.com/${remote_user}/${repo}-${locale}.git
exit 1
fi
#create as submodule
#git submodule add https://github.com/${remote_user}/${repo}-${locale}.git _locale/${locale}/$repo
##git submodule absorbgitdirs <path>
#create external ${locale} repo
mkdir -p ../${repo}-${locale}
#add update lessons to remote
cd ../${repo}-${locale}
git init
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]
then
git remote remove remote-repo
fi
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -le 0 ]]; then
if [[ -z $GITHUB_TOKEN ]]; then
url=https://github.com/${remote_user}/${repo}-${locale}.git
else
url="https://${git_user}:${GITHUB_TOKEN}@github.com/${remote_user}/${repo}-${locale}.git"
fi
git remote add remote-repo $url
fi
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -ge 1 ]]; then
git pull remote-repo master
fi
#move files to external repo
rsync -r ../i18n/locale/${locale}/${repo}/*md .
if [ -f CONDUCT.md ]; then
mv CONDUCT.md CODE_OF_CONDUCT.md
fi
rsync -r ../i18n/locale/${locale}/${repo}/_episodes/*md _episodes
rsync -r ../i18n/locale/${locale}/${repo}/_extras/*md _extras
#correct links for locale
sed -i "s/permalink: \/conduct\//permalink: \/${locale}\/conduct\//g" CODE_OF_CONDUCT.md
sed -i "s/permalink: \/aio\//permalink: \/${locale}\/aio\//g" aio.md
sed -i "s/root: \.$/root: \/${locale}\/\npermalink: \/${locale}\/index.html/g" index.md
sed -i "4s/root: \.\.$/root\: \/${locale}\//g" reference.md setup.md LICENSE.md
sed -i "3s/root: \.$/root\: \/${locale}\//g" aio.md LICENSE.md
sed -i "4s/---/permalink: \/${locale}\/aio\/\n---/g" aio.md
sed -i "5s/permalink: \/LICENSE\//permalink: \/${locale}\/LICENSE\//g" LICENSE.md
sed -i "5s/---/permalink: \/${locale}\/LICENSE\/\n---/g" LICENSE.md
sed -i "s/permalink: \/setup\//permalink: \/${locale}\/setup\//g" setup.md
sed -i "s/permalink: \/reference\//permalink: \/${locale}\/reference\//g" reference.md
sed -i "s/permalink: \/about\//permalink: \/${locale}\/about\//g " _extras/about.md
sed -i "s/permalink: \/discuss\//permalink: \/${locale}\/discuss\//g " _extras/discuss.md
sed -i "s/permalink: \/figures\//permalink: \/${locale}\/figures\//g " _extras/figures.md
sed -i "s/permalink: \/guide\//permalink: \/${locale}\/guide\//g " _extras/guide.md
# remove files provided by template
rm -rf bin/boilerplate
rm -rf _layouts _includes _episodes_rmd assets bin code
#restore figures paths
sed -i "s;(../fig/;(../../../fig/;g" _episodes/*md _extras/*md
sed -i "s;\"../fig/;\"../../../fig/;g" _episodes/*md _extras/*md
#rm -rf _extras/figures.md
git add -u
#add changes
git add *
git add index.md LICENSE.md reference.md setup.md aio.md
git add CODE_OF_CONDUCT.md CONDUCT.md
git commit -m "update lesson files"
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -le 0 ]]; then
if [[ -z $GITHUB_TOKEN ]]; then
url=https://github.com/${remote_user}/${repo}-${locale}.git
else
url="https://${git_user}:${GITHUB_TOKEN}@github.com/${remote_user}/${repo}-${locale}.git"
fi
git remote add remote-repo $url
fi
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -ge 1 ]]; then
git push remote-repo master
fi
echo "lesson $repo-${locale} pushed to ${remote_user}/$repo-${locale}"
#update original lesson to import translated content
cd ../i18n # or English lesson
# restore to version from remote
git submodule update -f --recursive
if [[ ! -d ../${repo} ]]; then
if [[ -z $GITHUB_TOKEN ]]; then
url=$(echo "https://github.com/${remote_user}/${repo}.git")
else
url=$(echo "https://${git_user}:${GITHUB_TOKEN}@github.com/${remote_user}/${repo}.git")
fi
git clone -b gh-pages $url ../${repo}
fi
#create external repo
mkdir -p ../${repo}
#add update lessons to remote
cd ../${repo}
git init
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]
then
git remote remove remote-repo
fi
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -le 0 ]]; then
if [[ -z $GITHUB_TOKEN ]]; then
url=https://github.com/${remote_user}/${repo}.git
else
url="https://${git_user}:${GITHUB_TOKEN}@github.com/${remote_user}/${repo}.git"
fi
git remote add remote-repo $url
fi
if [[ `git branch -v | grep "gh-pages" | wc -l` -le 0 ]]; then
git checkout -b gh-pages
#git checkout `git rev-list --max-parents=0 HEAD | tail -n 1` -b gh-pages
fi
git checkout gh-pages
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -ge 1 ]]; then
git pull remote-repo gh-pages
git submodule update -f --recursive
fi
#rename code of conduct if needed
if [ -f CONDUCT.md ]; then
mv CONDUCT.md CODE_OF_CONDUCT.md
fi
#update links
# add title if missing
sed -i '3s/root: \./Title: "Licenses"\nroot: \./g' LICENSE.md
sed -i '3s/root: \./Title: "Contributor Code of Conduct"\nroot: \./g' CODE_OF_CONDUCT.md
sed -i '3s/root: \./Title: \Reference"\nroot: \./g' reference.md
sed -i '3s/root: \./Title: "Setup"\nroot: \./g' setup.md
# add root if missing
sed -i "3s/---/root: \.\n---/g" index.md
sed -i "3s/root: \//root: \./g" index.md
sed -i "4s/---/root: \.\n---/g" LICENSE.md CODE_OF_CONDUCT.md
sed -i "4s/---/root: \.\.\n---/g" reference.md setup.md
sed -i "3s/---/root: \.\n---/g" LICENSE.md CODE_OF_CONDUCT.md
sed -i "3s/---/root: \.\.\n---/g" reference.md setup.md
sed -i "3s/---/root: \.\n---/g" aio.md
# add permlink if missing
sed -i "s/root\: \/\$/root\: \/\npermalink\: index.html/g" index.md
sed -i "s/root\: \.\$/root\: \.\npermalink\: \/LICENSE\//g" LICENSE.md
sed -i "s/root\: \.\$/root\: \.\npermalink\: \/conduct\//g" CODE_OF_CONDUCT.md
sed -i "s/root\: \.\.\$/root\: \.\.\npermalink\: \/reference\//g" reference.md
sed -i "s/root\: \.\.\$/root\: \.\.\npermalink\: \/setup\//g" setup.md
sed -i "s/root\: \.\.\$/root\: \.\.\npermalink\: \/aio\//g" aio.md
# remove if appears twice
sed -i '5{/permalink: index\.html/d;}' index.md
sed -i "/^permalink\:/{x;s/^/n/;/^n\{2\}$/{x;d};x}" index.md
sed -i '6{/permalink\: \/LICENSE\//d;}' LICENSE.md
sed -i '6{/permalink\: \/conduct\//d;}' CODE_OF_CONDUCT.md
sed -i '6{/permalink\: \/reference\//d;}' reference.md
sed -i '6{/permalink\: \/setup\//d;}' setup.md
sed -i '5{/permalink\: \/aio\//d;}' aio.md
# mask figures for now
if [[ -f _extras/figures.md ]]; then
echo "---\nlayout: page\ntitle: Figures\n---" > _extras/figures.md
git add -u _extras/figures.md
fi
sed -i "s;(../../fig/;(../fig/;g" _episodes/*md _extras/*md
sed -i "s;\"../../fig/;\"../fig/;g" _episodes/*md _extras/*md
sed -i "s;(../fig/;(../../../fig/;g" _locale/${locale}/_episodes/*md _locale/${locale}/_extras/*md
sed -i "s;\"../fig/;\"../../../fig/;g" _locale/${locale}/_episodes/*md _locale/${locale}/_extras/*md
#add changes
git add -u
git add index.md LICENSE.md reference.md setup.md aio.md
if [[ -f CONDUCT.md ]]; then
git add CONDUCT.md
else
git add CODE_OF_CONDUCT.md
fi
git submodule update -f --recursive
git submodule add https://github.com/${remote_user}/${repo}.git ./_locale/${locale}
cd _locale/${locale}
git init
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]
then
git remote remove remote-repo
fi
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -le 0 ]]; then
git remote add remote-repo https://github.com/${remote_user}/${repo}-${locale}.git
fi
if [[ `git branch -v | grep "master" | wc -l` -le 0 ]]; then
git checkout -b master
fi
git checkout master
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -ge 1 ]]; then
git pull remote-repo master
fi
if [[ `git branch -v | grep "master" | wc -l` -le 0 ]]; then
git checkout -b master
fi
git checkout master
cd ../..
#push updated _locale lessons to English lesson
git checkout gh-pages
git pull remote-repo gh-pages
git add -u
git commit -m "update Japanese lessons"
if [ `git remote | grep "remote-repo" | wc -l` -ge 1 ]
then
git remote remove remote-repo
fi
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -le 0 ]]; then
if [[ -z $GITHUB_TOKEN ]]; then
url=https://github.com/${remote_user}/${repo}.git
else
url="https://${git_user}:${GITHUB_TOKEN}@github.com/${remote_user}/${repo}.git"
fi
git remote add remote-repo $url
fi
remotes=`git remote | grep "remote-repo" | wc -l`
if [[ remotes -ge 1 ]]; then
git push remote-repo gh-pages
echo "lesson $repo pushed to ${remote_user}/$repo with locale $repo-${locale}"
fi
cd ../i18n
git submodule update -f --recursive
fi
echo "run complete!"