diff --git a/utils/dockerized/windows/modpath.iss b/utils/dockerized/windows/modpath.iss new file mode 100644 index 0000000..c9deb08 --- /dev/null +++ b/utils/dockerized/windows/modpath.iss @@ -0,0 +1,219 @@ +// ---------------------------------------------------------------------------- +// +// Inno Setup Ver: 5.4.2 +// Script Version: 1.4.2 +// Author: Jared Breland +// Homepage: http://www.legroom.net/software +// License: GNU Lesser General Public License (LGPL), version 3 +// http://www.gnu.org/licenses/lgpl.html +// +// Script Function: +// Allow modification of environmental path directly from Inno Setup installers +// +// Instructions: +// Copy modpath.iss to the same directory as your setup script +// +// Add this statement to your [Setup] section +// ChangesEnvironment=true +// +// Add this statement to your [Tasks] section +// You can change the Description or Flags +// You can change the Name, but it must match the ModPathName setting below +// Name: modifypath; Description: &Add application directory to your environmental path; Flags: unchecked +// +// Add the following to the end of your [Code] section +// ModPathName defines the name of the task defined above +// ModPathType defines whether the 'user' or 'system' path will be modified; +// this will default to user if anything other than system is set +// setArrayLength must specify the total number of dirs to be added +// Result[0] contains first directory, Result[1] contains second, etc. +// const +// ModPathName = 'modifypath'; +// ModPathType = 'user'; +// +// function ModPathDir(): TArrayOfString; +// begin +// setArrayLength(Result, 1); +// Result[0] := ExpandConstant('{app}'); +// end; +// #include "modpath.iss" +// ---------------------------------------------------------------------------- + +procedure ModPath(); +var + oldpath: String; + newpath: String; + updatepath: Boolean; + pathArr: TArrayOfString; + aExecFile: String; + aExecArr: TArrayOfString; + i, d: Integer; + pathdir: TArrayOfString; + regroot: Integer; + regpath: String; + +begin + // Get constants from main script and adjust behavior accordingly + // ModPathType MUST be 'system' or 'user'; force 'user' if invalid + if ModPathType = 'system' then begin + regroot := HKEY_LOCAL_MACHINE; + regpath := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'; + end else begin + regroot := HKEY_CURRENT_USER; + regpath := 'Environment'; + end; + + // Get array of new directories and act on each individually + pathdir := ModPathDir(); + for d := 0 to GetArrayLength(pathdir)-1 do begin + updatepath := true; + + // Modify WinNT path + if UsingWinNT() = true then begin + + // Get current path, split into an array + RegQueryStringValue(regroot, regpath, 'Path', oldpath); + oldpath := oldpath + ';'; + i := 0; + + while (Pos(';', oldpath) > 0) do begin + SetArrayLength(pathArr, i+1); + pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1); + oldpath := Copy(oldpath, Pos(';', oldpath)+1, Length(oldpath)); + i := i + 1; + + // Check if current directory matches app dir + if pathdir[d] = pathArr[i-1] then begin + // if uninstalling, remove dir from path + if IsUninstaller() = true then begin + continue; + // if installing, flag that dir already exists in path + end else begin + updatepath := false; + end; + end; + + // Add current directory to new path + if i = 1 then begin + newpath := pathArr[i-1]; + end else begin + newpath := newpath + ';' + pathArr[i-1]; + end; + end; + + // Append app dir to path if not already included + if (IsUninstaller() = false) AND (updatepath = true) then + newpath := newpath + ';' + pathdir[d]; + + // Write new path + RegWriteStringValue(regroot, regpath, 'Path', newpath); + + // Modify Win9x path + end else begin + + // Convert to shortened dirname + pathdir[d] := GetShortName(pathdir[d]); + + // If autoexec.bat exists, check if app dir already exists in path + aExecFile := 'C:\AUTOEXEC.BAT'; + if FileExists(aExecFile) then begin + LoadStringsFromFile(aExecFile, aExecArr); + for i := 0 to GetArrayLength(aExecArr)-1 do begin + if IsUninstaller() = false then begin + // If app dir already exists while installing, skip add + if (Pos(pathdir[d], aExecArr[i]) > 0) then + updatepath := false; + break; + end else begin + // If app dir exists and = what we originally set, then delete at uninstall + if aExecArr[i] = 'SET PATH=%PATH%;' + pathdir[d] then + aExecArr[i] := ''; + end; + end; + end; + + // If app dir not found, or autoexec.bat didn't exist, then (create and) append to current path + if (IsUninstaller() = false) AND (updatepath = true) then begin + SaveStringToFile(aExecFile, #13#10 + 'SET PATH=%PATH%;' + pathdir[d], True); + + // If uninstalling, write the full autoexec out + end else begin + SaveStringsToFile(aExecFile, aExecArr, False); + end; + end; + end; +end; + +// Split a string into an array using passed delimeter +procedure MPExplode(var Dest: TArrayOfString; Text: String; Separator: String); +var + i: Integer; +begin + i := 0; + repeat + SetArrayLength(Dest, i+1); + if Pos(Separator,Text) > 0 then begin + Dest[i] := Copy(Text, 1, Pos(Separator, Text)-1); + Text := Copy(Text, Pos(Separator,Text) + Length(Separator), Length(Text)); + i := i + 1; + end else begin + Dest[i] := Text; + Text := ''; + end; + until Length(Text)=0; +end; + + +procedure CurStepChanged(CurStep: TSetupStep); +var + taskname: String; +begin + taskname := ModPathName; + if CurStep = ssPostInstall then + if WizardIsTaskSelected(taskname) then + ModPath(); +end; + +procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); +var + aSelectedTasks: TArrayOfString; + i: Integer; + taskname: String; + regpath: String; + regstring: String; + appid: String; +begin + // only run during actual uninstall + if CurUninstallStep = usUninstall then begin + // get list of selected tasks saved in registry at install time + appid := '{#emit SetupSetting("AppId")}'; + if appid = '' then appid := '{#emit SetupSetting("AppName")}'; + regpath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\'+appid+'_is1'); + RegQueryStringValue(HKLM, regpath, 'Inno Setup: Selected Tasks', regstring); + if regstring = '' then RegQueryStringValue(HKCU, regpath, 'Inno Setup: Selected Tasks', regstring); + + // check each task; if matches modpath taskname, trigger patch removal + if regstring <> '' then begin + taskname := ModPathName; + MPExplode(aSelectedTasks, regstring, ','); + if GetArrayLength(aSelectedTasks) > 0 then begin + for i := 0 to GetArrayLength(aSelectedTasks)-1 do begin + if comparetext(aSelectedTasks[i], taskname) = 0 then + ModPath(); + end; + end; + end; + end; +end; + +function NeedRestart(): Boolean; +var + taskname: String; +begin + taskname := ModPathName; + if WizardIsTaskSelected(taskname) and not UsingWinNT() then begin + Result := True; + end else begin + Result := False; + end; +end; diff --git a/utils/dockerized/windows/msspec.exe b/utils/dockerized/windows/msspec.exe new file mode 100644 index 0000000..4e982e6 Binary files /dev/null and b/utils/dockerized/windows/msspec.exe differ diff --git a/utils/dockerized/windows/msspec.iss b/utils/dockerized/windows/msspec.iss new file mode 100644 index 0000000..a94374d --- /dev/null +++ b/utils/dockerized/windows/msspec.iss @@ -0,0 +1,69 @@ +; Script generated by the Inno Setup Script Wizard. +; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! + +#define MyAppName "MsSpec" +#define MyAppVersion "" +#define MyAppPublisher "IPR" +#define MyAppURL "https://msspec.cnrs.fr" +#define MyAppExeName "msspec.exe" +#define MyAppInstallerName "msspec_setup" + +[Setup] +; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications. +; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) +AppId={{BB2F7A31-BDDF-4D22-BDBD-C77BEB6D3780}} +AppName={#MyAppName} +;AppVersion={#MyAppVersion} +AppVerName={#MyAppName} {#MyAppVersion} +AppPublisher={#MyAppPublisher} +AppPublisherURL={#MyAppURL} +AppSupportURL={#MyAppURL} +AppUpdatesURL={#MyAppURL} +DefaultDirName={autopf}\{#MyAppName} +DefaultGroupName={#MyAppName} +DisableProgramGroupPage=yes +; Uncomment the following line to run in non administrative install mode (install for current user only.) +;PrivilegesRequired=lowest +PrivilegesRequiredOverridesAllowed=dialog +OutputBaseFilename={#MyAppInstallerName} +Compression=lzma +SolidCompression=yes +WizardStyle=modern +ChangesEnvironment=true + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl" + +[Files] +Source: ".\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion +;Source: "D:\Home\stricot\Documents\WindowsPowerShell\Scripts\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion +; NOTE: Don't use "Flags: ignoreversion" on any shared system files + +;[Icons] +;Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" + +;[Run] +;Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent + +[Tasks] +Name: modifypath; Description: Add application directory to your environmental path; +;Flags: unchecked + +[UninstallRun] +Filename: "{app}\{#MyAppExeName}"; Parameters: "-u"; + +[Messages] +FinishedLabelNoIcons=Setup has finished installing [name] on your computer. To launch MsSpec, open a terminal window and enter 'msspec'. + +[Code] +const + ModPathName = 'modifypath'; + ModPathType = 'user'; + +function ModPathDir(): TArrayOfString; +begin + setArrayLength(Result, 1) + Result[0] := ExpandConstant('{app}'); +end; +#include "modpath.iss" + diff --git a/utils/dockerized/windows/msspec.ps1 b/utils/dockerized/windows/msspec.ps1 new file mode 100644 index 0000000..cbbdab7 --- /dev/null +++ b/utils/dockerized/windows/msspec.ps1 @@ -0,0 +1,171 @@ +##[Ps1 To Exe] +## +##Kd3HDZOFADWE8uK1 +##Nc3NCtDXThU= +##Kd3HFJGZHWLWoLaVvnQnhQ== +##LM/RF4eFHHGZ7/K1 +##K8rLFtDXTiW5 +##OsHQCZGeTiiZ4tI= +##OcrLFtDXTiW5 +##LM/BD5WYTiiZ4tI= +##McvWDJ+OTiiZ4tI= +##OMvOC56PFnzN8u+Vs1Q= +##M9jHFoeYB2Hc8u+Vs1Q= +##PdrWFpmIG2HcofKIo2QX +##OMfRFJyLFzWE8uK1 +##KsfMAp/KUzWJ0g== +##OsfOAYaPHGbQvbyVvnQX +##LNzNAIWJGmPcoKHc7Do3uAuO +##LNzNAIWJGnvYv7eVvnQX +##M9zLA5mED3nfu77Q7TV64AuzAgg= +##NcDWAYKED3nfu77Q7TV64AuzAgg= +##OMvRB4KDHmHQvbyVvnQX +##P8HPFJGEFzWE8tI= +##KNzDAJWHD2fS8u+Vgw== +##P8HSHYKDCX3N8u+Vgw== +##LNzLEpGeC3fMu77Ro2k3hQ== +##L97HB5mLAnfMu77Ro2k3hQ== +##P8HPCZWEGmaZ7/K1 +##L8/UAdDXTlGDjpra7jFL9l/8S2skevm/trWyyYSy6/nQjCzXTZUDWmR4gSzuN0O4Vf4uZvYHvcEFRiEnPOEb57GeHv+sJQ== +##Kc/BRM3KXhU= +## +## +##fd6a9f26a06ea3bc99616d4851b372ba +# PowerShell + +$SCRIPT_PATH = $MyInvocation.MyCommand.Path +$IMAGE_NAME = "iprcnrs/msspec:latest" + +Function Read-YesNo($PROMPT, $DEFAULT) { + $VALID = 1 + While($VALID -ne 0) { + $ANSWER = Read-Host "$PROMPT (y/n) [$DEFAULT]? " + Switch($ANSWER) { + "" {$ANSWER=$DEFAULT; $VALID=0; Break} + "y" {$VALID=0; Break} + "n" {$VALID=0; Break} + Default {Write-Host "Invalid choice, please answer 'y' or 'n'."; $VALID=1; Break} + } + } + Return $ANSWER +} + +Function Get-MsSpecContainerID { + Return docker ps -a -q --filter ancestor=$IMAGE_NAME +} + +Function Get-MsSpecImageID { + Return docker images -q $IMAGE_NAME +} + +Function Add-MsSpecImage { + Write-Host "Pulling MsSpec image..."; + docker pull $IMAGE_NAME; + Write-Host "done." + $IID = Get-MsSpecImageID; + Return $IID; +} + +Function Add-MsSpecContainer { + $CID = Get-MsSpecContainerID + If($CID -eq $NULL) { + $IID = Get-MsSpecImageID + If($IID -eq $NULL) { + #Add-MsSpecImage; + } + Write-Host -nonewline "Creating the MsSpec container... " + $mydocuments = [environment]::GetFolderPath("mydocuments") + $drive = ($mydocuments -split ":",2)[0] + docker create -i -v ${drive}:\:/$drive --entrypoint /bin/bash $IMAGE_NAME >$NULL + $CID = Get-MsSpecContainerID + Write-Host "done." + } + Return $CID +} + +Function Start-MsSpecContainer { + $CID = Add-MsSpecContainer; + $status = docker container inspect -f '{{.State.Status}}' $CID; + IF($status -ne "running") { + Write-Host -nonewline "Starting MsSpec container..."; + $CID = docker start $CID; + Write-Host "done."; + } +} + +Function Remove-MsSpecContainer { + Write-Host -nonewline "Removing MsSpec container..."; + $CID = Get-MsSpecContainerID; + IF($CID -ne $NULL) { + docker stop -t 1 $CID >$NULL; + docker rm $CID >$NULL; + } + Write-Host "done." +} + +Function Run-MsSpec($opts) { + # Run msspec command + $CID = Get-MsSpecContainerID; + $nixPath = "/" + (${PWD} -replace "\\","/") -replace ":","" + docker exec -i -t -e DISPLAY=host.docker.internal:0 -w $nixPath $CID msspec $opts +} + +Function Run-Bash { + # Run bash + $CID = Get-MsSpecContainerID; + $nixPath = "/" + (${PWD} -replace "\\","/") -replace ":","" + docker exec -i -t -w $nixPath -e DISPLAY=host.docker.internal:0 $CID /bin/bash +} + +Function Uninstall-MsSpecImage { + $ANSWER = Read-YesNo "You are about to remove the MsSpec Docker image, its container and this script. Are you sure" "n" + Switch($ANSWER) { + "y" {Remove-MsSpecContainer; + Write-Host -nonewline "Removing $IMAGE_NAME..."; + $IID = Get-MsSpecImageID; + If($IID -ne $NULL) { + docker rmi $IMAGE_NAME >$NULL; + } + Write-Host "done."; +# Remove-Item $THIS_SCRIPT; + Break; + } + "n" {Write-Host "Uninstallation aborted."; Break} + } +} + +Function Show-Help { + Write-Host "Usage: 1) msspec -p [PYTHON OPTIONS] SCRIPT [ARGUMENTS...]" + Write-Host " 2) msspec [-l FILE | -i | -h]" + Write-Host " 3) msspec [bash | reset]" + Write-Host "" + Write-Host "Form (1) is used to launch a script" + Write-Host "Form (2) is used to load a hdf5 data file" + Write-Host "Form (3) is used to control the Docker container/image." + Write-Host "" + Write-Host "List of possible options:" + Write-Host " -p Pass every arguments after this option to the msspec" + Write-Host " virtual environment Python interpreter." + Write-Host " -i Run the interactive Python interpreter within msspec" + Write-Host " virtual environment." + Write-Host " -l Load and display a *.hdf5 data file in a graphical" + Write-Host " window." + Write-Host " -v Print the version." + Write-Host " -h Show this help message." + Write-Host "" + Write-Host " bash This command starts an interactive bash shell in the" + Write-Host " MsSpec container." + Write-Host " reset This command removes the MsSpec container (but not the" + Write-Host " image). Changes made in the container will be lost and" + Write-Host " any new call to msspec will recreate a new fresh container." +} + +Switch($args[0]) { + "reset" {Remove-MsSpecContainer; Break} + "bash" {Start-MsSpecContainer; Run-Bash; Break} + "-u" {Uninstall-MsSpecImage; Break} + "-h" {Start-MsSpecContainer; Show-Help; Break} + "" {Start-MsSpecContainer; Show-Help; Break} + Default {Start-MsSpecContainer; Run-MsSpec $args; Break} + pull {Add-MsSpecImage; Break} +} diff --git a/utils/dockerized/windows/msspec_setup.exe b/utils/dockerized/windows/msspec_setup.exe new file mode 100644 index 0000000..d95a82d Binary files /dev/null and b/utils/dockerized/windows/msspec_setup.exe differ