Ejemplo n.º 1
0
 static void WriteScriptModules(VariableDictionary variables, StringBuilder output)
 {
     foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
     {
         var name = "Library_" + new string(SpecialVariables.GetLibraryScriptModuleName(variableName).Where(char.IsLetterOrDigit).ToArray()) + "_" + DateTime.Now.Ticks;
         output.Append("New-Module -Name ").Append(name).Append(" -ScriptBlock {");
         output.AppendLine(variables.Get(variableName));
         output.AppendLine("} | Import-Module");
         output.AppendLine();
     }
 }
Ejemplo n.º 2
0
 static void WriteScriptModules(VariableDictionary variables, string parentDirectory, StringBuilder output)
 {
     foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
     {
         var name           = "Library_" + new string(SpecialVariables.GetLibraryScriptModuleName(variableName).Where(char.IsLetterOrDigit).ToArray()) + "_" + DateTime.Now.Ticks;
         var moduleFileName = $"{name}.psm1";
         var moduleFilePath = Path.Combine(parentDirectory, moduleFileName);
         CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), Encoding.UTF8);
         output.AppendLine($"Import-ScriptModule '{SpecialVariables.GetLibraryScriptModuleName(variableName).EscapeSingleQuotedString()}' '{moduleFilePath.EscapeSingleQuotedString()}'");
         output.AppendLine();
     }
 }
Ejemplo n.º 3
0
 static IEnumerable <string> PrepareScriptModules(VariableDictionary variables, string workingDirectory)
 {
     foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
     {
         if (SpecialVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.FSharp)
         {
             var libraryScriptModuleName = SpecialVariables.GetLibraryScriptModuleName(variableName);
             var name           = new string(libraryScriptModuleName.Where(char.IsLetterOrDigit).ToArray());
             var moduleFileName = $"{name}.fsx";
             var moduleFilePath = Path.Combine(workingDirectory, moduleFileName);
             Log.VerboseFormat("Writing script module '{0}' as f# module {1}. Import this module via `#load \"{1}\"`.", libraryScriptModuleName, moduleFileName, name);
             CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), Encoding.UTF8);
             yield return(moduleFileName);
         }
     }
 }
Ejemplo n.º 4
0
 static IEnumerable <string> PrepareScriptModules(IVariables variables, string workingDirectory)
 {
     foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
     {
         if (SpecialVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.Python)
         {
             var libraryScriptModuleName = SpecialVariables.GetLibraryScriptModuleName(variableName);
             var name           = new string(libraryScriptModuleName.Where(x => char.IsLetterOrDigit(x) || x == '_').ToArray());
             var moduleFileName = $"{name}.py";
             Log.VerboseFormat("Writing script module '{0}' as python module {1}. Import this module via `import {2}`.", libraryScriptModuleName, moduleFileName, name);
             var moduleFilePath = Path.Combine(workingDirectory, moduleFileName);
             CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), Encoding.UTF8);
             yield return(name);
         }
     }
 }
Ejemplo n.º 5
0
 static IEnumerable <string> PrepareScriptModules(IVariables variables, string workingDirectory)
 {
     foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
     {
         if (SpecialVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.Bash)
         {
             var libraryScriptModuleName = SpecialVariables.GetLibraryScriptModuleName(variableName);
             var name           = new string(libraryScriptModuleName.Where(char.IsLetterOrDigit).ToArray());
             var moduleFileName = $"{name}.sh";
             var moduleFilePath = Path.Combine(workingDirectory, moduleFileName);
             Log.VerboseFormat("Writing script module '{0}' as bash script {1}. Import this via `source {1}`.", libraryScriptModuleName, moduleFileName, name);
             Encoding utf8WithoutBom = new UTF8Encoding(false);
             CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), utf8WithoutBom);
             EnsureValidUnixFile(moduleFilePath);
             yield return(moduleFilePath);
         }
     }
 }
Ejemplo n.º 6
0
        static string[] WriteScriptModules(VariableDictionary variables, string parentDirectory, StringBuilder output)
        {
            var scriptModules = new List <string>();

            foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
            {
                if (SpecialVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.PowerShell)
                {
                    var libraryScriptModuleName = SpecialVariables.GetLibraryScriptModuleName(variableName);
                    var name           = "Library_" + new string(libraryScriptModuleName.Where(char.IsLetterOrDigit).ToArray()) + "_" + DateTime.Now.Ticks;
                    var moduleFileName = $"{name}.psm1";
                    var moduleFilePath = Path.Combine(parentDirectory, moduleFileName);
                    Log.VerboseFormat("Writing script module '{0}' as PowerShell module {1}. This module will be automatically imported - functions will automatically be in scope.", libraryScriptModuleName, moduleFileName, name);
                    CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), Encoding.UTF8);
                    output.AppendLine($"Import-ScriptModule '{libraryScriptModuleName.EscapeSingleQuotedString()}' '{moduleFilePath.EscapeSingleQuotedString()}'");
                    output.AppendLine();
                    scriptModules.Add(moduleFilePath);
                }
            }

            return(scriptModules.ToArray());
        }