188 lines
4.4 KiB
Bash
Executable File
188 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
print-help()
|
|
{
|
|
echo "Usage: myx-dev-project COMMAND [ARGS]"
|
|
echo "COMMAND:"
|
|
echo " -i Initialization"
|
|
echo " -u Update"
|
|
echo " -h Help"
|
|
echo "ARGS:"
|
|
echo " -s server (default: gitlab.2)"
|
|
echo " -d directory (default: .)"
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
key="$1"
|
|
|
|
case $key in
|
|
-h|--help)
|
|
print-help
|
|
exit 0
|
|
;;
|
|
-i|--init)
|
|
INIT="1"
|
|
UPDATE="1"
|
|
ACTION="1"
|
|
shift # past argument
|
|
;;
|
|
-u|--update)
|
|
UPDATE="1"
|
|
ACTION="1"
|
|
shift # past argument
|
|
;;
|
|
-s|--server)
|
|
SERVER="$2"
|
|
shift # past argument
|
|
shift # past value
|
|
;;
|
|
-d|--dir|--directory)
|
|
DIRECTORY="$2"
|
|
shift # past argument
|
|
shift # past value
|
|
;;
|
|
*) # unknown option
|
|
DIRECTORY="$1"
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "${ACTION}" ]]; then
|
|
echo "Command is not defined."
|
|
print-help
|
|
exit 1
|
|
fi
|
|
|
|
[[ -z "${SERVER}" ]] && SERVER=gitlab.2
|
|
|
|
TYPE=gitea
|
|
[[ "${SERVER}" == *"gitlab"* ]] && TYPE=gitlab
|
|
|
|
if [[ "$TYPE" == "gitea" ]]; then
|
|
BASE_URL="https://${SERVER}"
|
|
BRANCH_API="raw/branch"
|
|
GITHOOKS_ARCHIVE="archive/master.tar.gz"
|
|
fi
|
|
|
|
if [[ "$TYPE" == "gitlab" ]]; then
|
|
BASE_URL="http://${SERVER}"
|
|
BRANCH_API="-/raw"
|
|
GITHOOKS_ARCHIVE="-/archive/master/githooks-master.tar.gz"
|
|
fi
|
|
|
|
if [[ "x$INIT" == "x1" ]] ; then
|
|
[[ -z "$DIRECTORY" ]] && DIRECTORY="$(pwd)"
|
|
if [[ -d "${DIRECTORY}/.git" ]]; then
|
|
echo "Directory already has repository. Exiting"
|
|
exit 1
|
|
fi
|
|
|
|
if ! mkdir -p "$DIRECTORY"; then
|
|
echo "Can't create directory for git repository"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if ! cd "$DIRECTORY" >/dev/null; then
|
|
echo "Can't change directory to $DIRECTORY"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "x$INIT" == "x1" ]] ; then
|
|
if ! git init; then
|
|
echo "Can't create git repository in directory $DIRECTORY"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
mkdir -p files/{etc,log,share,var}
|
|
touch files/{etc,log,share,var}/.gitkeep
|
|
|
|
TF=$(mktemp -u)
|
|
if ! wget -O "$TF" "${BASE_URL}/f1x1t/cmake-format/${BRANCH_API}/master/.cmake-format.py" 2>/dev/null; then
|
|
echo "Can't download .clang-format.py"
|
|
exit 1
|
|
else
|
|
mv -f "$TF" .clang-format.py
|
|
fi
|
|
|
|
if ! wget -O "$TF" "${BASE_URL}/f1x1t/cmlib-gitignore/${BRANCH_API}/master/.gitignore" 2>/dev/null; then
|
|
echo "Can't download .gitignore"
|
|
exit 1
|
|
else
|
|
mv -f "$TF" .gitignore
|
|
fi
|
|
|
|
if ! wget -O "$TF" "${BASE_URL}/f1x1t/gitlab-ci/${BRANCH_API}/master/.gitlab-ci.yml" 2>/dev/null; then
|
|
echo "Can't download .gitlab-ci.yml"
|
|
exit 1
|
|
else
|
|
mv -f "$TF" .gitlab-ci.yml
|
|
fi
|
|
|
|
if ! wget -O "$TF" "${BASE_URL}/f1x1t/uncrustify-config/${BRANCH_API}/master/default.cfg" 2>/dev/null; then
|
|
echo "Can't download .uncrustify.cfg"
|
|
exit 1
|
|
else
|
|
mv -f "$TF" .uncrustify.cfg
|
|
fi
|
|
|
|
if ! wget -O "$TF" "${BASE_URL}/f1x1t/clang-tidy-config/${BRANCH_API}/master/.clang-tidy" 2>/dev/null; then
|
|
echo "Can't download .clang-tidy"
|
|
exit 1
|
|
else
|
|
mv -f "$TF" .clang-tidy
|
|
fi
|
|
|
|
if ! wget -O - "${BASE_URL}/f1x1t/githooks/${GITHOOKS_ARCHIVE}" | tar zx --strip-components=1 -C .git/hooks; then
|
|
echo "Can't download ${GITHOOKS_ARCHIVE}"
|
|
exit 1
|
|
fi
|
|
|
|
sed -i '/.*_CMD.*/d' .gitlab-ci.yml
|
|
sed -i '/.*variables:.*/d' .gitlab-ci.yml
|
|
sed -i 's/^UNCRUST_CONFIG.*/UNCRUST_CONFIG=$REPO\/.uncrustify.cfg/' .git/hooks/pre-commit-uncrustify.cfg
|
|
|
|
if [[ "x$INIT" != "x1" ]] ; then
|
|
exit 0
|
|
fi
|
|
|
|
tee -a CMakeLists.txt >/dev/null <<CML
|
|
# Минимальная версия CMake
|
|
cmake_minimum_required(VERSION 3.3)
|
|
|
|
# Предпочтительно следовать стандартам принятым в указанном диапазоне версий
|
|
cmake_policy(VERSION 3.0.2..3.7)
|
|
|
|
# Название и версия проекта и используемые языки программирования
|
|
project(FIXME VERSION 0.0.1 LANGUAGES C CXX)
|
|
|
|
###
|
|
# Обязательные переменные для MyxCMake
|
|
###
|
|
# Название организации
|
|
set(MYX_CMAKE_ORGANIZATION_NAME "FIXME" CACHE STRING "")
|
|
|
|
# Имя автора
|
|
set(MYX_CMAKE_AUTHOR_NAME "FIXME" CACHE STRING "")
|
|
|
|
# Почта автора
|
|
set(MYX_CMAKE_AUTHOR_EMAIL "FIXME" CACHE STRING "")
|
|
|
|
# Краткое описание проекта
|
|
set(MYX_CMAKE_DESCRIPTION "FIXME" CACHE STRING "")
|
|
|
|
find_package(MyxCMake 0.3.8 REQUIRED)
|
|
CML
|
|
|
|
git add CMakeLists.txt .clang-tidy .cmake-format.py .gitignore .gitlab-ci.yml .uncrustify.cfg files
|
|
git commit -m "Начало проекта"
|
|
|
|
if [ -e .gitmodules ]; then
|
|
sed -i 's/git@${SERVER}:/..\/..\//' .gitmodules
|
|
git submodule sync --recursive
|
|
git commit -m "Относительные пути к подмодулям" .gitmodules
|
|
fi
|
|
|