Created
October 10, 2023 06:42
-
-
Save kosivantsov/d823334b0a5cf8a3917445c1b5893032 to your computer and use it in GitHub Desktop.
createTeamProjects.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Some permanent variables used for each created project/repository | |
ORG="capstanlqc-pisa" | |
THIS_STEP="trend-prepp" | |
TEAM="translators" | |
### omegat.project contents is stored in OMTPOJ variable: | |
IFS='' read -r -d '' OMTPOJ <<"EOF" | |
<?xml version='1.0' encoding='UTF-8' standalone='yes'?> | |
<!DOCTYPE omegat [ | |
<!ENTITY DOMAIN "XXX"> | |
<!ENTITY TARGET_LANG "XXX"> | |
<!ENTITY PREV_STEP ""> | |
<!ENTITY THIS_STEP "XXX"> | |
<!ENTITY THIS_REPO "pisa_2025ft_transfer_&TARGET_LANG;_&THIS_STEP;"> | |
]> | |
<omegat> | |
<project version="1.0"> | |
<source_dir>__DEFAULT__</source_dir> | |
<source_dir_excludes> | |
<mask>**/.svn/**</mask> | |
<mask>**/CVS/**</mask> | |
<mask>**/.cvs/**</mask> | |
<mask>**/.git/**</mask> | |
<mask>**/.hg/**</mask> | |
<mask>**/.repositories/**</mask> | |
<mask>**/desktop.ini</mask> | |
<mask>**/Thumbs.db</mask> | |
<mask>**/.DS_Store</mask> | |
<mask>**/~$*</mask> | |
</source_dir_excludes> | |
<target_dir>__DEFAULT__</target_dir> | |
<tm_dir>__DEFAULT__</tm_dir> | |
<glossary_dir>__DEFAULT__</glossary_dir> | |
<glossary_file>__DEFAULT__</glossary_file> | |
<dictionary_dir>__DEFAULT__</dictionary_dir> | |
<source_lang>en</source_lang> | |
<target_lang>&TARGET_LANG;</target_lang> | |
<source_tok>org.omegat.tokenizer.LuceneEnglishTokenizer</source_tok> | |
<target_tok>org.omegat.tokenizer.DefaultTokenizer</target_tok> | |
<sentence_seg>true</sentence_seg> | |
<support_default_translations>true</support_default_translations> | |
<remove_tags>false</remove_tags> | |
<repositories> | |
<repository type="git" url="&DOMAIN;/&THIS_REPO;.git"> | |
<!-- self --> | |
<mapping local="/" repository="/"/> | |
</repository> | |
<repository type="git" url="&DOMAIN;/pisa_2025ft_translation_common.git"> | |
<!-- source files --> | |
<mapping local="source/trend" repository="source/trend" /> | |
<!-- project settings --> | |
<mapping local="omegat/filters.xml" repository="config/filters.xml"/> | |
<mapping local="omegat/[email protected]" repository="config/[email protected]"/> | |
<mapping local="omegat/segmentation.conf" repository="config/segmentation.conf"/> | |
<!-- language assets --> | |
<mapping local="tm/auto/trend" repository="assets/pisa22/&TARGET_LANG;/"> | |
<excludes>**/*</excludes> | |
<includes>*_&TARGET_LANG;*</includes> | |
</mapping> | |
</repository> | |
</repositories> | |
</project> | |
</omegat> | |
EOF | |
### Check if locales.txt is passed and if it actually exists | |
case $1 in | |
"" ) | |
echo -e "The file locales.txt is not specified.\nExiting now..." | |
exit | |
;; | |
* ) | |
echo "Reading ${1}..." | |
if [ ! -f $1 ]; then | |
echo -e "The specified file does not exist.\nExiting now..." | |
exit | |
fi | |
;; | |
esac | |
### Since the file exists, lets read it and create and populate a repo for each locale | |
for loc in $(cat ${1}) ; do | |
REPO="pisa_2025ft_transfer_${loc}_${THIS_STEP}" | |
info="Creating a team project for $loc" | |
echo -e "\n$(printf "%0.s>" $(seq ${#info}))" | |
echo -e "${info}" | |
echo -e "Repository URL:\n$REPO" | |
yes no | gh repo create $ORG/$REPO --private --clone --team $TEAM | |
if [ -z "$TMPDIR" ]; then | |
TMPDIR="/tmp" | |
fi | |
LOCALCOPY=$(mktemp -d "$TMPDIR/${loc}_XXX") | |
cd $(dirname ${LOCALCOPY}) | |
gh repo clone $ORG/$REPO $(basename ${LOCALCOPY}) | |
cd ${LOCALCOPY} | |
echo -e "$OMTPOJ" |\ | |
sed "s/ENTITY DOMAIN \"XXX\">/ENTITY DOMAIN \"https:\/\/github.com\/$ORG\">/g" |\ | |
sed "s/ENTITY THIS_STEP \"XXX\">/ENTITY THIS_STEP \"$THIS_STEP\">/g" |\ | |
sed "s/TARGET_LANG \"XXX\">/TARGET_LANG \"$loc\">/g" > omegat.project | |
git add omegat.project | |
git commit -m "Add omegat.project using the script" | |
git push | |
rm -rf ${LOCALCOPY} | |
info="Team project for $loc has been created" | |
echo -e "${info}" | |
echo "$(printf "%0.s<" $(seq ${#info}))" | |
done | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment