@echo off

set platform=x64
if NOT EXIST "%ProgramFiles(x86)%" set platform=x86

echo.
echo Installing UConn GitHub for Windows...
echo.

rem Prompt for Name and Email.
echo.
echo You need to enter some information so Git can be configured for you.
echo.
set /P name=Please enter your name: 
set /P email=Please enter your email address: 

rem Install Programs.
echo.
echo Installing Git...
start /w Git-1.7.8-preview20111206.exe /silent
echo Installing GitExtensions...
start /w msiexec /I GitExtensions228SetupComplete.msi SSHCLIENT="OpenSSH" INSTALLMSYSGIT="0" INSTALLKDIFF3="0" ALLUSERS="1" /quiet /passive
echo Installing KDiff3...
start /w KDiff3Setup_0.9.96.exe /S

if "%platform%"=="x64" goto path64
goto path86

rem ADD TO PATH (x64)
:path64
set GITPATH=C:\Program Files (x86)\Git\bin
goto :path

:path86
set GITPATH=C:\Program Files\Git\bin
goto :path

:path
setx PATH "%PATH%;%GITPATH%" -m >NUL

rem SET GIT CONFIGURATION
:config
"%GITPATH%\git" config --global core.editor notepad.exe
"%GITPATH%\git" config --global core.name %name%
"%GITPATH%\git" config --global core.email %email%

rem CHECK FOR SSH KEY.  IF NOT DETECTED, GENERATE.
if not exist "%HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa" (
    mkdir "%HOMEDRIVE%%HOMEPATH%\.ssh"
    "%GITPATH%\ssh-keygen.exe" -f "%HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa" -t rsa -b 2048 -N '' -C "%name% <%email%>" >NUL
)

clip < "%HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa.pub"

echo.
echo Your SSH key has been automatically generated and copied to your clipboard.
echo Click this window and then press any key to continue.  Your web browser will open to UConn GitHub.
echo     1) Sign in if you have not already done so.
echo     2) Click "Account Settings" in the upper right corner of the page.
echo     3) Click "SSH Public Keys" on the left.
echo     4) Click "Add another public key".
echo     5) Paste (Control+V) into the "Key" box and Click "Add Key".
echo.

pause
start http://github.uconn.edu/account/ssh

:finish
echo.
echo Done!  You can now close this window and start using Git / UConn GitHub.
echo.

pause >NUL