diff --git a/DIRECTORY_TREE.md b/DIRECTORY_TREE.md index 9b19f28..cdb3810 100644 --- a/DIRECTORY_TREE.md +++ b/DIRECTORY_TREE.md @@ -1,44 +1,47 @@ ## Дерево каталогов
-. -├─ avatars -│ ├─ README.md -│ ├─ color-tomato-theme.jpg -│ ├─ dispatcher.jpg -│ ├─ older-tomato-theme.jpg -│ ├─ pomodoro.jpg -│ └─ website.jpg -├─ bash_scripts -│ ├─ archive_backup.sh -│ ├─ archive_cleanup.sh -│ ├─ archive_packaging.sh -│ ├─ info_param.sh -│ ├─ info_references.sh -│ ├─ info_tree_license.sh -│ ├─ repo_compose.sh -│ ├─ repo_forgejo.tmpl.sh -│ ├─ repo_forgejo2.tmpl.sh -│ ├─ repo_gitlab.tmpl.sh -│ ├─ repo_local.tmpl.sh -│ ├─ repo_testing.smpl.sh -│ ├─ suite_orchestrate.sh -│ └─ suite_pages2.sh -├─ print_screen -│ ├─ LISTVIEW.md -│ ├─ archive_cleanup.png -│ ├─ archive_packaging.gif -│ ├─ info_references.png -│ ├─ info_tree_license.png -│ ├─ repo_compose.png -│ ├─ repo_testing.smpl.png -│ ├─ suite_orchestrate.gif -│ └─ suite_pages2.gif -├─ .gitignore -├─ CONTRIBUTING.md -├─ DIRECTORY_TREE.md -├─ LICENSE.md -├─ OPEN_LICENSE.txt -├─ README.en.md -└─ README.md +. +├─ avatars +│ ├─ LISTVIEW.md 551 +│ ├─ color-tomato-theme.jpg 4,9K +│ ├─ dispatcher.jpg 3,7K +│ ├─ older-tomato-theme.jpg 4,2K +│ ├─ pomodoro.jpg 3,3K +│ └─ website.jpg 3,9K +├─ bash_scripts +│ ├─ archive_backup.sh 1,4K +│ ├─ archive_cleanup.sh 916 +│ ├─ archive_packaging.sh 2,1K +│ ├─ info_param.sh 148 +│ ├─ info_references.sh 1,2K +│ ├─ info_tree_license.sh 3,3K +│ ├─ repo_compose.sh 5,5K +│ ├─ repo_forgejo.tmpl.sh 4,0K +│ ├─ repo_forgejo2.tmpl.sh 4,0K +│ ├─ repo_gitlab.tmpl.sh 4,2K +│ ├─ repo_local.tmpl.sh 1,7K +│ ├─ suite_orchestrate.sh 5,1K +│ ├─ suite_pages2.sh 4,3K +│ ├─ suite_profile2.sh 4,6K +│ └─ suite_testing.sh 2,1K +├─ print_screen +│ ├─ LISTVIEW.md 1,4K +│ ├─ archive_backup.png 2,9K +│ ├─ archive_cleanup.png 1,5K +│ ├─ archive_packaging.gif 22K +│ ├─ info_references.png 2,3K +│ ├─ info_tree_license.png 1,6K +│ ├─ repo_compose.png 1,8K +│ ├─ suite_orchestrate.gif 293K +│ ├─ suite_pages2.gif 109K +│ ├─ suite_profile2.gif 106K +│ └─ suite_testing.png 3,9K +├─ .gitignore 29 +├─ CONTRIBUTING.md 557 +├─ DIRECTORY_TREE.md 3,8K +├─ LICENSE.md 955 +├─ OPEN_LICENSE.txt 25K +├─ README.en.md 5,1K +└─ README.md 6,1Kdiff --git a/README.en.md b/README.en.md index 0979102..ea05fa7 100644 --- a/README.en.md +++ b/README.en.md @@ -1,10 +1,10 @@ # [Dispatcher](README.md) -Creating the archive, switching a domain, saving scripts in the directories of projects and publishing the repositories on to server. +Creating the archive, switching a domain, saving scripts in the directories of projects and publishing repositories on the server. | № | Bash script | Actions performed | (+) | |:-:|:--------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:-----------------------------------------:| -| 1 | [**archive_backup.sh**](bash_scripts/archive_backup.sh) | Creating a common archive for the directories of projects on the current date. | | +| 1 | [**archive_backup.sh**](bash_scripts/archive_backup.sh) | Creating a common archive for the directories of projects on the current date. | [png](print_screen/archive_backup.png) | | | [archive_cleanup.sh](bash_scripts/archive_cleanup.sh) | Deleting files and folders from the directories of projects before restoring the archive. | [png](print_screen/archive_cleanup.png) | | | [archive_packaging.sh](bash_scripts/archive_packaging.sh) | Building websites, packaging and copying archives for deployment. | [gif](print_screen/archive_packaging.gif) | | 2 | [**info_param.sh**](bash_scripts/info_param.sh) | Parameter for other scripts. Switching the domain of the remote repository. | | @@ -12,12 +12,13 @@ Creating the archive, switching a domain, saving scripts in the directories of p | | [info_tree_license.sh](bash_scripts/info_tree_license.sh) | Building a directory tree for each project and copying license files. | [png](print_screen/info_tree_license.png) | | 3 | [**repo_compose.sh**](bash_scripts/repo_compose.sh) | Creating scripts from templates with parameters and saving them in the directories of projects. | [png](print_screen/repo_compose.png) | | | [repo_forgejo.tmpl.sh](bash_scripts/repo_forgejo.tmpl.sh) | Template of a script without parameters to create a remote repository forgejo. | | -| | [repo_forgejo2.tmpl.sh](bash_scripts/repo_forgejo2.tmpl.sh) | Template of a script without parameters to deploy a website on the server codeberg. | | +| | [repo_forgejo2.tmpl.sh](bash_scripts/repo_forgejo2.tmpl.sh) | Template of a script without parameters to publish a website on the server codeberg. | | | | [repo_gitlab.tmpl.sh](bash_scripts/repo_gitlab.tmpl.sh) | Template of a script without parameters to create a remote repository gitlab. | | | | [repo_local.tmpl.sh](bash_scripts/repo_local.tmpl.sh) | Template of a script without parameters to create a local repository git. | | -| | [repo_testing.smpl.sh](bash_scripts/repo_testing.smpl.sh) | Sample of a script for testing the accessibility of pages in the web-interface on the server. | [png](print_screen/repo_testing.smpl.png) | -| 4 | [**suite_orchestrate.sh**](bash_scripts/suite_orchestrate.sh) | Parallel execution of scripts and publishing the repositories for the directories of projects. | [gif](print_screen/suite_orchestrate.gif) | -| | [suite_pages2.sh](bash_scripts/suite_pages2.sh) | Parallel execution of scripts and deploying the websites on the server codeberg. | [gif](print_screen/suite_pages2.gif) | +| 4 | [**suite_orchestrate.sh**](bash_scripts/suite_orchestrate.sh) | Execution of scripts. Publishing the source code from the directories of projects. | [gif](print_screen/suite_orchestrate.gif) | +| | [suite_pages2.sh](bash_scripts/suite_pages2.sh) | Execution of scripts. Publishing the finished websites on the server codeberg. | [gif](print_screen/suite_pages2.gif) | +| | [suite_profile2.sh](bash_scripts/suite_profile2.sh) | Execution of scripts. Publishing the tables of contents of websites on the server codeberg. | [gif](print_screen/suite_profile2.gif) | +| | [suite_testing.sh](bash_scripts/suite_testing.sh) | Testing the accessibility of pages in the web-interface on the server. | [png](print_screen/suite_testing.png) | ## Directories of projects diff --git a/README.md b/README.md index d7ce53c..f98966e 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,23 @@ Создание архива, переключение домена, сохранение скриптов в каталогах проектов и публикация репозиториев на сервере. -| № | Скрипт Bash | Выполняемые действия | (+) | -|:-:|:--------------------------------------------------------------|:-----------------------------------------------------------------------------------|:-----------------------------------------:| -| 1 | [**archive_backup.sh**](bash_scripts/archive_backup.sh) | Создание общего архива для каталогов проектов на текущую дату. | | -| | [archive_cleanup.sh](bash_scripts/archive_cleanup.sh) | Удаление файлов и папок из каталогов проектов перед восстановлением архива. | [png](print_screen/archive_cleanup.png) | -| | [archive_packaging.sh](bash_scripts/archive_packaging.sh) | Сборка вёб-сайтов, упаковка и копирование архивов для развёртывания. | [gif](print_screen/archive_packaging.gif) | -| 2 | [**info_param.sh**](bash_scripts/info_param.sh) | Параметр для других скриптов. Переключение домена удалённого репозитория. | | -| | [info_references.sh](bash_scripts/info_references.sh) | Обновление домена удалённого репозитория в перекрёстных ссылках в описаниях. | [png](print_screen/info_references.png) | -| | [info_tree_license.sh](bash_scripts/info_tree_license.sh) | Построение дерева каталогов для каждого проекта и копирование файлов лицензии. | [png](print_screen/info_tree_license.png) | -| 3 | [**repo_compose.sh**](bash_scripts/repo_compose.sh) | Создание скриптов из шаблонов с параметрами и сохранение их в каталогах проектов. | [png](print_screen/repo_compose.png) | -| | [repo_forgejo.tmpl.sh](bash_scripts/repo_forgejo.tmpl.sh) | Шаблон скрипта без параметров для создания удалённого репозитория forgejo. | | -| | [repo_forgejo2.tmpl.sh](bash_scripts/repo_forgejo2.tmpl.sh) | Шаблон скрипта без параметров для развёртывания вёб-сайта на сервере codeberg. | | -| | [repo_gitlab.tmpl.sh](bash_scripts/repo_gitlab.tmpl.sh) | Шаблон скрипта без параметров для создания удалённого репозитория gitlab. | | -| | [repo_local.tmpl.sh](bash_scripts/repo_local.tmpl.sh) | Шаблон скрипта без параметров для создания локального репозитория git. | | -| | [repo_testing.smpl.sh](bash_scripts/repo_testing.smpl.sh) | Образец скрипта для тестирования доступности страниц в вёб-интерфейсе на сервере. | [png](print_screen/repo_testing.smpl.png) | -| 4 | [**suite_orchestrate.sh**](bash_scripts/suite_orchestrate.sh) | Параллельное выполнение скриптов и публикация репозиториев для каталогов проектов. | [gif](print_screen/suite_orchestrate.gif) | -| | [suite_pages2.sh](bash_scripts/suite_pages2.sh) | Параллельное выполнение скриптов и развёртывание вёб-сайтов на сервере codeberg. | [gif](print_screen/suite_pages2.gif) | +| № | Скрипт Bash | Выполняемые действия | (+) | +|:-:|:--------------------------------------------------------------|:----------------------------------------------------------------------------------|:-----------------------------------------:| +| 1 | [**archive_backup.sh**](bash_scripts/archive_backup.sh) | Создание общего архива для каталогов проектов на текущую дату. | [png](print_screen/archive_backup.png) | +| | [archive_cleanup.sh](bash_scripts/archive_cleanup.sh) | Удаление файлов и папок из каталогов проектов перед восстановлением архива. | [png](print_screen/archive_cleanup.png) | +| | [archive_packaging.sh](bash_scripts/archive_packaging.sh) | Сборка вёб-сайтов, упаковка и копирование архивов для развёртывания. | [gif](print_screen/archive_packaging.gif) | +| 2 | [**info_param.sh**](bash_scripts/info_param.sh) | Параметр для других скриптов. Переключение домена удалённого репозитория. | | +| | [info_references.sh](bash_scripts/info_references.sh) | Обновление домена удалённого репозитория в перекрёстных ссылках в описаниях. | [png](print_screen/info_references.png) | +| | [info_tree_license.sh](bash_scripts/info_tree_license.sh) | Построение дерева каталогов для каждого проекта и копирование файлов лицензии. | [png](print_screen/info_tree_license.png) | +| 3 | [**repo_compose.sh**](bash_scripts/repo_compose.sh) | Создание скриптов из шаблонов с параметрами и сохранение их в каталогах проектов. | [png](print_screen/repo_compose.png) | +| | [repo_forgejo.tmpl.sh](bash_scripts/repo_forgejo.tmpl.sh) | Шаблон скрипта без параметров для создания удалённого репозитория forgejo. | | +| | [repo_forgejo2.tmpl.sh](bash_scripts/repo_forgejo2.tmpl.sh) | Шаблон скрипта без параметров для публикации вёб-сайта на сервере codeberg. | | +| | [repo_gitlab.tmpl.sh](bash_scripts/repo_gitlab.tmpl.sh) | Шаблон скрипта без параметров для создания удалённого репозитория gitlab. | | +| | [repo_local.tmpl.sh](bash_scripts/repo_local.tmpl.sh) | Шаблон скрипта без параметров для создания локального репозитория git. | | +| 4 | [**suite_orchestrate.sh**](bash_scripts/suite_orchestrate.sh) | Выполнение скриптов. Публикация исходного кода из каталогов проектов. | [gif](print_screen/suite_orchestrate.gif) | +| | [suite_pages2.sh](bash_scripts/suite_pages2.sh) | Выполнение скриптов. Публикация готовых вёб-сайтов на сервере codeberg. | [gif](print_screen/suite_pages2.gif) | +| | [suite_profile2.sh](bash_scripts/suite_profile2.sh) | Выполнение скриптов. Публикация оглавлений вёб-сайтов на сервере codeberg. | [gif](print_screen/suite_profile2.gif) | +| | [suite_testing.sh](bash_scripts/suite_testing.sh) | Тестирование доступности страниц в вёб-интерфейсе на сервере. | [png](print_screen/suite_testing.png) | ## Каталоги проектов diff --git a/avatars/README.md b/avatars/LISTVIEW.md similarity index 100% rename from avatars/README.md rename to avatars/LISTVIEW.md diff --git a/avatars/color-tomato-theme.jpg b/avatars/color-tomato-theme.jpg index 4777099..29385a1 100644 Binary files a/avatars/color-tomato-theme.jpg and b/avatars/color-tomato-theme.jpg differ diff --git a/avatars/dispatcher.jpg b/avatars/dispatcher.jpg index 84c8396..4f59edf 100644 Binary files a/avatars/dispatcher.jpg and b/avatars/dispatcher.jpg differ diff --git a/avatars/older-tomato-theme.jpg b/avatars/older-tomato-theme.jpg index bf1024d..4f53368 100644 Binary files a/avatars/older-tomato-theme.jpg and b/avatars/older-tomato-theme.jpg differ diff --git a/avatars/pomodoro.jpg b/avatars/pomodoro.jpg index 2301a85..3fcf50e 100644 Binary files a/avatars/pomodoro.jpg and b/avatars/pomodoro.jpg differ diff --git a/avatars/website.jpg b/avatars/website.jpg index 3d27162..9ddae6a 100644 Binary files a/avatars/website.jpg and b/avatars/website.jpg differ diff --git a/bash_scripts/archive_backup.sh b/bash_scripts/archive_backup.sh index 3e1b2bf..eb70507 100755 --- a/bash_scripts/archive_backup.sh +++ b/bash_scripts/archive_backup.sh @@ -1,9 +1,15 @@ #!/bin/bash echo "Создание общего архива для каталогов проектов на текущую дату." -cd ../.. # выход из папки и из репозитория filename="pomodoro-$(date '+%Y-%m-%d').zip" -# сводная строка исключений для всех проектов из файлов ".gitignore" -exclusions="$(find . -maxdepth 2 -type f -name '.gitignore' -exec \ - sed -E "s|^(.*)$|-xr!'\1'|" {} \; | sort | uniq | tr '\n' ' ')" -rm -f "$filename" -eval "7z a -tzip '$filename' . -xr!'.git' $exclusions" | grep -E '\S' +cd ../.. # выход из папки и из репозитория +time_ms="$(date '+%s%3N')" +rm -vf "$filename" # удаление старого файла +# поиск всех каталогов на одном уровне с текущим, кроме папки ".idea", сортировка и добавление +# в общий архив их содержимого, за исключением неотслеживаемых файлов по спискам ".gitignore" +find . -mindepth 1 -maxdepth 1 -type d -not -path "*.idea*" -printf '%P\n' | sort | xargs -I{} bash -c \ + "echo 'Обработка += {}' && 7z u -tzip $filename {} -xr!'.git' -xr@'{}/.gitignore' &>/dev/null" +# вывод общей информации о целостности полученного архива +7z t "$filename" |& grep -E '\S' | grep -E "\-\-|ERROR" -A20 +# замер продолжительности выполнения в миллисекундах, пересчёт в минуты, секунды и миллисекунды +tms="$(($(date '+%s%3N') - time_ms))" && min="$((tms / 1000 / 60))" && sec="$((tms / 1000 % 60))" +ms="$((tms % 1000))" && printf 'Общее время выполнения: %02d:%02d.%03d мс.\n' "$min" "$sec" "$ms" diff --git a/bash_scripts/archive_packaging.sh b/bash_scripts/archive_packaging.sh index 186a2f8..67d1b17 100755 --- a/bash_scripts/archive_packaging.sh +++ b/bash_scripts/archive_packaging.sh @@ -4,23 +4,23 @@ echo "Сборка вёб-сайтов, упаковка и копировани function packaging { dir="pomodoro${1}" && red="\e[91m" && green="\e[92m" && norm="\e[0m" # соответствующая строка для вывода сообщений по ходу выполнения функции - num="$((7 - ${1}))" && pre="\e[${num}A${dir}: " && aft="\e[K\e[${num}B\r" - printf "${pre}%s${aft}" "Обработка." - cd "./$dir" &>/dev/null || { printf "${pre}${red}%s${norm}${aft}" "Не найден каталог." && return; } - printf "${pre}%s${aft}" "Сборка." - ./build.sh &>/dev/null || { printf "${pre}${red}%s${norm}${aft}" "Ошибка сборки." && return; } - printf "${pre}%s${aft}" "Упаковка." - ./package.sh &>/dev/null || { printf "${pre}${red}%s${norm}${aft}" "Ошибка упаковки." && return; } - printf "${pre}%s${aft}" "Копирование." - cp "$dir".zip .. &>/dev/null || { printf "${pre}${red}%s${norm}${aft}" "Ошибка копирования." && return; } - printf "${pre}${green}%s${norm}${aft}" "Выполнено." + num="$((7 - ${1}))" && pre="\e[${num}A${dir} " && aft="\e[K\e[${num}B\r" + printf "${pre}%s %s${aft}" "[•••]" "Обработка." + cd "./$dir" &>/dev/null || { printf "${pre}${red}%s${norm} %s${aft}" "[•••]" "Не найден каталог." && return; } + printf "${pre}%s %s${aft}" "[#••]" "Сборка." + ./build.sh &>/dev/null || { printf "${pre}${red}%s${norm} %s${aft}" "[#••]" "Ошибка сборки." && return; } + printf "${pre}%s %s${aft}" "[##•]" "Упаковка." + ./package.sh &>/dev/null || { printf "${pre}${red}%s${norm} %s${aft}" "[##•]" "Ошибка упаковки." && return; } + printf "${pre}%s %s${aft}" "[###]" "Копирование." + cp "$dir".zip .. &>/dev/null || { printf "${pre}${red}%s${norm} %s${aft}" "[###]" "Ошибка копирования." && return; } + printf "${pre}${green}%s${norm} %s${aft}" "[###]" "Выполнено." } export -f packaging cd ../.. # выход из папки и из репозитория time_ms="$(date '+%s%3N')" # смещение курсора вниз на соответствующее количество строк printf 'pomodoro%s\n' {1..6} -# обход всех вёб-сайтов и параллельный запуск функции для каждого +# вывод номеров вёб-сайтов и параллельный запуск функции для каждого printf 'packaging "%s"\0' {1..6} | xargs -n1 -0 -P0 bash -c # замер продолжительности выполнения в миллисекундах, пересчёт в минуты, секунды и миллисекунды tms="$(($(date '+%s%3N') - time_ms))" && min="$((tms / 1000 / 60))" && sec="$((tms / 1000 % 60))" diff --git a/bash_scripts/info_references.sh b/bash_scripts/info_references.sh index 758df1c..4b56508 100755 --- a/bash_scripts/info_references.sh +++ b/bash_scripts/info_references.sh @@ -17,7 +17,7 @@ else fi cd ../.. # выход из папки и из репозитория time_ms="$(date '+%s%3N')" -# поиск файлов "README" и параллельная подстановка значений по шаблонам для каждого -find . -type f -name "README*.md" -printf '%p\0' | xargs -I{} -n1 -0 -P0 bash -c \ - "echo '$domain => {}' && sed -i $(printf " -e '%s'" "${expr[@]}") '{}'" +# поиск файлов "README" в корне каждого репозитория, замена строк по шаблонам и сортировка вывода +find . -maxdepth 2 -type f -name "README*.md" -printf '%p\0' | xargs -I{} -n1 -0 -P0 bash -c \ + "echo '$domain => {}' && sed -i $(printf " -e '%s'" "${expr[@]}") '{}'" | LC_COLLATE=C sort echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс." diff --git a/bash_scripts/info_tree_license.sh b/bash_scripts/info_tree_license.sh index c29831c..fa2f674 100755 --- a/bash_scripts/info_tree_license.sh +++ b/bash_scripts/info_tree_license.sh @@ -20,7 +20,10 @@ function directory_tree { # префикс текущего элемента, сворачивать синглтоны в одну строку [ "$4" == "one" ] && printf '%s' "/" || printf '\n%s' "$head" # текущий элемент дерева — относительная гиперссылка - printf '%s' "${path##*/}" + printf '%s' "${path#*/}" "${path##*/}" + # суффикс текущего элемента — размер файла меньшим шрифтом + [ -f "$path" ] && printf ' %s' \ + "$(stat -c %s "$path" | numfmt --to=iec --round=nearest)" # рекурсивные вызовы для подкаталогов if [ -d "$path" ]; then local i # счётчик @@ -46,7 +49,7 @@ function tree_license { fi # строка исключений для "ls" из списка неотслеживаемых файлов ".gitignore" exclusions="-I'.git' $(sed -E "s|^(.*)$|-I'\1'|" .gitignore | tr '\n' ' ')" - # помещаем дерево в контейнер, добавляем заголовок и выводим в файл + # поместить дерево в контейнер, добавить заголовок и вывести в файл printf '%s\n' "## Дерево каталогов" "" "
" \ "$(directory_tree . | grep '\S')" "" >DIRECTORY_TREE.md } diff --git a/bash_scripts/repo_compose.sh b/bash_scripts/repo_compose.sh index 78e3130..d7e6682 100755 --- a/bash_scripts/repo_compose.sh +++ b/bash_scripts/repo_compose.sh @@ -6,10 +6,8 @@ export basedir="$PWD" # текущая папка function compose { echo "Обработка: $1" cd "$1" || return - # добавление скриптов в список неотслеживаемых файлов, если ещё не добавлено - if [[ ! -f ".gitignore" || "$(grep -cF ".repo_*" ".gitignore")" == 0 ]]; then - echo ".repo_*" >>".gitignore" && echo "Обновлён файл: $1/.gitignore" - fi + # удаление скриптов предыдущей компоновки, если таковые имеются + find . -maxdepth 1 -type f -name ".repo_*" -exec rm -f {} \; # подготовка значений для параметров user="golovin" && owner="$user" && repo="$1" case "$1" in @@ -25,63 +23,74 @@ function compose { pomodoro) description="Описание и оглавление" ;; color*) description="Тема оформления / Цветной помидор" ;; older*) description="Тема оформления / Старый помидор" ;; - *) return ;; # шесть помидорных вёб-сайтов и три сопутствующих проекта + *) return ;; # шесть помидорных вёб-сайтов и четыре сопутствующих проекта esac - file="DIRECTORY_TREE.md" if [ "$domain" == "hub.mos.ru" ]; then - model="gitlab" && folder="blob" && wiki_home="-/wikis/home" - [ -f "WIKI.md" ] && wiki="$(uni2ascii -aU -qpsn "WIKI.md")" + model="gitlab" && [ -f "WIKI.md" ] && wiki="$(uni2ascii -aU -qpsn "WIKI.md")" else - model="forgejo" && folder="src/branch" && wiki_home="wiki" - [ -f "WIKI.md" ] && wiki="$(basenc "WIKI.md" --base64 -w0)" + model="forgejo" && [ -f "WIKI.md" ] && wiki="$(basenc --base64 -w0 "WIKI.md")" fi if [ "$domain" == "codeberg.org" ]; then [[ "$1" =~ [1-6] ]] && description2="Исходные тексты вёб-сайта — https://$domain/$owner/$repo" [ -f "WIKI.md" ] && wiki="$(sed 's|mircloud\.ru|codeberg.page|g' WIKI.md | basenc --base64 -w0)" description="${description//mircloud.ru/codeberg.page}" fi - # создание трёх скриптов в каталоге проекта с одинаковой шапкой для всех - echo "#!/bin/bash" | tee ".repo_remote.sh" ".repo_local.sh" >".repo_testing.sh" - chmod +x ".repo_remote.sh" ".repo_local.sh" ".repo_testing.sh" - # параметры для удалённого репозитория - param_remote+=("domain='$domain'") - param_remote+=("owner='$owner'") - param_remote+=("user='$user'") - param_remote+=("repo='$repo'") - param_remote+=("description='$description'") - param_remote+=("wiki='$wiki'") - param_remote+=("token='$(head -n+1 "$basedir/.token_$model")'") - # скрипт для создания удалённого репозитория - printf '%s\n' "${param_remote[@]}" >>".repo_remote.sh" - tail -n+2 "$basedir/repo_$model.tmpl.sh" >>".repo_remote.sh" - # параметры для локального репозитория - param_local+=("domain='$domain'") - param_local+=("owner='$owner'") - param_local+=("repo='$repo'") - param_local+=("dir='$1'") - # скрипт для создания локального репозитория - printf '%s\n' "${param_local[@]}" >>".repo_local.sh" - tail -n+2 "$basedir/repo_local.tmpl.sh" >>".repo_local.sh" - # параметры для тестирования вёб-интерфейса - param_testing+=("'https://$domain/$owner/$repo/$folder/master/$file' '$file'") - [ "$wiki" ] && param_testing+=("'https://$domain/$owner/$repo/$wiki_home' 'Home'") - # скрипт для тестирования вёб-интерфейса - printf 'pages+=("%s")\n' "${param_testing[@]}" >>".repo_testing.sh" - tail -n+21 "$basedir/repo_testing.smpl.sh" >>".repo_testing.sh" - # создание четвёртого скрипта в каталоге вёб-сайта - if [[ "$domain" == "codeberg.org" && "$1" =~ [1-6] ]]; then - # параметры для развёртывания вёб-сайта - param_pages+=("#!/bin/bash") - param_pages+=("domain='$domain'") - param_pages+=("owner='$owner$repo'") - param_pages+=("user='$user'") - param_pages+=("repo='pages'") - param_pages+=("description='$description2'") - param_pages+=("token='$(head -n+1 "$basedir/.token_forgejo")'") - # скрипт для развёртывания вёб-сайта - printf '%s\n' "${param_pages[@]}" >".repo_pages2.sh" - tail -n+2 "$basedir/repo_forgejo2.tmpl.sh" >>".repo_pages2.sh" - chmod +x ".repo_pages2.sh" + # параметры для публикации репозитория + repo_publish+=("#!/bin/bash") + repo_publish+=("domain='$domain'") + repo_publish+=("owner='$owner'") + repo_publish+=("user='$user'") + repo_publish+=("repo='$repo'") + repo_publish+=("dir='$1'") + repo_publish+=("description='$description'") + repo_publish+=("wiki='$wiki'") + repo_publish+=("token='$(head -n+1 "$basedir/.token_$model")'") + # шаблоны для публикации репозитория + tmpl_remote="$basedir/repo_$model.tmpl.sh" + tmpl_local="$basedir/repo_local.tmpl.sh" + # место вставки для локального шаблона + local="$(grep -nF '#LOCAL#' "$tmpl_remote" | sed 's|:.*$||')" + { # скрипт для публикации репозитория + printf '%s\n' "${repo_publish[@]}" + head -n+"$((local - 1))" "$tmpl_remote" | tail -n+2 + tail -n+2 "$tmpl_local" + tail -n+"$((local + 1))" "$tmpl_remote" + } >".repo_publish.sh" + chmod 555 ".repo_publish.sh" + # два скрипта для публикации вёб-сайтов + if [[ "$domain" == "codeberg.org" ]]; then + # шесть помидорных вёб-сайтов и один общий помидор + [[ "$1" =~ [1-6] ]] && group="$owner$repo" || group="pomodoro" + if [[ "$1" =~ [1-6] ]]; then + # параметры для развёртывания вёб-сайта + param_pages+=("#!/bin/bash") + param_pages+=("domain='$domain'") + param_pages+=("owner='$group'") + param_pages+=("folder='_site'") + param_pages+=("repo='pages'") + param_pages+=("avatar='website'") + param_pages+=("description='$description2'") + param_pages+=("token='$(head -n+1 "$basedir/.token_forgejo")'") + # скрипт для развёртывания вёб-сайта + printf '%s\n' "${param_pages[@]}" >".repo_pages2.sh" + tail -n+2 "$basedir/repo_forgejo2.tmpl.sh" >>".repo_pages2.sh" + chmod 555 ".repo_pages2.sh" + fi + if [[ "$1" == "pomodoro" || "$1" =~ [1-5] ]]; then + # параметры для оглавления вёб-сайта + param_profile+=("#!/bin/bash") + param_profile+=("domain='$domain'") + param_profile+=("owner='$group'") + param_profile+=("folder='_profile'") + param_profile+=("repo='.profile'") + param_profile+=("avatar='pomodoro'") + param_profile+=("description='Оглавление / Contents'") + param_profile+=("token='$(head -n+1 "$basedir/.token_forgejo")'") + # скрипт для оглавления вёб-сайта + printf '%s\n' "${param_profile[@]}" >".repo_profile2.sh" + tail -n+2 "$basedir/repo_forgejo2.tmpl.sh" >>".repo_profile2.sh" + chmod 555 ".repo_profile2.sh" + fi fi } export -f compose diff --git a/bash_scripts/repo_forgejo.tmpl.sh b/bash_scripts/repo_forgejo.tmpl.sh index 18d43f5..0e5d3e6 100644 --- a/bash_scripts/repo_forgejo.tmpl.sh +++ b/bash_scripts/repo_forgejo.tmpl.sh @@ -1,56 +1,76 @@ #!/bin/false -if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$user" ]]; then +if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$user" || -z "$dir" ]]; then echo "Не указаны обязательные параметры." && exit 1 fi -if [ -z "$1" ]; then - echo "Создание удалённого репозитория для текущего проекта." -fi time_ms="$(date '+%s%3N')" if [[ -z "$1" || "$1" == "delete" ]]; then echo "Удаление старого репозитория." - curl -i -X DELETE "https://$domain/api/v1/repos/$owner/$repo" \ + curl -f -X DELETE "https://$domain/api/v1/repos/$owner/$repo" \ -H "Authorization: token $token" \ - -H "Accept: application/json" + -H "Accept: application/json" &>/dev/null \ + || { echo "Не удалось удалить репозиторий на сервере."; } fi if [[ -z "$1" || "$1" == "create" ]]; then echo "Создание нового репозитория пользователя." - curl -i -X POST "https://$domain/api/v1/user/repos" \ + curl -f -X POST "https://$domain/api/v1/user/repos" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ - -H "Content-Type: application/json" -d "{ \"name\": \"$repo\", \"description\": \"$description\" }" + -H "Content-Type: application/json" -d "{ + \"name\": \"$repo\", \"description\": \"$description\" }" &>/dev/null \ + || { echo "Не удалось создать репозиторий на сервере."; } +fi +if [[ -z "$1" || "$1" == "transfer" ]]; then if [ "$user" != "$owner" ]; then echo "Перемещение репозитория в группу." - curl -i -X POST "https://$domain/api/v1/repos/$user/$repo/transfer" \ + curl -f -X POST "https://$domain/api/v1/repos/$user/$repo/transfer" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ - -H "Content-Type: application/json" -d "{ \"new_owner\": \"$owner\" }" + -H "Content-Type: application/json" -d "{ \"new_owner\": \"$owner\" }" &>/dev/null \ + || { echo "Не удалось переместить репозиторий в группу." && exit 1; } fi fi -if [[ -z "$1" || "$1" == "options" ]]; then - [ "$wiki" ] && has_wiki=true || has_wiki=false +[ -n "$wiki" ] && has_wiki=true || has_wiki=false +if [[ -z "$1" || "$1" == "patch" ]]; then echo "Изменение свойств репозитория / отключение ненужного." - curl -i -X PATCH "https://$domain/api/v1/repos/$owner/$repo" \ + curl -f -X PATCH "https://$domain/api/v1/repos/$owner/$repo" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ -H "Content-Type: application/json" -d "{ \"has_projects\": false, \"has_issues\": false, \"has_releases\": false, \"has_actions\": false, \"has_packages\": false, \"has_pull_requests\": false, - \"has_wiki\": $has_wiki }" - if [ "$wiki" ]; then - echo "Добавление страницы wiki в репозиторий." - curl -i -X POST "https://$domain/api/v1/repos/$owner/$repo/wiki/new" \ - -H "Authorization: token $token" \ - -H "Accept: application/json" \ - -H "Content-Type: application/json" -d "{ \"content_base64\": \"$wiki\", \"title\": \"Home\" }" - fi + \"has_wiki\": $has_wiki }" &>/dev/null \ + || { echo "Не удалось изменить свойства репозитория на сервере." && exit 1; } +fi +if [[ -z "$1" || "$1" == "wiki" ]] && [[ -n "$wiki" ]]; then + echo "Добавление страницы wiki в репозиторий." + curl -f -X POST "https://$domain/api/v1/repos/$owner/$repo/wiki/new" \ + -H "Authorization: token $token" \ + -H "Accept: application/json" \ + -H "Content-Type: application/json" -d "{ + \"content_base64\": \"$wiki\", \"title\": \"Home\" }" &>/dev/null \ + || { echo "Не удалось добавить страницу wiki для репозитория." && exit 1; } +fi +if [[ -z "$1" || "$1" == "avatar" ]]; then echo "Добавление аватарки для репозитория." [ "$user" != "$owner" ] && picture="website" || picture="$repo" avatar=$(basenc "../dispatcher/avatars/$picture.jpg" --base64 -w0) - curl -i -X POST "https://$domain/api/v1/repos/$owner/$repo/avatar" \ + curl -f -X POST "https://$domain/api/v1/repos/$owner/$repo/avatar" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ - -H "Content-Type: application/json" -d "{ \"image\": \"$avatar\" }" + -H "Content-Type: application/json" -d "{ \"image\": \"$avatar\" }" &>/dev/null \ + || { echo "Не удалось добавить аватарку для репозитория." && exit 1; } +fi +#LOCAL# +if [ -z "$1" ]; then + echo "Ожидание 3 секунды." && sleep 3 +fi +if [[ -z "$1" || "$1" == "testing" ]]; then + echo "Получение списка ветвей для удалённого репозитория." + curl -f -X GET "https://$domain/api/v1/repos/$owner/$repo/branches" \ + -H "Authorization: token $token" \ + -H "Accept: application/json" 2>/dev/null | grep -v '^null$' &>/dev/null \ + || { echo "Не удалось получить список ветвей для репозитория." && exit 1; } fi if [ -z "$1" ]; then echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс." diff --git a/bash_scripts/repo_forgejo2.tmpl.sh b/bash_scripts/repo_forgejo2.tmpl.sh index be75494..2760142 100644 --- a/bash_scripts/repo_forgejo2.tmpl.sh +++ b/bash_scripts/repo_forgejo2.tmpl.sh @@ -1,59 +1,79 @@ #!/bin/false -if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$user" ]]; then +if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$folder" ]]; then echo "Не указаны обязательные параметры." && exit 1 elif [ "$domain" != "codeberg.org" ]; then echo "Некорректно указан сервер." && exit 1 fi -cd _site || exit 1 -if [ -z "$1" ]; then - echo "Создание удалённого репозитория, локального репозитория, отправка данных и проверка их получения." +if [[ -z "$1" || "$1" == "prepare" ]] && [[ "$folder" == ".profile" ]]; then + echo "Создание каталога и создание файлов в каталоге." + rm -rf "$folder" && mkdir "$folder" + if [[ "$owner" == "pomodoro" ]]; then + expr+=" -e 's|details open|details|'" + fi + expr+=" -e 's|mircloud\.ru|codeberg.page|g'" + eval "sed $expr 'WIKI.md'" >"$folder/README.md" + echo "*.md linguist-language=INFO" >"$folder/.gitattributes" fi +cd "$folder" || exit 1 time_ms="$(date '+%s%3N')" -if [[ -z "$1" || "$1" == "remote" ]]; then +if [[ -z "$1" || "$1" == "delete" ]]; then echo "Удаление старого репозитория на сервере." - curl -i -X DELETE "https://$domain/api/v1/repos/$owner/$repo" \ + curl -f -X DELETE "https://$domain/api/v1/repos/$owner/$repo" \ -H "Authorization: token $token" \ - -H "Accept: application/json" + -H "Accept: application/json" &>/dev/null \ + || { echo "Не удалось удалить репозиторий на сервере."; } +fi +if [[ -z "$1" || "$1" == "create" ]]; then echo "Создание нового репозитория в группе на сервере." - curl -i -X POST "https://$domain/api/v1/orgs/$owner/repos" \ + curl -f -X POST "https://$domain/api/v1/orgs/$owner/repos" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ -H "Content-Type: application/json" -d "{ - \"name\": \"$repo\", \"description\": \"$description\" }" + \"name\": \"$repo\", \"description\": \"$description\" }" &>/dev/null \ + || { echo "Не удалось создать репозиторий на сервере." && exit 1; } +fi +if [[ -z "$1" || "$1" == "patch" ]]; then echo "Изменение свойств репозитория / отключение ненужного." - curl -i -X PATCH "https://$domain/api/v1/repos/$owner/$repo" \ + curl -f -X PATCH "https://$domain/api/v1/repos/$owner/$repo" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ -H "Content-Type: application/json" -d "{ \"has_projects\": false, \"has_issues\": false, \"has_releases\": false, \"has_actions\": false, \"has_packages\": false, \"has_pull_requests\": false, - \"has_wiki\": false }" + \"has_wiki\": false }" &>/dev/null \ + || { echo "Не удалось изменить свойства репозитория на сервере." && exit 1; } +fi +if [[ -z "$1" || "$1" == "avatar" ]]; then echo "Добавление аватарки для репозитория." - avatar=$(basenc "../../dispatcher/avatars/website.jpg" --base64 -w0) - curl -i -X POST "https://$domain/api/v1/repos/$owner/$repo/avatar" \ + avatar=$(basenc "../../dispatcher/avatars/$avatar.jpg" --base64 -w0) + curl -f -X POST "https://$domain/api/v1/repos/$owner/$repo/avatar" \ -H "Authorization: token $token" \ -H "Accept: application/json" \ - -H "Content-Type: application/json" -d "{ \"image\": \"$avatar\" }" + -H "Content-Type: application/json" -d "{ \"image\": \"$avatar\" }" &>/dev/null \ + || { echo "Не удалось добавить аватарку для репозитория." && exit 1; } fi if [[ -z "$1" || "$1" == "local" ]]; then - echo "Пересоздание локального репозитория и отправка данных на сервер." + echo "Создание локального репозитория." rm -rf ".git" # удаление старого репозитория git init -b "master" - git remote add "$domain" "git@$domain:$owner/$repo.git" git add --all - git commit -m "$(printf '%(%F %T)T' "$(stat . -c'%W')")" + git commit -m "$(date -I'seconds' -d"@$(stat . -c'%W')")" +fi +if [[ -z "$1" || "$1" == "push" ]]; then + echo "Подключение к удалённому репозиторию и передача данных." + git remote add "$domain" "git@$domain:$owner/$repo.git" git push -u "$domain" "master" fi if [ -z "$1" ]; then echo "Ожидание 3 секунды." && sleep 3 fi if [[ -z "$1" || "$1" == "testing" ]]; then - echo "Получение списка коммитов для удалённого репозитория." - param="stat=false&verification=false&files=false" - curl -i -X GET "https://$domain/api/v1/repos/$owner/$repo/commits?$param" \ + echo "Получение списка ветвей для удалённого репозитория." + curl -f -X GET "https://$domain/api/v1/repos/$owner/$repo/branches" \ -H "Authorization: token $token" \ - -H "Accept: application/json" + -H "Accept: application/json" 2>/dev/null | grep -v '^null$' &>/dev/null \ + || { echo "Не удалось получить список ветвей для репозитория." && exit 1; } fi if [ -z "$1" ]; then echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс." diff --git a/bash_scripts/repo_gitlab.tmpl.sh b/bash_scripts/repo_gitlab.tmpl.sh index fb69cac..a1e0a41 100644 --- a/bash_scripts/repo_gitlab.tmpl.sh +++ b/bash_scripts/repo_gitlab.tmpl.sh @@ -1,67 +1,70 @@ #!/bin/false -if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$user" ]]; then +if [[ -z "$domain" || -z "$token" || -z "$owner" || -z "$repo" || -z "$description" || -z "$user" || -z "$dir" ]]; then echo "Не указаны обязательные параметры." && exit 1 fi -if [ -z "$1" ]; then - echo "Создание удалённого репозитория для текущего проекта." -fi time_ms="$(date '+%s%3N')" if [[ -z "$1" || "$1" == "delete" ]]; then echo "Удаление старого репозитория." - curl -i -X DELETE "https://$domain/api/v4/projects/$owner%2F$repo" \ + curl -f -X DELETE "https://$domain/api/v4/projects/$owner%2F$repo" \ -H "PRIVATE-TOKEN: $token" \ - -H "Content-Type: application/json" -d "{ \"permanently_remove\": \"true\", \"full_path\": \"$owner/$repo\" }" - echo + -H "Content-Type: application/json" -d "{ + \"permanently_remove\": \"true\", \"full_path\": \"$owner/$repo\" }" &>/dev/null \ + || { echo "Не удалось удалить репозиторий на сервере."; } fi if [[ -z "$1" || "$1" == "create" ]]; then echo "Создание нового репозитория пользователя." - curl -i -X POST "https://$domain/api/v4/projects" \ - -H "PRIVATE-TOKEN: $token" \ - -H "Content-Type: application/json" -d "{ \"name\": \"$repo\", \"description\": \"$description\" }" - echo - if [ "$user" != "$owner" ]; then - echo "Перемещение репозитория в группу." - curl -i -X PUT "https://$domain/api/v4/projects/$user%2F$repo/transfer?namespace=$owner" \ - -H "PRIVATE-TOKEN: $token" - echo - fi -fi -if [[ -z "$1" || "$1" == "options" ]]; then - [ "$wiki" ] && has_wiki="enabled" || has_wiki="disabled" - echo "Изменение свойств репозитория / отключение ненужного." - curl -i -X PUT "https://$domain/api/v4/projects/$owner%2F$repo" \ + curl -f -X POST "https://$domain/api/v4/projects" \ -H "PRIVATE-TOKEN: $token" \ -H "Content-Type: application/json" -d "{ - \"emails_disabled\": \"true\", \"issues_access_level\": \"disabled\", - \"merge_requests_access_level\": \"disabled\", \"operations_access_level\": \"disabled\", - \"builds_access_level\": \"disabled\", \"request_access_enabled\": \"false\", - \"keep_latest_artifact\": \"false\", \"ci_forward_deployment_enabled\": \"false\", - \"ci_separated_caches\": \"false\", \"ci_allow_fork_pipelines_to_run_in_parent_project\": \"false\", - \"jobs_enabled\": \"false\", \"public_builds\": \"false\", \"packages_enabled\": \"false\", - \"merge_requests_enabled\": \"false\", \"issues_enabled\": \"false\", \"lfs_enabled\": \"false\", - \"snippets_enabled\": \"false\", \"container_registry_enabled\": \"false\", - \"wiki_access_level\": \"$has_wiki\", \"container_registry_access_level\": \"disabled\", - \"security_and_compliance_access_level\": \"disabled\", \"pages_access_level\": \"disabled\", - \"analytics_access_level\": \"disabled\", \"forking_access_level\": \"disabled\", - \"releases_access_level\": \"disabled\", \"requirements_access_level\": \"disabled\", - \"environments_access_level\": \"disabled\", \"feature_flags_access_level\": \"private\", - \"infrastructure_access_level\": \"private\", \"monitor_access_level\": \"disabled\", - \"snippets_access_level\": \"disabled\", \"auto_devops_enabled\": \"false\", - \"shared_runners_enabled\": \"false\", \"group_runners_enabled\": \"false\" }" - echo - if [ "$wiki" ]; then - echo "Добавление страницы wiki в репозиторий." - curl -i -X POST "https://$domain/api/v4/projects/$owner%2F$repo/wikis" \ - -H "PRIVATE-TOKEN: $token" \ - -H "Content-Type: application/json" -d "{ \"content\": \"$wiki\", \"title\": \"Home\" }" - echo + \"name\": \"$repo\", \"description\": \"$description\" }" &>/dev/null \ + || { echo "Не удалось создать репозиторий на сервере."; } +fi +if [[ -z "$1" || "$1" == "transfer" ]]; then + if [ "$user" != "$owner" ]; then + echo "Перемещение репозитория в группу." + curl -f -X PUT "https://$domain/api/v4/projects/$user%2F$repo/transfer?namespace=$owner" \ + -H "PRIVATE-TOKEN: $token" &>/dev/null \ + || { echo "Не удалось переместить репозиторий в группу." && exit 1; } fi +fi +[ -n "$wiki" ] && has_wiki="enabled" || has_wiki="disabled" +if [[ -z "$1" || "$1" == "patch" ]]; then + echo "Изменение свойств репозитория / отключение ненужного." + curl -f -X PUT "https://$domain/api/v4/projects/$owner%2F$repo" \ + -H "PRIVATE-TOKEN: $token" \ + -H "Content-Type: application/json" -d "{ + \"request_access_enabled\": false, \"issues_enabled\": false, \"lfs_enabled\": false, \"packages_enabled\": false, + \"builds_access_level\": \"disabled\", \"forking_access_level\": \"disabled\", \"snippets_access_level\": \"disabled\", + \"analytics_access_level\": \"disabled\", \"releases_access_level\": \"disabled\", \"show_default_award_emojis\": false, + \"merge_requests_access_level\": \"disabled\", \"wiki_access_level\": \"$has_wiki\", \"container_registry_enabled\": false, + \"security_and_compliance_access_level\": \"disabled\", \"warn_about_potentially_unwanted_characters\": false }" &>/dev/null \ + || { echo "Не удалось изменить свойства репозитория на сервере." && exit 1; } +fi +if [[ -z "$1" || "$1" == "wiki" ]] && [[ -n "$wiki" ]]; then + echo "Добавление страницы wiki в репозиторий." + curl -f -X POST "https://$domain/api/v4/projects/$owner%2F$repo/wikis" \ + -H "PRIVATE-TOKEN: $token" \ + -H "Content-Type: application/json" -d "{ + \"content\": \"$wiki\", \"title\": \"Home\" }" &>/dev/null \ + || { echo "Не удалось добавить страницу wiki для репозитория." && exit 1; } +fi +if [[ -z "$1" || "$1" == "avatar" ]]; then echo "Добавление аватарки для репозитория." [ "$user" != "$owner" ] && picture="website" || picture="$repo" - curl -i -X PUT "https://$domain/api/v4/projects/$owner%2F$repo" \ + curl -f -X PUT "https://$domain/api/v4/projects/$owner%2F$repo" \ -H "PRIVATE-TOKEN: $token" \ - -F "avatar=@../dispatcher/avatars/$picture.jpg" - echo + -F "avatar=@../dispatcher/avatars/$picture.jpg" &>/dev/null \ + || { echo "Не удалось добавить аватарку для репозитория." && exit 1; } +fi +#LOCAL# +if [ -z "$1" ]; then + echo "Ожидание 3 секунды." && sleep 3 +fi +if [[ -z "$1" || "$1" == "testing" ]]; then + echo "Получение списка ветвей для удалённого репозитория." + curl -f -X GET "https://$domain/api/v4/projects/$owner%2F$repo/repository/branches" \ + -H "PRIVATE-TOKEN: $token" 2>/dev/null | grep -v '^\[\]$' &>/dev/null \ + || { echo "Не удалось получить список ветвей для репозитория." && exit 1; } fi if [ -z "$1" ]; then echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс." diff --git a/bash_scripts/repo_local.tmpl.sh b/bash_scripts/repo_local.tmpl.sh index f81b093..be3aa80 100644 --- a/bash_scripts/repo_local.tmpl.sh +++ b/bash_scripts/repo_local.tmpl.sh @@ -1,38 +1,31 @@ #!/bin/false -if [[ -z "$domain" || -z "$owner" || -z "$repo" || -z "$dir" ]]; then - echo "Не указаны обязательные параметры." && exit 1 +if [[ -z "$1" || "$1" == "local" ]]; then + echo "Создание локального репозитория." + rm -rf .git # удаление старого репозитория + git init -b master + git add .git* + git commit -m "Инициализация / $dir" + find . -type f | grep -E 'CONTRIBUTING|LICENSE' | xargs git add + git commit -m "Открытая лицензия РФ" + find . -type f -name '*.md' | grep -E 'TREE|WIKI|README|VIEW' | xargs git add + git commit -m "Описание проекта" + find . -type f | grep -E '(yml|Gemfile.*|gemspec|robots.txt)$' | xargs git add + git commit -m "Настройки" + git add \*.sh + git commit -m "Скрипты bash" + find . -type f | grep -E '(min.css|min.js|woff)$' | xargs git add + git commit -m "Сторонние материалы" + find . -type f | grep -E '(bmp|gif|ico|jpg|png|svg)$' | xargs git add + git commit -m "Картинки" + git add --all + # преобразование шаблонов "glob" в расширенные выражения "regexp" + patterns="$(sed 's|\.|\\.|;s|*|.*|' .gitignore | tr '\n' '|')\.git" + # выбор всех файлов в каталоге, кроме списка ".gitignore", сортировка и внесение в репозиторий + find . -type f -printf '%P\n' | grep -vE "(^|.+/)($patterns)(/.+|$)" | LC_COLLATE=C sort -r \ + | xargs -I{} -d'\n' bash -c 'echo "Обработка: {}" && git commit "{}" -m "{}" &>/dev/null' fi -echo "Создание локального репозитория, подключение к удалённому и передача данных." -time_ms="$(date '+%s%3N')" -# строка исключений для "find" из списка неотслеживаемых файлов ".gitignore" -exclusions="-not -path '*/.git/*' $(sed -E "s|^(.*)$|-not -path '*/\1*'|" .gitignore | tr '\n' ' ')" -# перевести размеры файла в человеко-читаемую строку, отбросить нули из дробной части и добавить пробел -function BKM { numfmt --to=iec --format="%.2f" --suffix="B" "$1" | sed -r 's|,{,1}0{,2}([BKM])| \1|'; } -rm -rf .git -git init -b master -git remote add "$domain" "git@$domain:$owner/$repo.git" -git add .git* -git commit -m "Инициализация / $dir" -if [ "$domain" == "hub.mos.ru" ]; then - echo "Второй пуш, потому что лингвист с первого раза не срабатывает." +if [[ -z "$1" || "$1" == "push" ]]; then + echo "Подключение к удалённому репозиторию и передача данных." + git remote add "$domain" "git@$domain:$owner/$repo.git" git push -u "$domain" master fi -find . -type f | grep -E 'CONTRIBUTING|LICENSE' | xargs git add -git commit -m "Открытая лицензия РФ" -find . -type f -name '*.md' | grep -E 'TREE|WIKI|README|VIEW' | xargs git add -git commit -m "Описание проекта" -find . -type f | grep -E '(yml|Gemfile.*|gemspec|robots.txt)$' | xargs git add -git commit -m "Настройки" -git add \*.sh -git commit -m "Скрипты bash" -find . -type f | grep -E '(min.css|min.js|woff)$' | xargs git add -git commit -m "Сторонние материалы" -find . -type f | grep -E '(bmp|gif|ico|jpg|png|svg)$' | xargs git add -git commit -m "Картинки" -while read -r file size; do - echo "Обработка: $file" - git add "$file" - git commit -m "${file#*/} / $(BKM "$size")" -done < <(eval "find . -type f $exclusions -printf '%p %s\n'" | LC_COLLATE=C sort -r) -git push -u "$domain" master -echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс." diff --git a/bash_scripts/repo_testing.smpl.sh b/bash_scripts/repo_testing.smpl.sh deleted file mode 100755 index 6446f6a..0000000 --- a/bash_scripts/repo_testing.smpl.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -echo "Образец скрипта для тестирования доступности страниц в вёб-интерфейсе на сервере." -domain="git.org.ru" && source info_param.sh -# две страницы для тестирования -file="DIRECTORY_TREE.md" -if [ "$domain" == "hub.mos.ru" ]; then - folder="blob" && wiki_home="-/wikis/home" -else - folder="src/branch" && wiki_home="wiki" -fi -# подготовка массива строк — адрес страницы и название файла через пробел -for repo in {1..6}; do - #pages+=("'https://$domain/golovin/$repo/$folder/master/$file' '$file'") - pages+=("'https://$domain/pomodoro/$repo/$folder/master/$file' '$file'") - pages+=("'https://$domain/pomodoro/$repo/$wiki_home' 'Home'") -done -for repo in {pomodoro,older-tomato-theme,color-tomato-theme}; do - pages+=("'https://$domain/golovin/$repo/$folder/master/$file' '$file'") - pages+=("'https://$domain/golovin/$repo/$wiki_home' 'Home'") -done -# тестирование доступности страниц -function testing { - # название файла должно находиться в заголовке страницы, иначе сервер должен вернуть ошибку - case "$(curl "$1" 2>/dev/null | grep -oP '(?<=