1
0
Fork 0
pomodoro/bash_scripts/repo_compose.sh
2023-12-30 23:37:18 +03:00

83 lines
3.3 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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"
fi
# параметры для шаблонов
owner="golovin"
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
description+=" — https://$owner$repo.mircloud.ru"
else
description="Описание и оглавление"
fi
elif [[ "$dir" =~ "color-tomato" ]]; then
description="Тема оформления / Цветной помидор"
elif [[ "$dir" =~ "older-tomato" ]]; then
description="Тема оформления / Старый помидор"
fi
# скрипт для создания удалённого репозитория
{
echo "#!/bin/bash"
echo "remote=\"$remote\""
echo "user=\"golovin\""
echo "owner=\"$owner\""
echo "repo=\"$repo\""
echo "description=\"$description\""
echo "type=\"$type\""
echo "wiki=\"$wiki\""
if [ "$remote" == "hub.mos.ru" ]; then
echo "token=\"$(cat "$basedir/.token_gitlab")\""
cat "$basedir/repo_gitlab.tmpl.sh"
else
echo "token=\"$(cat "$basedir/.token_gitea")\""
cat "$basedir/repo_gitea.tmpl.sh"
fi
} >"$dir"/.repo_remote.sh && chmod +x "$dir"/.repo_remote.sh
# скрипт для создания локального репозитория
{
echo "#!/bin/bash"
echo "remote=\"$remote\""
echo "owner=\"$owner\""
echo "repo=\"$repo\""
echo "folder=\"${dir##*/}\""
cat "$basedir/repo_local.tmpl.sh"
} >"$dir"/.repo_local.sh && chmod +x "$dir"/.repo_local.sh
done