@echo off

REM This script should be run from an elevated prompt

SET USER_NAME=%1 %2
SET USER_EMAIL=%3

if not defined USER_NAME goto :missing_arguments
if not defined USER_EMAIL goto :missing_arguments

:rest_of_script

REM Installing chocolatey

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

choco feature enable -n=allowGlobalConfirmation

choco install 7zip.install

choco install openvpn

choco install vcredist2010

choco install mysql.workbench

choco install git.install

choco install gitextensions

choco install putty.install

choco install winscp

choco install nodejs

choco install visualstudiocode

choco install notepadplusplus

choco install kdiff3

choco install vmware-workstation-player

REM Create desktop shortcuts

REM Moved to electron app so it can support args: mklink "%USERPROFILE%\Desktop\pageant.lnk" "%ProgramFiles%\PUTTY\pageant.exe"
mklink "%USERPROFILE%\Desktop\putty.lnk" "%ProgramFiles%\PUTTY\putty.exe"
mklink "%USERPROFILE%\Desktop\WinSCP.lnk" "%ProgramFiles(x86)%\WinSCP\WinSCP.exe"
mklink "%USERPROFILE%\Desktop\MySQLWorkbench.lnk" "%ProgramFiles%\MySQL\MySQL Workbench 6.3 CE\MySQLWorkbench.exe"
mklink "%USERPROFILE%\Desktop\Code.lnk" "%ProgramFiles%\Microsoft VS Code\Code.exe"
mklink "%USERPROFILE%\Desktop\notepad++.lnk" "%ProgramFiles%\Notepad++\notepad++.exe"

REM Generate ssh keys without needing a passphrase
SET noPassowrd  = ""

REM Commit as is push as is
git config --global core.autocrlf false

REM Configure git user.name and user.email
git config --global user.name %USER_NAME%
git config --global user.email %USER_EMAIL%

REM Create a shortcut for pageant.exe and place it in Startup folder
REM Moved to electron app so it can support args: mklink "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\pageant.lnk" "%ProgramFiles%\PUTTY\pageant.exe"

REM Generate SSH keys and put them in \.ssh folder
ssh-keygen -t rsa -b 4096 -N "%noPassowrd%" -f "%USERPROFILE%\.ssh\id_rsa"

REM Convert OpenSSH key format to Putty .ppk format
WinSCP.com /keygen %USERPROFILE%\.ssh\id_rsa -output=%USERPROFILE%\.ssh\id_rsa.ppk

REM Set WinSCP to run as administrator
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%ProgramFiles(x86)%\WinSCP\WinSCP.exe" /t REG_SZ /d "RUNASADMIN" /f

REM Set OpenVPN to run as administrator
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%ProgramFiles%\OpenVPN\bin\openvpn-gui.exe" /t REG_SZ /d "RUNASADMIN" /f

REM Add git to Path so that you can access it from cmd
setx path "%PATH%;%ProgramFiles%\Git\bin" 

REM Configure WinSCP with ini file
%~d0
copy "%~dp0/WinSCP.ini" "%ProgramFiles(x86)%\WinSCP"
regedit /s "%~dp0\putty_agent_forwarding.reg"

REM Protect SSH keys and WinSCP.ini with efs
cipher /E "%USERPROFILE%\.ssh\*"
cipher /E "%ProgramFiles(x86)%\WinSCP\WinSCP.ini"

exit /b 0

:missing_arguments

SET /p "USER_NAME= Please enter your name(firstname and lastname) followed by [ENTER]"
SET /p "USER_EMAIL= Please enter your email followed by [ENTER]"

if not defined USER_NAME goto :missing_arguments
if not defined USER_EMAIL goto :missing_arguments

goto :rest_of_script
	