@echo off
echo CreateConfiguratorRepo.bat - v1.0.0

rem -------------------- ATTRIBUTES -------------------------------

set GitRaumgleiter=git.raumgleiter.com
set ConfiguratorGroup=/web/configurators/
set Template=pilatus_configurator
set User=simongloor
set Token=Dc717ZNyse6c4snsWEKP

rem -------------------------------------------

set GitServerRaumgleiter=https://%user%:%Token%@%GitRaumgleiter%
set TemplateRepository=%GitServerRaumgleiter%%ConfiguratorGroup%%Template%.git

rem -------------------- USER INPUTS ----------------------------------

echo "                          "
echo "             _            "
echo "            [ ]           "
echo "           (^-^)          "
echo "            | |           "
echo "         __/===\__        "
echo "        //| o=o |\\       "
echo "      <]  | o=o |  [>     "
echo "          \=====/         "
echo "         / / | \ \        "
echo "        <_________>       "
echo "                          "
echo "   Hi! I'm CreateConfi Bot!   "
echo "                              "
echo ""
echo "   Before we can start,                                         "
echo "   I'm required to gather some information about the project.   "
echo ""
set /p ProjectName="What is the projects name?   "

rem ------------------------------------------------------

set RepoName=%ProjectName%_configurator
set NewRepository=%GitServerRaumgleiter%%ConfiguratorGroup%%RepoName%.git

echo "                          "
echo "             _            "
echo "            [ ]           "
echo "           (^-^)          "
echo "                          "
echo ""
echo "   Allright, this will create this git repo:   "
echo ""  %NewRepository%
echo ""

pause

rem ----------------------- CHECK CONNECTION -------------------------------

setlocal enabledelayedexpansion

set /A i=0
:PluginAccess
call echo "   Connecting to Template: " %TemplateRepository%
call git ls-remote %TemplateRepository% >nul
  if not errorlevel 1 (
  	call echo "   Success: " %TemplateRepository%
	set /a i=%i%+1
  	goto :ConnectionSuccessful
  ) else (
    call echo "                          "
		call echo "             _            "
		call echo "            [ ]           "
		call echo "           (>_<)          "
		call echo "                          "
		call echo ""
		call echo "   Hmmmm...                                       "
		call echo "   The template can't be accessed: "	%TemplateRepository%
		call echo ""
		call echo "   Here are some ideas what could be wrong:       "
		call echo "    - Have you entered correct credentials?       "
		call echo "    - Does your network prevent the connection?   "
		call echo ""
		call echo "   Try again?                                     "
		call echo ""
		pause

    call echo "Resetting password for: "	%GitServerRaumgleiter%
    call echo url=%GitServerRaumgleiter%/ > tmp.txt
    call git credential reject < tmp.txt
    goto :PluginAccess
    )
)
setlocal disabledelayedexpansion

:ConnectionSuccessful

rem ----------------------- MIRROR -------------------------------

:Downloaded
C:
cd C:/temp
call git clone --bare %TemplateRepository%
cd %Template%.git
call git lfs fetch --all
call git lfs install
call git push --set-upstream %NewRepository%
git lfs push --all %NewRepository%
cd ..
rmdir -s %Template%.git

rem ------------------------ DONE ----------------------

echo "                          "
echo "             _            "
echo "            [ ]           "
echo "           (^-^)          "
echo "                          "
echo ""
echo "   Allright!                             "
echo "   The repository has been mirrored.     "
echo ""
pause

start "" "%NewRepository%"

timeout 300
EXIT /B 0

rem ------------------------------------------------------
