82 lines
2.1 KiB
Bash
Executable File
82 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
key="$1"
|
|
|
|
case $key in
|
|
-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
|
|
|
|
[[ -z "$DIRECTORY" ]] && DIRECTORY="$(pwd)"
|
|
if [[ -d "${DIRECTORY}/.git" ]]; then
|
|
echo "Directory already has repository. Exiting"
|
|
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 ! mkdir -p "$DIRECTORY"; then
|
|
echo "Can't create directory for git repository"
|
|
exit 1
|
|
fi
|
|
|
|
pushd "$DIRECTORY" >/dev/null
|
|
|
|
if ! git init; then
|
|
echo "Can't create git repository in directory $DIRECTORY"
|
|
exit 1
|
|
fi
|
|
mkdir -p files/{etc,log,share,var}
|
|
touch files/{etc,log,share,var}/.gitkeep
|
|
|
|
wget "${BASE_URL}/f1x1t/cmake-format/${BRANCH_API}/master/.cmake-format.py"
|
|
wget "${BASE_URL}/f1x1t/cmlib-gitignore/${BRANCH_API}/master/.gitignore"
|
|
wget "${BASE_URL}/f1x1t/gitlab-ci/${BRANCH_API}/master/.gitlab-ci.yml"
|
|
wget -o files/etc/uncrustify.cfg "${BASE_URL}/f1x1t/uncrustify-config/${BRANCH_API}/master/default.cfg"
|
|
wget -O - "${BASE_URL}/f1x1t/githooks/${GITHOOKS_ARCHIVE}" | tar zx --strip-components=1 -C .git/hooks
|
|
|
|
sed -i '/.*_CMD.*/d' .gitlab-ci.yml
|
|
sed -i '/.*variables:.*/d' .gitlab-ci.yml
|
|
sed -i 's/^UNCRUST_CONFIG.*/UNCRUST_CONFIG=$REPO\/files\/etc\/uncrustify.cfg/' .git/hooks/pre-commit-uncrustify.cfg
|
|
|
|
git add .cmake-format.py .gitignore .gitlab-ci.yml files
|
|
git commit -m "Начало проекта"
|
|
|
|
if [ -e .gitmodules ]; then
|
|
sed -i 's/git@${SERVER}:/..\/..\//' .gitmodules
|
|
git submodule sync --recursive
|
|
git commit -m "Относительные пути к подмодулям" .gitmodules
|
|
fi
|
|
|
|
popd >/dev/null
|
|
|