From fa7f621960ba6703b5a3bc9606972e4ceafb6dd6 Mon Sep 17 00:00:00 2001 From: golovin Date: Sat, 30 Nov 2024 20:51:14 +0300 Subject: [PATCH] 2024-11-30 --- bash_scripts/archive_cleanup.sh | 2 +- bash_scripts/repo_local.tmpl.sh | 8 ++++++-- bash_scripts/repo_orchestrate.sh | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bash_scripts/archive_cleanup.sh b/bash_scripts/archive_cleanup.sh index 2b2b107..f5bb6db 100755 --- a/bash_scripts/archive_cleanup.sh +++ b/bash_scripts/archive_cleanup.sh @@ -7,6 +7,6 @@ time_ms="$(date '+%s%3N')" find . -mindepth 1 -maxdepth 1 -type d -not -name ".idea" | while read -r dir; do echo "Обработка: $dir" # внутри репозитория — удаление всех вложенных файлов и папок, кроме папки ".git" - find "$dir" -mindepth 1 -maxdepth 1 -type f,d -not -name ".git" -print0 | xargs -0 rm -r + find "$dir" -mindepth 1 -maxdepth 1 -type f,d -not -name ".git" -exec rm -r {} \; done echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс." diff --git a/bash_scripts/repo_local.tmpl.sh b/bash_scripts/repo_local.tmpl.sh index ef5d5de..5f52033 100644 --- a/bash_scripts/repo_local.tmpl.sh +++ b/bash_scripts/repo_local.tmpl.sh @@ -4,6 +4,10 @@ fi echo "Создание локального репозитория, подключение к удалённому и передача данных." seconds=3 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" @@ -44,7 +48,7 @@ git commit -m "Картинки" while read -r file size; do echo "Обработка: $file" git add "$file" - git commit -m "${file#*/} / $(numfmt --to=iec --format="%.2f" --suffix="B" "$size" | sed -E 's|,{,1}0{,2}([BKM])| \1|')" -done < <(find . -type f -not -path "*/.*" -not -path "./_site*" -printf '%h/%f %s\n' | LC_COLLATE=C sort -r) + git commit -m "${file#*/} / $(BKM "$size")" +done < <(eval "find . -type f $exclusions -printf '%h/%f %s\n'" | LC_COLLATE=C sort -r) git push -u "$domain" master echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс." diff --git a/bash_scripts/repo_orchestrate.sh b/bash_scripts/repo_orchestrate.sh index 3f66ae5..eb3ead1 100755 --- a/bash_scripts/repo_orchestrate.sh +++ b/bash_scripts/repo_orchestrate.sh @@ -12,8 +12,11 @@ find . -mindepth 1 -maxdepth 1 -type d -printf \ # 2 Создание репозиториев на сервере 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 Изменение настроек репозиториев на сервере, отключение ненужного +# 3 Проверка корректности пересоздания репозиториев на сервере — выход в случае ошибки +find . -mindepth 2 -maxdepth 2 -type f -name ".repo_remote.log" -exec grep -cE '^HTTP\/[1,2].{,2}? [4,5]' {} \; | + tr -d '0\n' | xargs -r bash -c 'exit 1' || { echo "Ошибка 400-500. Невозможно подключение к серверу." && exit 1; } +# 4 Создание локальных репозиториев и отправка данных на сервер +# 5 Изменение настроек репозиториев на сервере, отключение ненужного 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