From 114218cf17a2dfb17e47ec1e019c92aac100c48a Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 11 Dec 2018 11:59:59 +0100 Subject: [PATCH] First version of the package --- OpenSSH-Win32.zip | 3 + OpenSSH-Win64.zip | 3 + WAPT/control | 32 ++++++ WAPT/wapt.psproj | 295 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 60 +++++++++++ 5 files changed, 393 insertions(+) create mode 100644 OpenSSH-Win32.zip create mode 100644 OpenSSH-Win64.zip create mode 100644 WAPT/control create mode 100644 WAPT/wapt.psproj create mode 100644 setup.py diff --git a/OpenSSH-Win32.zip b/OpenSSH-Win32.zip new file mode 100644 index 0000000..49313df --- /dev/null +++ b/OpenSSH-Win32.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c9179bbd4d651cc15fe036120234fb0e1b21c2661ca3228106470f3ac7e86a19 +size 2892367 diff --git a/OpenSSH-Win64.zip b/OpenSSH-Win64.zip new file mode 100644 index 0000000..76aaff3 --- /dev/null +++ b/OpenSSH-Win64.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8631f00013116388362cb06f3e6fd2c44c8e57d8f857033111f98feb34fa5bce +size 3302851 diff --git a/WAPT/control b/WAPT/control new file mode 100644 index 0000000..d9dd284 --- /dev/null +++ b/WAPT/control @@ -0,0 +1,32 @@ +package : fws-openssh +version : 7.7.2.0-1 +architecture : all +section : base +priority : optional +maintainer : Daniel Berteaud +description : OpenSSH for Windows +depends : +conflicts : +maturity : DEV +locale : +target_os : windows +min_os_version : 6.1 +max_os_version : +min_wapt_version : 1.5 +sources : +installed_size : +impacted_process : sshd.exe,ssh.exe +description_fr : OpenSSH pour WIndows +description_pl : +description_de : +description_es : +audit_schedule : 2d +editor : +keywords : ssh +licence : +homepage : https://github.com/PowerShell/Win32-OpenSSH +package_uuid : +signer : Daniel Berteaud +signer_fingerprint: +signature_date : +signed_attributes : \ No newline at end of file diff --git a/WAPT/wapt.psproj b/WAPT/wapt.psproj new file mode 100644 index 0000000..29acc4b --- /dev/null +++ b/WAPT/wapt.psproj @@ -0,0 +1,295 @@ +[PyScripter] +Version=3.3.2.0 + +[Project] +ClassName=TProjectRootNode +StoreRelativePaths=TRUE +ShowFileExtensions=FALSE + +[Project\ChildNodes\Node0] +ClassName=TProjectFilesNode + +[Project\ChildNodes\Node0\ChildNodes\Node0] +ClassName=TProjectFolderNode +Name=wapt + +[Project\ChildNodes\Node0\ChildNodes\Node0\ChildNodes\Node0] +ClassName=TProjectFileNode +FileName=C:\Program Files (x86)\wapt\common.py + +[Project\ChildNodes\Node0\ChildNodes\Node0\ChildNodes\Node1] +ClassName=TProjectFileNode +FileName=C:\Program Files (x86)\wapt\setuphelpers.py + +[Project\ChildNodes\Node0\ChildNodes\Node0\ChildNodes\Node2] +ClassName=TProjectFileNode +FileName=C:\Program Files (x86)\wapt\wapt-get.ini + +[Project\ChildNodes\Node0\ChildNodes\Node0\ChildNodes\Node3] +ClassName=TProjectFileNode +FileName=C:\Program Files (x86)\wapt\wapt-get.py + +[Project\ChildNodes\Node0\ChildNodes\Node0\ChildNodes\Node4] +ClassName=TProjectFileNode +FileName=C:\Program Files (x86)\wapt\waptpackage.py + +[Project\ChildNodes\Node0\ChildNodes\Node0\ChildNodes] +Count=5 + +[Project\ChildNodes\Node0\ChildNodes\Node1] +ClassName=TProjectFileNode +FileName=$[Project-Path]changelog.txt + +[Project\ChildNodes\Node0\ChildNodes\Node2] +ClassName=TProjectFileNode +FileName=$[Project-Path]control + +[Project\ChildNodes\Node0\ChildNodes\Node3] +ClassName=TProjectFileNode +FileName=$[Project-Path]..\setup.py + +[Project\ChildNodes\Node0\ChildNodes] +Count=4 + +[Project\ChildNodes\Node1] +ClassName=TProjectRunConfiguationsNode + +[Project\ChildNodes\Node1\ChildNodes\Node0] +ClassName=TProjectRunConfiguationNode +Name=install + +[Project\ChildNodes\Node1\ChildNodes\Node0\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=install "$[Project-Path].." +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node0\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node1] +ClassName=TProjectRunConfiguationNode +Name=remove + +[Project\ChildNodes\Node1\ChildNodes\Node1\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=remove "$[Project-Path].." +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node1\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node2] +ClassName=TProjectRunConfiguationNode +Name=session-setup + +[Project\ChildNodes\Node1\ChildNodes\Node2\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=session-setup "$[Project-Path].." +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node2\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node3] +ClassName=TProjectRunConfiguationNode +Name=update + +[Project\ChildNodes\Node1\ChildNodes\Node3\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=update +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node3\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node4] +ClassName=TProjectRunConfiguationNode +Name=upgrade + +[Project\ChildNodes\Node1\ChildNodes\Node4\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=-f upgrade +WorkingDir=$[ActiveScript-Dir] +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node4\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node5] +ClassName=TProjectRunConfiguationNode +Name=-i build-upload + +[Project\ChildNodes\Node1\ChildNodes\Node5\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=-i build-upload "$[Project-Path].." +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node5\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node6] +ClassName=TProjectRunConfiguationNode +Name=svn update + +[Project\ChildNodes\Node1\ChildNodes\Node6\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=sources "$[Project-Path].." +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node6\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node7] +ClassName=TProjectRunConfiguationNode +Name=uninstall + +[Project\ChildNodes\Node1\ChildNodes\Node7\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=uninstall "$[Project-Path].." +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node7\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[Project-Path].. +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node8] +ClassName=TProjectRunConfiguationNode +Name=update-package-sources + +[Project\ChildNodes\Node1\ChildNodes\Node8\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=update-package-sources "$[Project-Path].." +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node8\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes\Node9] +ClassName=TProjectRunConfiguationNode +Name=audit + +[Project\ChildNodes\Node1\ChildNodes\Node9\RunConfig] +ScriptName=C:\Program Files (x86)\wapt\wapt-get.py +EngineType=peRemote +ReinitializeBeforeRun=TRUE +Parameters=audit "$[Project-Path].." +WorkingDir=$[Project-Path].. +WriteOutputToFile=FALSE +OutputFileName=$[ActiveScript-NoExt].log +AppendToFile=FALSE + +[Project\ChildNodes\Node1\ChildNodes\Node9\RunConfig\ExternalRun] +Caption=External Run +Description=Run script using an external Python Interpreter +ApplicationName=$[PythonExe-Short] +Parameters=$[ActiveScript-Short] +WorkingDirectory=$[ActiveScript-Dir] +ShortCut=0 +MessagesFormat=$[FileName] $[LineNumber] + +[Project\ChildNodes\Node1\ChildNodes] +Count=10 + +[Project\ChildNodes] +Count=2 + +[Project\ExtraPythonPath] +Count=0 + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..15472c0 --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +from setuphelpers import * +import requests,json + +uninstallkey = [] + +def install(): + print('Installing OpenSSH') + mkdirs(makepath(programfiles,'OpenSSH')) + print(' Stoping the service') + run_notfatal(r'sc stop sshd') + 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(' 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') + run(r'sc start sshd', accept_returncodes=[0,1056]) + print(r' Enabling sshd service on boot') + run('sc config sshd start= auto') + +def uninstall(): + print('Removing OpenSSH') + print(' Stoping the service') + run_notfatal('sc stop sshd') + killalltasks('ssh.exe') + print(' Uninstalling the service') + run(r'powershell.exe -ExecutionPolicy Bypass -File "%s\uninstall-sshd.ps1"' % makepath(programfiles,'OpenSSH')) + print(' Removing files') + remove_tree(makepath(programfiles,'OpenSSH')) + +def update_package(): + print('Updating OpenSSH Package') + latest = json.loads(requests.get('https://api.github.com/repos/PowerShell/Win32-OpenSSH/releases/latest').text.encode('utf-8')) + version = latest['tag_name'].split('-',1)[0].lstrip('v').rstrip('p1') + pe = PackageEntry(); + control = pe.load_control_from_wapt('.') + for arch in ['32','64']: + for asset in latest['assets']: + if asset['name'] == 'OpenSSH-Win%s.zip' % arch and not isfile('OpenSSH-Win%s.zip' % arch): + url = asset['browser_download_url'] + print('Downloading OpenSSH %s for win%s from %s' % (version,arch,url)) + wget(url,'OpenSSH-Win%s.zip' % arch) + if Version(version) > Version(control['version'].split('-',1)[0]): + print('Updating control file with new version %s' % version) + pe.version = version + '-0' + pe.save_control_to_wapt('.') + +def audit(): + version = control['version'].split('-',1)[0] + installed_version = get_file_properties(makepath(programfiles,'OpenSSH','sshd.exe'))['FileVersion'] + if Version(version) != Version(installed_version): + print('Installed version %s does not match version %s' % (version, installed_version)) + return "ERROR" + return "OK" + +if __name__ == '__main__': + update_package()