|
|
|
@ -7,30 +7,51 @@ uninstallkey = [] |
|
|
|
|
def install(): |
|
|
|
|
print('Installing OpenSSH') |
|
|
|
|
mkdirs(makepath(programfiles,'OpenSSH')) |
|
|
|
|
|
|
|
|
|
print(' Stoping the service') |
|
|
|
|
if service_installed('sshd') and service_is_running('sshd'): |
|
|
|
|
service_stop('sshd') |
|
|
|
|
killalltasks('sshd.exe') |
|
|
|
|
for service in ['sshd','ssh-agent']: |
|
|
|
|
if service_installed(service) and service_is_running(service): |
|
|
|
|
service_stop(service) |
|
|
|
|
killalltasks('%s.exe' % service) |
|
|
|
|
|
|
|
|
|
print(' Extract OpenSSH archive') |
|
|
|
|
run('"%s" e -y -o"%s" OpenSSH-Win%s.zip' % (makepath(programfiles,'7-Zip','7z.exe'),makepath(programfiles,'OpenSSH'),'64' if iswin64() else '32')) |
|
|
|
|
print(' Installing the service') |
|
|
|
|
run(r'powershell.exe -ExecutionPolicy Bypass -File "%s\install-sshd.ps1"' % makepath(programfiles,'OpenSSH')) |
|
|
|
|
|
|
|
|
|
print(' Installing the services') |
|
|
|
|
run(r'sc.exe create sshd binPath= "%s" DisplayName= "OpenSSH Server" start= auto' % makepath(programfiles,'OpenSSH','sshd.exe'), accept_returncodes=[0,1073]) |
|
|
|
|
run(r'sc.exe privs sshd SeAssignPrimaryTokenPrivilege/SeTcbPrivilege/SeBackupPrivilege/SeRestorePrivilege/SeImpersonatePrivilege') |
|
|
|
|
run(r'sc.exe create ssh-agent binPath= "%s" DisplayName= "OpenSSH Authentication Agent" start= auto' % makepath(programfiles,'OpenSSH','ssh-agent.exe'), accept_returncodes=[0,1073]) |
|
|
|
|
run(r'sc.exe sdset ssh-agent "D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)(A;;RP;;;AU)"') |
|
|
|
|
run(r'sc.exe privs ssh-agent SeImpersonatePrivilege') |
|
|
|
|
run(r'wevtutil.exe um "%s"' % makepath(programfiles,'OpenSSH','openssh-events.man')) |
|
|
|
|
filecopyto('openssh-events.man',makepath(programfiles,'OpenSSH')) |
|
|
|
|
run(r'wevtutil.exe im "%s"' % makepath(programfiles,'OpenSSH','openssh-events.man')) |
|
|
|
|
|
|
|
|
|
print(' Opening port 22 in the firewall') |
|
|
|
|
run_notfatal(r'netsh advfirewall firewall del rule name="OpenSSH Server"') |
|
|
|
|
run(r'netsh advfirewall firewall add rule name="OpenSSH Server" dir=in action=allow protocol=TCP localport=22 enable=yes') |
|
|
|
|
|
|
|
|
|
print(' Starting the service') |
|
|
|
|
service_start('sshd') |
|
|
|
|
|
|
|
|
|
print(r' Enabling sshd service on boot') |
|
|
|
|
run('sc config sshd start= auto') |
|
|
|
|
|
|
|
|
|
def uninstall(): |
|
|
|
|
print('Removing OpenSSH') |
|
|
|
|
print(' Stoping the service') |
|
|
|
|
if service_is_running('sshd'): |
|
|
|
|
service_stop('sshd') |
|
|
|
|
killalltasks('sshd.exe') |
|
|
|
|
print(' Uninstalling the service') |
|
|
|
|
run(r'powershell.exe -ExecutionPolicy Bypass -File "%s\uninstall-sshd.ps1"' % makepath(programfiles,'OpenSSH')) |
|
|
|
|
|
|
|
|
|
for service in ['sshd','ssh-agent']: |
|
|
|
|
print(' Stoping the services %s' % service) |
|
|
|
|
if service_is_running(service): |
|
|
|
|
service_stop(service) |
|
|
|
|
killalltasks('%s.exe' % service) |
|
|
|
|
|
|
|
|
|
print(' Uninstalling service %s' % service) |
|
|
|
|
run(r'sc.exe delete %s' % service) |
|
|
|
|
|
|
|
|
|
print(' Unregister events handler') |
|
|
|
|
run(r'wevtutil um "%s"' % makepath(programfiles,'OpenSSH','openssh-events.man')) |
|
|
|
|
|
|
|
|
|
print(' Removing files') |
|
|
|
|
remove_tree(makepath(programfiles,'OpenSSH')) |
|
|
|
|
|
|
|
|
|