2024-07-31
This commit is contained in:
parent
d59da594ba
commit
9fe170e09b
14 changed files with 172 additions and 180 deletions
|
@ -10,7 +10,7 @@
|
|||
│ ├─ <a href='bash_scripts/README.md'>README.md</a>
|
||||
│ ├─ <a href='bash_scripts/archive_backup.sh'>archive_backup.sh</a>
|
||||
│ ├─ <a href='bash_scripts/archive_cleanup.sh'>archive_cleanup.sh</a>
|
||||
│ ├─ <a href='bash_scripts/archive_packages.sh'>archive_packages.sh</a>
|
||||
│ ├─ <a href='bash_scripts/archive_packaging.sh'>archive_packaging.sh</a>
|
||||
│ ├─ <a href='bash_scripts/info_param.sh'>info_param.sh</a>
|
||||
│ ├─ <a href='bash_scripts/info_references.sh'>info_references.sh</a>
|
||||
│ ├─ <a href='bash_scripts/info_tree_license.sh'>info_tree_license.sh</a>
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
Creating an archive, switching the domain, composing scripts and creating repositories for publishing.
|
||||
|
||||
| № | Bash scripts | Actions performed |
|
||||
|---|:-----------------------------------------------|:--------------------------------------------------------------------------------------------|
|
||||
| 1 | [**archive_backup.sh**](archive_backup.sh) | Creating a common archive for the directories of projects on the current date. |
|
||||
| | [archive_cleanup.sh](archive_cleanup.sh) | Deleting files and folders from the directories of projects before restoring the archive. |
|
||||
| | [archive_packages.sh](archive_packages.sh) | Building websites, creating and copying archives for deployment. |
|
||||
| 2 | [**info_param.sh**](info_param.sh) | Parameter for other scripts. Switching the domain of the remote repository. |
|
||||
| | [info_references.sh](info_references.sh) | Updating the domain of a remote repository in cross-references in descriptions. |
|
||||
| | [info_tree_license.sh](info_tree_license.sh) | Building a directory tree for each project and copying license files. |
|
||||
| 3 | [**repo_compose.sh**](repo_compose.sh) | Composing scripts with parameters and copying them to the directories of projects. |
|
||||
| | [repo_gitea.tmpl.sh](repo_gitea.tmpl.sh) | Script template without parameters to create a remote repository gitea. |
|
||||
| | [repo_gitlab.tmpl.sh](repo_gitlab.tmpl.sh) | Script template without parameters to create a remote repository gitlab. |
|
||||
| | [repo_local.tmpl.sh](repo_local.tmpl.sh) | Script template without parameters to create a local repository. |
|
||||
| 4 | [**repo_orchestrate.sh**](repo_orchestrate.sh) | Parallel execution of scripts and creation of repositories for the directories of projects. |
|
||||
| № | Bash scripts | Actions performed |
|
||||
|---|:-----------------------------------------------|:------------------------------------------------------------------------------------------------|
|
||||
| 1 | [**archive_backup.sh**](archive_backup.sh) | Creating a common archive for the directories of projects on the current date. |
|
||||
| | [archive_cleanup.sh](archive_cleanup.sh) | Deleting files and folders from the directories of projects before restoring the archive. |
|
||||
| | [archive_packaging.sh](archive_packaging.sh) | Building websites, packaging and copying archives for deployment. |
|
||||
| 2 | [**info_param.sh**](info_param.sh) | Parameter for other scripts. Switching the domain of the remote repository. |
|
||||
| | [info_references.sh](info_references.sh) | Updating the domain of a remote repository in cross-references in descriptions. |
|
||||
| | [info_tree_license.sh](info_tree_license.sh) | Building a directory tree for each project and copying license files. |
|
||||
| 3 | [**repo_compose.sh**](repo_compose.sh) | Creating scripts from templates with parameters and saving them in the directories of projects. |
|
||||
| | [repo_gitea.tmpl.sh](repo_gitea.tmpl.sh) | Script template without parameters to create a remote repository gitea. |
|
||||
| | [repo_gitlab.tmpl.sh](repo_gitlab.tmpl.sh) | Script template without parameters to create a remote repository gitlab. |
|
||||
| | [repo_local.tmpl.sh](repo_local.tmpl.sh) | Script template without parameters to create a local repository git. |
|
||||
| 4 | [**repo_orchestrate.sh**](repo_orchestrate.sh) | Parallel execution of scripts and creation of repositories for the directories of projects. |
|
||||
|
||||
## Directories of projects
|
||||
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
Создание архива, переключение домена, составление скриптов и создание репозиториев для публикации.
|
||||
|
||||
| № | Скрипты Bash | Выполняемые действия |
|
||||
|---|:-----------------------------------------------|:---------------------------------------------------------------------------------|
|
||||
| 1 | [**archive_backup.sh**](archive_backup.sh) | Создание общего архива для каталогов проектов на текущую дату. |
|
||||
| | [archive_cleanup.sh](archive_cleanup.sh) | Удаление файлов и папок из каталогов проектов перед восстановлением архива. |
|
||||
| | [archive_packages.sh](archive_packages.sh) | Сборка вёб-сайтов, создание и копирование архивов для развёртывания. |
|
||||
| 2 | [**info_param.sh**](info_param.sh) | Параметр для других скриптов. Переключение домена удалённого репозитория. |
|
||||
| | [info_references.sh](info_references.sh) | Обновление домена удалённого репозитория в перекрёстных ссылках в описаниях. |
|
||||
| | [info_tree_license.sh](info_tree_license.sh) | Построение дерева каталогов для каждого проекта и копирование файлов лицензии. |
|
||||
| 3 | [**repo_compose.sh**](repo_compose.sh) | Составление скриптов с параметрами и копирование их в каталоги проектов. |
|
||||
| | [repo_gitea.tmpl.sh](repo_gitea.tmpl.sh) | Шаблон скрипта без параметров для создания удалённого репозитория gitea. |
|
||||
| | [repo_gitlab.tmpl.sh](repo_gitlab.tmpl.sh) | Шаблон скрипта без параметров для создания удалённого репозитория gitlab. |
|
||||
| | [repo_local.tmpl.sh](repo_local.tmpl.sh) | Шаблон скрипта без параметров для создания локального репозитория. |
|
||||
| 4 | [**repo_orchestrate.sh**](repo_orchestrate.sh) | Параллельное выполнение скриптов и создание репозиториев для каталогов проектов. |
|
||||
| № | Скрипты Bash | Выполняемые действия |
|
||||
|---|:-----------------------------------------------|:----------------------------------------------------------------------------------|
|
||||
| 1 | [**archive_backup.sh**](archive_backup.sh) | Создание общего архива для каталогов проектов на текущую дату. |
|
||||
| | [archive_cleanup.sh](archive_cleanup.sh) | Удаление файлов и папок из каталогов проектов перед восстановлением архива. |
|
||||
| | [archive_packaging.sh](archive_packaging.sh) | Сборка вёб-сайтов, упаковка и копирование архивов для развёртывания. |
|
||||
| 2 | [**info_param.sh**](info_param.sh) | Параметр для других скриптов. Переключение домена удалённого репозитория. |
|
||||
| | [info_references.sh](info_references.sh) | Обновление домена удалённого репозитория в перекрёстных ссылках в описаниях. |
|
||||
| | [info_tree_license.sh](info_tree_license.sh) | Построение дерева каталогов для каждого проекта и копирование файлов лицензии. |
|
||||
| 3 | [**repo_compose.sh**](repo_compose.sh) | Создание скриптов из шаблонов с параметрами и сохранение их в каталогах проектов. |
|
||||
| | [repo_gitea.tmpl.sh](repo_gitea.tmpl.sh) | Шаблон скрипта без параметров для создания удалённого репозитория gitea. |
|
||||
| | [repo_gitlab.tmpl.sh](repo_gitlab.tmpl.sh) | Шаблон скрипта без параметров для создания удалённого репозитория gitlab. |
|
||||
| | [repo_local.tmpl.sh](repo_local.tmpl.sh) | Шаблон скрипта без параметров для создания локального репозитория git. |
|
||||
| 4 | [**repo_orchestrate.sh**](repo_orchestrate.sh) | Параллельное выполнение скриптов и создание репозиториев для каталогов проектов. |
|
||||
|
||||
## Каталоги проектов
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
echo "Создание общего архива для каталогов проектов на текущую дату."
|
||||
cd ../..
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
filename="pomodoro-$(date '+%Y-%m-%d').zip"
|
||||
rm -rf "$filename"
|
||||
7z a -tzip -ssw -mx9 -r0 "$filename" ./* -xr!".idea" -xr!".git" -x!"*.iml" \
|
||||
-x!"*.gem" -x!"*.lock" -x!"*.zip" -x!"_site*" -x!".token_*" -x!".repo_*"
|
||||
7z a -tzip "$filename" . -xr!".git" -xr!".idea" -xr!"*.iml" -xr!"*.zip" \
|
||||
-xr!"*.gem" -xr!"*.lock" -xr!"_site*" -xr!".token_*" -xr!".repo_*"
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#!/bin/bash
|
||||
echo "Удаление файлов и папок из каталогов проектов перед восстановлением архива."
|
||||
echo "Отмена" && exit 0; # предохранитель
|
||||
cd ..
|
||||
echo "ОТМЕНА" && exit 0 # предохранитель
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
# обходим все репозитории, расположенные на одном уровне с текущим
|
||||
find .. -mindepth 1 -maxdepth 1 -type d | sort -r | while read -r dir; do
|
||||
find . -mindepth 1 -maxdepth 1 -type d | sort -r | while read -r dir; do
|
||||
echo "Обработка: $dir"
|
||||
# заходим в каталог, иначе пропускаем итерацию
|
||||
cd "$dir" || continue
|
||||
# удаляем вложенные файлы и папки кроме папок '.git' и '.idea'
|
||||
find . -mindepth 1 -maxdepth 1 -type f,d -not -name '.git' -not -name '.idea' -print0 | xargs -0 rm -r
|
||||
# удаляем вложенные файлы и папки кроме папок ".git" и ".idea"
|
||||
find "$dir" -mindepth 1 -maxdepth 1 -type f,d -not -regex ".*\.git\|.*\.idea" -print0 | xargs -0 rm -r
|
||||
done
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
#!/bin/bash
|
||||
echo "Сборка вёб-сайтов, создание и копирование архивов для развёртывания."
|
||||
cd ..
|
||||
currentTimeMillis=$(date '+%s%3N')
|
||||
for ((i = 1; i <= 6; i++)); do
|
||||
echo "Обработка: pomodoro$i"
|
||||
cd "../pomodoro$i" || continue
|
||||
./build.sh
|
||||
./package.sh
|
||||
cp -v "pomodoro$i.zip" ..
|
||||
done
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$currentTimeMillis")) мс."
|
16
bash_scripts/archive_packaging.sh
Executable file
16
bash_scripts/archive_packaging.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
echo "Сборка вёб-сайтов, упаковка и копирование архивов для развёртывания."
|
||||
# обработка репозитория вёб-сайта
|
||||
function packaging {
|
||||
echo "Обработка: pomodoro$1"
|
||||
cd "./pomodoro$1" || return
|
||||
./build.sh >/dev/null
|
||||
./package.sh >/dev/null
|
||||
cp -v "pomodoro$1.zip" ..
|
||||
}
|
||||
export -f packaging
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
time_ms="$(date '+%s%3N')"
|
||||
# запуск параллельной обработки репозиториев всех вёб-сайтов
|
||||
printf '%s\0' {1..6} | xargs -I{} -n1 -0 -P0 bash -c 'packaging "{}"'
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
|
|
@ -1,27 +1,32 @@
|
|||
#!/bin/bash
|
||||
echo "Обновление домена удалённого репозитория в перекрёстных ссылках в описаниях."
|
||||
remote="git.org.ru" && source info_param.sh
|
||||
export remote="git.org.ru" && source info_param.sh
|
||||
# экранируем точки в названии домена
|
||||
domain="${remote//"."/"\."}"
|
||||
export domain="${remote//"."/"\."}"
|
||||
# название домена в верхнем регистре
|
||||
DOMAIN="${domain^^}"
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
# обходим все репозитории, расположенные на одном уровне с текущим
|
||||
find . -type f -name 'README*.md' | sort -r | while read -r file; do
|
||||
echo "$remote => $file"
|
||||
export DOMAIN="${domain^^}"
|
||||
# обработка информационных файлов
|
||||
function references {
|
||||
echo "$remote => $1"
|
||||
# сбрасываем значения параметров
|
||||
sed -i 's/gitea\.com/tmp_stub/g' "$file"
|
||||
sed -i 's/GITEA\.COM/TMP_STUB/g' "$file"
|
||||
sed -i 's/git\.org\.ru/tmp_stub/g' "$file"
|
||||
sed -i 's/GIT\.ORG\.RU/TMP_STUB/g' "$file"
|
||||
sed -i 's/hub\.mos\.ru/tmp_stub/g' "$file"
|
||||
sed -i 's/HUB\.MOS\.RU/TMP_STUB/g' "$file"
|
||||
sed -i "s|gitea\.com|tmp_stub|g" "$1"
|
||||
sed -i "s|GITEA\.COM|TMP_STUB|g" "$1"
|
||||
sed -i "s|git\.org\.ru|tmp_stub|g" "$1"
|
||||
sed -i "s|GIT\.ORG\.RU|TMP_STUB|g" "$1"
|
||||
sed -i "s|hub\.mos\.ru|tmp_stub|g" "$1"
|
||||
sed -i "s|HUB\.MOS\.RU|TMP_STUB|g" "$1"
|
||||
# устанавливаем значения параметров
|
||||
sed -i 's/tmp_stub/'$domain'/g' "$file"
|
||||
sed -i 's/TMP_STUB/'$DOMAIN'/g' "$file"
|
||||
sed -i "s|tmp_stub|$domain|g" "$1"
|
||||
sed -i "s|TMP_STUB|$DOMAIN|g" "$1"
|
||||
if [ "$remote" == "hub.mos.ru" ]; then
|
||||
sed -i 's/src\/branch/blob/g' "$file"
|
||||
sed -i "s|src/branch|blob|g" "$1"
|
||||
else
|
||||
sed -i 's/blob/src\/branch/g' "$file"
|
||||
sed -i "s|blob|src/branch|g" "$1"
|
||||
fi
|
||||
done
|
||||
}
|
||||
export -f references
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
time_ms="$(date '+%s%3N')"
|
||||
# запуск параллельной обработки информационных файлов "README" в подкаталогах репозиториев
|
||||
find . -type f -name "README*.md" -print0 | xargs -I{} -n1 -0 -P0 bash -c 'references "{}"'
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
|
||||
|
|
|
@ -38,15 +38,16 @@ function directory_tree {
|
|||
done
|
||||
fi
|
||||
}
|
||||
cd .. # выходим из папки в корень репозитория
|
||||
basedir=$(pwd) # текущий репозиторий
|
||||
currentTimeMillis=$(date '+%s%3N')
|
||||
# обходим все репозитории, расположенные на одном уровне с текущим
|
||||
find .. -mindepth 1 -maxdepth 1 -type d | sort -r | while read -r dir; do
|
||||
echo "Обработка: $dir"
|
||||
# заходим в каталог, иначе пропускаем итерацию
|
||||
cd "$dir" || continue
|
||||
# строка исключений для 'ls' из списка '.gitignore' — неотслеживаемые файлы
|
||||
# копирование файлов лицензии и построение дерева каталогов
|
||||
function tree_license {
|
||||
echo "Обработка: $1"
|
||||
cd "$1" || return
|
||||
# копирование файлов из этого репозитория во все остальные
|
||||
if [ "$1" != "./pomodoro" ]; then
|
||||
cp -f ../pomodoro/CONTRIBUTING.md .
|
||||
cp -f ../pomodoro/*LICENSE* .
|
||||
fi
|
||||
# строка исключений для "ls" из списка ".gitignore" — неотслеживаемые файлы
|
||||
exclusions="-I \".git\" $(sed 's/^/ -I "/;s/$/"/' .gitignore | tr -d '\n')"
|
||||
# помещаем дерево в контейнер, добавляем заголовок и выводим в файл
|
||||
{
|
||||
|
@ -55,12 +56,10 @@ find .. -mindepth 1 -maxdepth 1 -type d | sort -r | while read -r dir; do
|
|||
directory_tree .
|
||||
echo -e "\n</pre>"
|
||||
} >DIRECTORY_TREE.md
|
||||
# копирование файлов из этого репозитория во все остальные
|
||||
if [ "${dir##*/}" != "${basedir##*/}" ]; then
|
||||
rm CONTRIBUTING.md
|
||||
rm ./*LICENSE*
|
||||
cp "$basedir"/CONTRIBUTING.md .
|
||||
cp "$basedir"/*LICENSE* .
|
||||
fi
|
||||
done
|
||||
echo "Время выполнения: $(("$(date '+%s%3N')" - "$currentTimeMillis")) мс."
|
||||
}
|
||||
export -f tree_license directory_tree list_directory_contents
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
time_ms="$(date '+%s%3N')"
|
||||
# запуск параллельной обработки всех репозиториев, расположенных на одном уровне с текущим
|
||||
find . -mindepth 1 -maxdepth 1 -type d -print0 | xargs -I{} -n1 -0 -P0 bash -c 'tree_license "{}"'
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
|
||||
|
|
|
@ -1,49 +1,37 @@
|
|||
#!/bin/bash
|
||||
echo "Составление скриптов с параметрами и копирование их в каталоги проектов."
|
||||
remote="git.org.ru" && source info_param.sh
|
||||
basedir=$(pwd)
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
# обходим все репозитории, расположенные на одном уровне с текущим
|
||||
find . -mindepth 1 -maxdepth 1 -type d | sort -r | while read -r dir; do
|
||||
echo "Обработка: $dir"
|
||||
# добавляем исключение в список '.gitignore', если ещё не добавлено
|
||||
if [ ! -f "$dir"/.gitignore ] || [ "$(grep -cx "\.repo_\*" "$dir"/.gitignore)" == 0 ]; then
|
||||
echo ".repo_*" >>"$dir"/.gitignore
|
||||
echo "Обновлён файл .gitignore"
|
||||
echo "Создание скриптов из шаблонов с параметрами и сохранение их в каталогах проектов."
|
||||
export remote="git.org.ru" && source info_param.sh
|
||||
export basedir="$PWD" # текущая папка
|
||||
# обновление списка исключений
|
||||
function update_gitignore {
|
||||
# добавляем исключение в список ".gitignore", если оно ещё не добавлено
|
||||
if [ ! -f "$1/.gitignore" ] || [ "$(grep -cx "\.repo_\*" "$1/.gitignore")" == 0 ]; then
|
||||
echo ".repo_*" >>"$1/.gitignore"
|
||||
echo "Обновлён файл: $1/.gitignore"
|
||||
fi
|
||||
}
|
||||
# создание скриптов из шаблонов с параметрами
|
||||
function compose {
|
||||
echo "Обработка: $1"
|
||||
update_gitignore "$1"
|
||||
# параметры для шаблонов
|
||||
dir="${1##*/}"
|
||||
owner="golovin"
|
||||
repo=${dir##*/}
|
||||
repo="$dir"
|
||||
description=""
|
||||
type="usr"
|
||||
wiki=""
|
||||
# оглавления по страницам сайтов
|
||||
if [ -f "$dir"/WIKI.md ]; then
|
||||
if [ "$remote" == "hub.mos.ru" ]; then
|
||||
wiki=$(uni2ascii -a U -qpsn "$dir"/WIKI.md)
|
||||
else
|
||||
wiki=$(basenc "$dir"/WIKI.md --base64 -w0)
|
||||
fi
|
||||
fi
|
||||
# краткие описания для репозиториев
|
||||
if [[ "$dir" =~ "pomodoro" ]]; then
|
||||
if [[ "$dir" =~ [[:digit:]] ]]; then
|
||||
owner="pomodoro"
|
||||
repo=${dir//[^[:digit:]]/}
|
||||
type="org"
|
||||
if [[ "$dir" =~ "1" ]]; then
|
||||
description="Трёхмерная графика на JavaScript"
|
||||
elif [[ "$dir" =~ "2" ]]; then
|
||||
description="Декартово произведение, комбинаторика"
|
||||
elif [[ "$dir" =~ "3" ]]; then
|
||||
description="Умножение матриц и повороты"
|
||||
elif [[ "$dir" =~ "4" ]]; then
|
||||
description="Практическая философия, поэзия и юмор"
|
||||
elif [[ "$dir" =~ "5" ]]; then
|
||||
description="Рисуем картинки текстом"
|
||||
elif [[ "$dir" =~ "6" ]]; then
|
||||
description="Пустой"
|
||||
fi
|
||||
repo="${dir//[^[:digit:]]/}"
|
||||
case "$repo" in
|
||||
"1") description="Трёхмерная графика на JavaScript" ;;
|
||||
"2") description="Декартово произведение, комбинаторика" ;;
|
||||
"3") description="Умножение матриц и повороты" ;;
|
||||
"4") description="Практическая философия, поэзия и юмор" ;;
|
||||
"5") description="Рисуем картинки текстом" ;;
|
||||
"6") description="Пустой" ;;
|
||||
*) return ;; # шесть помидорных вёб-сайтов
|
||||
esac
|
||||
description+=" — https://$owner$repo.mircloud.ru"
|
||||
else
|
||||
description="Описание и оглавление"
|
||||
|
@ -53,15 +41,22 @@ find . -mindepth 1 -maxdepth 1 -type d | sort -r | while read -r dir; do
|
|||
elif [[ "$dir" =~ "older-tomato" ]]; then
|
||||
description="Тема оформления / Старый помидор"
|
||||
fi
|
||||
wiki="" # оглавление по страницам вёб-сайта
|
||||
if [ -f "$1/WIKI.md" ]; then
|
||||
if [ "$remote" == "hub.mos.ru" ]; then
|
||||
wiki="$(uni2ascii -a U -qpsn "$1/WIKI.md")"
|
||||
else
|
||||
wiki="$(basenc "$1/WIKI.md" --base64 -w0)"
|
||||
fi
|
||||
fi
|
||||
# скрипт для создания удалённого репозитория
|
||||
{
|
||||
echo "#!/bin/bash"
|
||||
echo "remote=\"$remote\""
|
||||
echo "user=\"golovin\""
|
||||
echo "owner=\"$owner\""
|
||||
echo "user=\"golovin\""
|
||||
echo "repo=\"$repo\""
|
||||
echo "description=\"$description\""
|
||||
echo "type=\"$type\""
|
||||
echo "wiki=\"$wiki\""
|
||||
if [ "$remote" == "hub.mos.ru" ]; then
|
||||
echo "token=\"$(cat "$basedir/.token_gitlab")\""
|
||||
|
@ -70,14 +65,20 @@ find . -mindepth 1 -maxdepth 1 -type d | sort -r | while read -r dir; do
|
|||
echo "token=\"$(cat "$basedir/.token_gitea")\""
|
||||
cat "$basedir/repo_gitea.tmpl.sh"
|
||||
fi
|
||||
} >"$dir"/.repo_remote.sh && chmod +x "$dir"/.repo_remote.sh
|
||||
} >"$1/.repo_remote.sh" && chmod +x "$1/.repo_remote.sh"
|
||||
# скрипт для создания локального репозитория
|
||||
{
|
||||
echo "#!/bin/bash"
|
||||
echo "remote=\"$remote\""
|
||||
echo "owner=\"$owner\""
|
||||
echo "repo=\"$repo\""
|
||||
echo "folder=\"${dir##*/}\""
|
||||
echo "dir=\"$dir\""
|
||||
cat "$basedir/repo_local.tmpl.sh"
|
||||
} >"$dir"/.repo_local.sh && chmod +x "$dir"/.repo_local.sh
|
||||
done
|
||||
} >"$1/.repo_local.sh" && chmod +x "$1/.repo_local.sh"
|
||||
}
|
||||
export -f compose update_gitignore
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
time_ms="$(date '+%s%3N')"
|
||||
# запуск параллельной обработки всех репозиториев, расположенных на одном уровне с текущим
|
||||
find . -mindepth 1 -maxdepth 1 -type d -print0 | xargs -I{} -n1 -0 -P0 bash -c 'compose "{}"'
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
if [ -z "$remote" ] || [ -z "$token" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$description" ] || [ -z "$user" ] || [ -z "$type" ]; then
|
||||
echo "Не указаны обязательные параметры." && exit 2
|
||||
if [ -z "$remote" ] || [ -z "$token" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$description" ] || [ -z "$user" ]; then
|
||||
echo "Не указаны обязательные параметры." && exit 1
|
||||
fi
|
||||
if [ -z "$1" ]; then
|
||||
echo "Создание удалённого репозитория для текущего каталога."
|
||||
fi
|
||||
seconds=5
|
||||
currentTimeMillis=$(date '+%s%3N')
|
||||
time_ms="$(date '+%s%3N')"
|
||||
if [ -z "$1" ] || [ "$1" == "delete" ]; then
|
||||
echo "Удаление старого репозитория."
|
||||
curl -X DELETE "https://$remote/api/v1/repos/$owner/$repo" \
|
||||
-H "Authorization: token $token" \
|
||||
-H "Accept: application/json" -i
|
||||
echo "Ожидание $seconds с."
|
||||
sleep $seconds
|
||||
if [ "$1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
sleep "$seconds"
|
||||
fi
|
||||
if [ -z "$1" ] || [ "$1" == "create" ]; then
|
||||
echo "Создание нового репозитория пользователя."
|
||||
|
@ -24,18 +21,15 @@ if [ -z "$1" ] || [ "$1" == "create" ]; then
|
|||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/json" -d "{ \"name\": \"$repo\", \"description\": \"$description\" }" -i
|
||||
echo "Ожидание $seconds с."
|
||||
sleep $seconds
|
||||
if [ "$type" == "org" ]; then
|
||||
sleep "$seconds"
|
||||
if [ "$user" != "$owner" ]; then
|
||||
echo "Перемещение репозитория в группу."
|
||||
curl -X POST "https://$remote/api/v1/repos/$user/$repo/transfer" \
|
||||
-H "Authorization: token $token" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/json" -d "{ \"new_owner\": \"$owner\" }" -i
|
||||
echo "Ожидание $seconds с."
|
||||
sleep $seconds
|
||||
fi
|
||||
if [ "$1" ]; then
|
||||
exit 0
|
||||
sleep "$seconds"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$1" ] || [ "$1" == "options" ]; then
|
||||
|
@ -61,10 +55,9 @@ if [ -z "$1" ] || [ "$1" == "options" ]; then
|
|||
\"has_pull_requests\": false,
|
||||
\"has_releases\": false,
|
||||
\"has_wiki\": $has_wiki }" -i
|
||||
# Метод API появился в версии 1.21.0
|
||||
echo "Добавление аватарки для репозитория."
|
||||
picture=$repo
|
||||
if [ "$type" == "org" ]; then
|
||||
picture="$repo"
|
||||
if [ "$user" != "$owner" ]; then
|
||||
picture="website"
|
||||
fi
|
||||
avatar=$(basenc "../pomodoro/pictures/$picture.jpg" --base64 -w0)
|
||||
|
@ -72,8 +65,7 @@ if [ -z "$1" ] || [ "$1" == "options" ]; then
|
|||
-H "Authorization: token $token" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/json" -d "{ \"image\": \"$avatar\" }" -i
|
||||
if [ "$1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
echo "Время создания удалённого репозитория: $(("$(date '+%s%3N')" - "$currentTimeMillis")) мс."
|
||||
if [ -z "$1" ]; then
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
|
||||
fi
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
if [ -z "$remote" ] || [ -z "$token" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$description" ] || [ -z "$user" ] || [ -z "$type" ]; then
|
||||
echo "Не указаны обязательные параметры." && exit 2
|
||||
if [ -z "$remote" ] || [ -z "$token" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$description" ] || [ -z "$user" ]; then
|
||||
echo "Не указаны обязательные параметры." && exit 1
|
||||
fi
|
||||
if [ -z "$1" ]; then
|
||||
echo "Создание удалённого репозитория для текущего каталога."
|
||||
fi
|
||||
seconds=5
|
||||
currentTimeMillis=$(date '+%s%3N')
|
||||
time_ms="$(date '+%s%3N')"
|
||||
if [ -z "$1" ] || [ "$1" == "delete" ]; then
|
||||
echo "Удаление старого репозитория."
|
||||
curl -i -X DELETE "https://$remote/api/v4/projects/$owner%2F$repo" \
|
||||
|
@ -13,10 +13,7 @@ if [ -z "$1" ] || [ "$1" == "delete" ]; then
|
|||
-H "Content-Type: application/json" -d "{\"permanently_remove\": \"true\", \"full_path\": \"$owner/$repo\"}"
|
||||
echo
|
||||
echo "Ожидание $seconds с."
|
||||
sleep $seconds
|
||||
if [ "$1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
sleep "$seconds"
|
||||
fi
|
||||
if [ -z "$1" ] || [ "$1" == "create" ]; then
|
||||
echo "Создание нового репозитория пользователя."
|
||||
|
@ -25,17 +22,14 @@ if [ -z "$1" ] || [ "$1" == "create" ]; then
|
|||
-H "Content-Type: application/json" -d "{\"name\": \"$repo\", \"description\": \"$description\"}"
|
||||
echo
|
||||
echo "Ожидание $seconds с."
|
||||
sleep $seconds
|
||||
if [ "$type" == "org" ]; then
|
||||
sleep "$seconds"
|
||||
if [ "$user" != "$owner" ]; then
|
||||
echo "Перемещение репозитория в группу."
|
||||
curl -i -X PUT "https://$remote/api/v4/projects/$user%2F$repo/transfer?namespace=$owner" \
|
||||
-H "PRIVATE-TOKEN: $token"
|
||||
echo
|
||||
echo "Ожидание $seconds с."
|
||||
sleep $seconds
|
||||
fi
|
||||
if [ "$1" ]; then
|
||||
exit 0
|
||||
sleep "$seconds"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$1" ] || [ "$1" == "options" ]; then
|
||||
|
@ -89,16 +83,15 @@ if [ -z "$1" ] || [ "$1" == "options" ]; then
|
|||
\"group_runners_enabled\": \"false\"}"
|
||||
echo
|
||||
echo "Добавление аватарки для репозитория."
|
||||
picture=$repo
|
||||
if [ "$type" == "org" ]; then
|
||||
picture="$repo"
|
||||
if [ "$user" != "$owner" ]; then
|
||||
picture="website"
|
||||
fi
|
||||
curl -i -X PUT "https://$remote/api/v4/projects/$owner%2F$repo" \
|
||||
-H "PRIVATE-TOKEN: $token" \
|
||||
-F "avatar=@../pomodoro/pictures/$picture.jpg"
|
||||
echo
|
||||
if [ "$1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
echo "Время создания удалённого репозитория: $(("$(date '+%s%3N')" - "$currentTimeMillis")) мс."
|
||||
if [ -z "$1" ]; then
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
|
||||
fi
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
if [ -z "$remote" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$folder" ]; then
|
||||
echo "Не указаны обязательные параметры." && exit 2
|
||||
if [ -z "$remote" ] || [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$dir" ]; then
|
||||
echo "Не указаны обязательные параметры." && exit 1
|
||||
fi
|
||||
echo "Создание локального репозитория, подключение к удалённому и передача данных."
|
||||
seconds=3
|
||||
currentTimeMillis=$(date '+%s%3N')
|
||||
time_ms="$(date '+%s%3N')"
|
||||
rm -rf .git
|
||||
git init -b master
|
||||
git remote add "$remote" "git@$remote:$owner/$repo.git"
|
||||
git add .git*
|
||||
git commit -m "Инициализация / $folder"
|
||||
git commit -m "Инициализация / $dir"
|
||||
if [ "$remote" == "hub.mos.ru" ]; then
|
||||
echo "Второй пуш, потому что лингвист с первого раза не срабатывает."
|
||||
git push -u "$remote" master
|
||||
|
@ -41,10 +41,10 @@ git add \*.jpg
|
|||
git add \*.png
|
||||
git add \*.svg
|
||||
git commit -m "Картинки"
|
||||
find . -type f -not -path "*/.*" -not -path "./_site*" | sort -r | while read -r file; do
|
||||
find . -type f -not -path "*/.*" -not -path "./_site*" | LC_COLLATE=C sort -r | while read -r file; do
|
||||
echo "Обработка: $file"
|
||||
git add "$file"
|
||||
git commit -m "${file#*/}"
|
||||
done
|
||||
git push -u "$remote" master
|
||||
echo "Время создания локального репозитория: $(("$(date '+%s%3N')" - "$currentTimeMillis")) мс."
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
|
||||
|
|
|
@ -4,17 +4,17 @@ echo "Параллельное выполнение скриптов и созд
|
|||
# Скрипт в одну строчку — это выполнение одного из заранее подготовленных других скриптов для локальных и удалённых репозиториев.
|
||||
# Формируем и выполняем скрипты в несколько шагов с разными параметрами и по дороге сохраняем отчёты о выполнении.
|
||||
# Параллельное выполнение скриптов на последующем шаге начинается после завершения всех потоков на предыдущем шаге.
|
||||
cd .. # выходим из папки в корень репозитория
|
||||
currentTimeMillis=$(date '+%s%3N')
|
||||
cd ../.. # выходим из папки и из репозитория
|
||||
time_ms="$(date '+%s%3N')"
|
||||
# 1 Удаление репозиториев на сервере
|
||||
find .. -mindepth 1 -maxdepth 1 -type d -printf \
|
||||
find . -mindepth 1 -maxdepth 1 -type d -printf \
|
||||
'cd %h/%f && ./.repo_remote.sh "delete" >.repo_remote.log\0' | xargs -L1 -0 -P0 bash -c
|
||||
# 2 Создание репозиториев на сервере
|
||||
find .. -mindepth 1 -maxdepth 1 -type d -printf \
|
||||
find . -mindepth 1 -maxdepth 1 -type d -printf \
|
||||
'cd %h/%f && ./.repo_remote.sh "create" >>.repo_remote.log\0' | xargs -L1 -0 -P0 bash -c
|
||||
# 3 Создание локальных репозиториев и отправка данных на сервер
|
||||
# 4 Изменение настроек репозиториев на сервере, отключение ненужного
|
||||
find .. -mindepth 1 -maxdepth 1 -type d -printf \
|
||||
find . -mindepth 1 -maxdepth 1 -type d -printf \
|
||||
'cd %h/%f && ./.repo_local.sh >.repo_local.log\0
|
||||
cd %h/%f && ./.repo_remote.sh "options" >>.repo_remote.log\0' | xargs -L1 -0 -P0 bash -c
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$currentTimeMillis")) мс."
|
||||
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс."
|
||||
|
|
Loading…
Add table
Reference in a new issue