@echo off & (if not "%cmd_shelled%" == "" goto shell2) & call :shell1 %~f0 %* 2>&1 <nul & goto return
:shell1
c:\windows\system32\cmd.exe /c set cmd_shelled=1^& %* & (if ERRORLEVEL 1 echo ERROR) & goto return
:shell2
set cmd_shelled=
cd %~dp0
set ssh_folder=%userprofile%\.ssh\ssh

if exist %ssh_folder%\sshd_config goto configure_done
mkdir %ssh_folder%\__PROGRAMDATA__
if errorlevel 1 goto return
mklink /d %ssh_folder%\__PROGRAMDATA__\ssh ..
if errorlevel 1 goto return
ssh-keygen.exe -A -f %ssh_folder%\
if errorlevel 1 goto return
rmdir %ssh_folder%\__PROGRAMDATA__\ssh
rmdir %ssh_folder%\__PROGRAMDATA__
copy sshd.exe %ssh_folder%
copy sshd-auth.exe %ssh_folder%
copy sshd-session.exe %ssh_folder%
copy libcrypto.dll %ssh_folder%
cd /d %ssh_folder%
echo PidFile none>sshd_config
echo Port 2222>>sshd_config
echo AllowAgentForwarding no>>sshd_config
echo AllowTcpForwarding no>>sshd_config
echo PermitTunnel no>>sshd_config
echo PrintMotd no>>sshd_config
echo PrintLastLog no>>sshd_config
echo UseDNS no>>sshd_config
echo PermitUserEnvironment yes>>sshd_config
echo PasswordAuthentication no>>sshd_config
echo KbdInteractiveAuthentication no>>sshd_config
echo PubkeyAuthentication yes>>sshd_config
echo HostKeyAlgorithms +ssh-rsa>>sshd_config
echo PubkeyAcceptedKeyTypes +ssh-rsa>>sshd_config
echo HostKey ssh_host_rsa_key>>sshd_config
echo HostKey ssh_host_ecdsa_key>>sshd_config
echo HostKey ssh_host_ed25519_key>>sshd_config
:configure_done

cd /d %ssh_folder%
%ssh_folder%\sshd.exe -f sshd_config -e

:return
