1
0
mirror of https://github.com/akpaevj/executor-scripts.git synced 2025-07-14 06:44:20 +02:00
This commit is contained in:
akpaevj
2024-02-17 23:19:54 +03:00
parent 9fa293f1c0
commit 036cd2a6a3
21 changed files with 392 additions and 251 deletions

26
.vscode/launch.json vendored
View File

@ -10,13 +10,29 @@
"request": "launch",
"scriptFile": "${file}",
"args": [
"localhost",
"erp_dev",
"sa",
"1qazxsw@",
"erv_dev_test"
"8.3.23.2040",
"W228\\USR1CV8",
"N3Ak8bPu7",
"erp_main_extension_2765112a",
"C:\\Users\\akpaev.e\\Desktop\\erp-ibsrv-config.yml"
]
// "args": [
// "C:\\Users\\akpaev.e\\Desktop\\erp-ibsrv-config2.yml",
// "http.http-services.service.name",
// "testvalue"
// ]
// "args": [
// "update_extension.sbsl",
// "script.sbsl"
// ]
// "args": [
// "localhost",
// "erp_dev",
// "sa",
// "1qazxsw@",
// "erv_dev_test"
// ]
// "args": [
// "localhost",
// "erp_tehnogerm_test_update",
// "Администратор",

View File

@ -1,18 +1,20 @@
#required ProcessHelper.sbsl
#required V8Util.sbsl
#required Processes.sbsl
#required V8.sbsl
@Global
method UpdateConfiguration(
Platform: V8Util.V8Platform,
PlatformVersion: String,
Server: String,
Infobase: String,
User: String,
Password: String,
AccessCode: String,
CfuPath: String): Number
val Platform = V8.GetInstalledPlatform(PlatformVersion)
val OutFile = Files.CreateTempFile()
val args = [
val Args = [
"DESIGNER",
"/S${Server}\\${Infobase}",
"/N${User}",
@ -28,30 +30,16 @@ method UpdateConfiguration(
"-Server",
"-SessionTerminate force"
]
val Process = new OsProcess(Platform.ExecutablePath, args, True)
Process.Start()
ProcessHelper.WaitForCompletionAndReadOutput(Process)
Process.Stop()
var ExitCode = Process.GetExitCode()
if ExitCode > 0
Console.WriteError("Failed to update infobase (${ExitCode})")
else
Console.Write("${Infobase} is successfully updated")
;
val ExitCode = Processes.Run(Platform.ExecutablePath, Args)
RedirectOutToConsole(OutFile)
use OutputStream = OutFile.OpenReadableStream()
val OutputStreamText = OutputStream.ReadAsString()
if (OutputStreamText.Length() > 0)
Console.Write(OutputStreamText)
;
return Process.GetExitCode()
return ExitCode
;
@Global
method UpdateExtension(
Platform: V8Util.V8Platform,
PlatformVersion: String,
Server: String,
Infobase: String,
User: String,
@ -59,9 +47,11 @@ method UpdateExtension(
AccessCode: String,
ExtensionName: String,
ExtensionArchive: String): Number
val Platform = V8.GetInstalledPlatform(PlatformVersion)
val OutFile = Files.CreateTempFile()
val args = [
val Args = [
"DESIGNER",
"/S${Server}\\${Infobase}",
"/N${User}",
@ -78,23 +68,18 @@ method UpdateExtension(
"-Server",
"-SessionTerminate force"
]
val Process = new OsProcess(Platform.ExecutablePath, args, True)
Process.Start()
ProcessHelper.WaitForCompletionAndReadOutput(Process)
Process.Stop()
var ExitCode = Process.GetExitCode()
if ExitCode > 0
Console.WriteError("Failed to update extension ${ExtensionName} in ${Infobase}")
else
Console.Write("Extension \"${ExtensionName}\" in ${Infobase} is successfully updated")
val ExitCode = Processes.Run(Platform.ExecutablePath, Args)
RedirectOutToConsole(OutFile)
return ExitCode
;
method RedirectOutToConsole(OutFile: File)
use OutputStream = OutFile.OpenReadableStream()
val OutputStreamText = OutputStream.ReadAsString()
if (OutputStreamText.Length() > 0)
Console.Write(OutputStreamText)
;
val OutputStreamContent = OutputStream.ReadAsString()
return Process.GetExitCode()
if (OutputStreamContent.Length() > 0)
Console.Write(OutputStreamContent)
;
;

View File

@ -1,9 +1,9 @@
#required Helpers/V8Util.sbsl
#required IO.sbsl
#required Zip.sbsl
method Script(
method BuildXmlFiles(
CliPath: String,
ProjectPath: String): Number
if not IO.PathExists(CliPath)
Console.WriteError("Couldn't find edt cli executable by passed path")
return 1
@ -35,7 +35,7 @@ method Script(
Files.Delete(DataPath)
val ArchivePath = IO.JoinPath(new File(ProjectPath).Directory.Path, "${new File(ProjectPath).Name}.zip")
IO.ZipFolder(BuildPath, ArchivePath)
Zip.ZipFolder(BuildPath, ArchivePath)
Files.Delete(BuildPath)

View File

@ -1,62 +0,0 @@
@Global
method GetFileName(Path: String): String
return new File(Path).Name
;
@Global
method GetParentDirectory(Path: String): String
return new File(Path).Directory.Path
;
@Global
method JoinPath(path: String, path1: String): String
if path.EndsWith("\\") or path.EndsWith("//")
return path + path1
else
return path + Files.SeparatorSymbol + path1
;
;
@Global
method JoinPath(path: String, path1: String, path2: String): String
val result = JoinPath(path, path1)
return JoinPath(result, path2)
;
@Global
method JoinPath(path: String, path1: String, path2: String, path3: String): String
val result = JoinPath(path, path1, path2)
return JoinPath(result, path3)
;
@Global
method PathExists(path: String): Boolean
return new File(path).Exists()
;
@Global
method TempPath(): String
return ExecutionEnvironment.GetProperty("java.io.tmpdir")
;
@Global
method ZipFolder(Folder: File, ArchivePath: String)
val ArchiveFile = new File(ArchivePath)
var Writer = new ZipWriter(ArchiveFile.OpenWritableStream())
for F in Folder.Children
AddToZipArchive(Writer, F, Folder)
;
Writer.Write()
;
method AddToZipArchive(Writer: ZipWriter, Source: File, Folder: File)
if Source.IsFile()
Writer.Add(Source.OpenReadableStream(), Source.Path.Replace(Folder.Path, ""))
;
for F in Source.Children
AddToZipArchive(Writer, F, Folder)
;
;

View File

@ -1,18 +0,0 @@
@Global
method WaitForCompletionAndReadOutput(Process: OsProcess): Boolean
use ProcessOutputStream = Process.GetOutputStream()
while True
val ProcessOutputText = ProcessOutputStream.ReadAsString()
if (ProcessOutputText.Length() > 0)
Console.Write(ProcessOutputText)
;
if not Process.IsAlive()
break
;
;
return Process.WaitForCompletion()
;

58
IO.sbsl Normal file
View File

@ -0,0 +1,58 @@
@Global
method GetFileName(Path: String): String
return new File(Path).Name
;
@Global
method GetParentDirectory(Path: String): String
return new File(Path).Directory.Path
;
@Global
method JoinPath(Path: String, Path1: String): String
if Path.EndsWith("\\") or Path.EndsWith("/")
return Path + Path1
else
return Path + Files.SeparatorSymbol + Path1
;
;
@Global
method JoinPath(Path: String, Path1: String, Path2: String): String
val result = JoinPath(Path, Path1)
return JoinPath(result, Path2)
;
@Global
method JoinPath(Path: String, Path1: String, Path2: String, Path3: String): String
val result = JoinPath(Path, Path1, Path2)
return JoinPath(result, Path3)
;
@Global
method PathExists(Path: String): Boolean
return new File(Path).Exists()
;
@Global
method TempPath(): String
return ExecutionEnvironment.GetProperty("java.io.tmpdir")
;
@Global
method ReadFileToEnd(FilePath: String): String
val File = new File(FilePath)
use Stream = File.OpenReadableStream()
return Stream.ReadAsString()
;
@Global
method WriteTextToFile(FilePath: String, Content: String)
val File = new File(FilePath)
use Stream = File.OpenWritableStream()
Stream.Flush()
Stream.Write(Content)
;

77
Ibsrv.sbsl Normal file
View File

@ -0,0 +1,77 @@
#required IO.sbsl
#required V8.sbsl
#required Processes.sbsl
#required Services.sbsl
#required Yaml.sbsl
const SERVICE_NAME_TEMPLATE = "Standalone server"
const SERVICE_DESC_TEMPLATE = "Standalone server 1C:Enterprise 8.3"
@Global
method RegisterService(
PlatformVersion: String,
ServiceUser: String,
ServicePassword: String,
InstanceId: String,
TemplateConfigPath: String,
Port: Number = 8314,
DataPath: String = ""): Number
Processes.ThrowIfHasNoAdminRights()
val Platform = V8.GetInstalledPlatform(PlatformVersion)
V8.ThrowIfHasNoStandaloneServer(Platform)
if DataPath.Length() == 0
DataPath = GetServerDataPath(InstanceId)
;
val ServiceName = GetServiceName(InstanceId)
val ServiceDesc = GetServiceDescription(InstanceId)
val NewConfigPath = IO.JoinPath(IO.GetParentDirectory(TemplateConfigPath), "${InstanceId}.yaml")
Files.Copy(TemplateConfigPath, NewConfigPath)
Yaml.ReplaceValue(NewConfigPath, "infobase.name", InstanceId)
Yaml.ReplaceValue(NewConfigPath, "database.name", InstanceId)
Yaml.ReplaceValue(NewConfigPath, "server.port", Port.ToString().Replace(" ", ""))
val BinPath = GetServiceBinPath(Platform, NewConfigPath, DataPath)
return Services.Create(ServiceName, BinPath, ServiceUser, ServicePassword, ServiceDesc)
;
@Global
method StartService(InstanceId: String): Number
val ServiceName = GetServiceName(InstanceId)
return Services.Start(ServiceName, True)
;
@Global
method StopService(InstanceId: String): Number
val ServiceName = GetServiceName(InstanceId)
return Services.Stop(ServiceName, True)
;
@Global
method RemoveService(InstanceId: String): Number
val ServiceName = GetServiceName(InstanceId)
return Services.Remove(ServiceName, True)
;
method GetServerDataPath(InstanceId: String): String
return IO.JoinPath(ExecutionEnvironment.GetVariable("APPDATA"), "StandaloneService${Files.SeparatorSymbol}${InstanceId}")
;
method GetServiceBinPath(
Platform: V8.V8Platform,
ConfigPath: String,
DataPath: String = ""): String
return "\\\"${Platform.IbsrvPath}\\\" --service --data=\\\"${DataPath}\\\" --config=\\\"${ConfigPath}\\\""
;
method GetServiceName(InstanceId: String): String
return "${SERVICE_NAME_TEMPLATE} ${InstanceId}"
;
method GetServiceDescription(InstanceId: String): String
return "${SERVICE_DESC_TEMPLATE} (${InstanceId})"
;

91
Processes.sbsl Normal file
View File

@ -0,0 +1,91 @@
@Global
method Run(
Command: String,
Arguments: Array<String>,
RedirectOutputToConsole: Boolean = True,
LifeRedirect: Boolean = True,
WaitCompletion: Boolean = True,
OutputEncoding: Encoding = Encoding.Utf8): Number
val Process = new OsProcess(Command, Arguments)
return Run(Process, RedirectOutputToConsole, LifeRedirect, WaitCompletion, OutputEncoding)
;
@Global
method Run(
Process: OsProcess,
RedirectOutputToConsole: Boolean = True,
LifeRedirect: Boolean = True,
WaitCompletion: Boolean = True,
OutputEncoding: Encoding = Encoding.Utf8): Number
Process.Start()
if RedirectOutputToConsole and LifeRedirect
RedirectOutputWhileAlive(Process, OutputEncoding)
;
if WaitCompletion
Process.WaitForCompletion()
;
if RedirectOutputToConsole and not LifeRedirect
WriteOutputToConsole(Process, OutputEncoding)
;
if WaitCompletion
return Process.GetExitCode()
else
return 0
;
;
@Global
method RedirectOutputWhileAlive(Process: OsProcess, Encoding: Encoding = Encoding.Utf8)
use ProcessOutputStream = Process.GetOutputStream()
while True
val ProcessOutputText = ProcessOutputStream.ReadAsString(Encoding)
if (ProcessOutputText.Length() > 0)
Console.Write(ProcessOutputText)
;
if not Process.IsAlive()
break
;
;
;
@Global
method WriteOutputToConsole(Process: OsProcess, Encoding: Encoding = Encoding.Utf8)
val Output = GetProcessOutput(Process, Encoding)
Console.Write(Output)
;
@Global
method GetProcessOutput(Process: OsProcess, Encoding: Encoding = Encoding.Utf8): String
use ProcessOutputStream = Process.GetOutputStream()
return ProcessOutputStream.ReadAsString(Encoding)
;
@Global
method HasAdminRights(): Boolean
val Process = new OsProcess("net", ["session"])
Process.Start()
Process.WaitForCompletion()
use OutputStream = Process.GetOutputStream()
val Output = OutputStream.ReadAsString(Encoding.Cp866)
val HasNo = Output.Contains("Отказано в доступе") or Output.Contains("Access denied")
return not HasNo
;
@Global
method ThrowIfHasNoAdminRights()
val Has = HasAdminRights()
if not Has
throw new IllegalStateException("Current user doesn't have admin rights")
;
;

51
Services.sbsl Normal file
View File

@ -0,0 +1,51 @@
#required Processes.sbsl
@Global
enum ServiceStartMode
Disabled,
Auto
;
@Global
method Create(
ServiceName: String,
BinPath: String,
User: String,
Password: String,
ServiceDescription: String = "",
StartMode: ServiceStartMode = ServiceStartMode.Auto,
RedirectOutputToConsole: Boolean = True): Number
var Start = "auto"
if StartMode == ServiceStartMode.Disabled
Start = "disabled"
;
var Args = "/C sc create \"${ServiceName}\" binPath= \"${BinPath}\" start= ${Start} obj= ${User} password= ${Password}"
if ServiceDescription.Length() > 0
Args = "${Args} displayname= \"${ServiceDescription}\""
;
return Processes.Run("cmd", [Args], RedirectOutputToConsole = RedirectOutputToConsole, OutputEncoding = Encoding.Cp866)
;
@Global
method Start(ServiceName: String, RedirectOutputToConsole: Boolean = True): Number
return Processes.Run("cmd", ["/C sc start \"${ServiceName}\""], RedirectOutputToConsole = RedirectOutputToConsole, OutputEncoding = Encoding.Cp866)
;
@Global
method Stop(ServiceName: String, RedirectOutputToConsole: Boolean = True): Number
return Processes.Run("cmd", ["/C sc stop \"${ServiceName}\""], RedirectOutputToConsole = RedirectOutputToConsole, OutputEncoding = Encoding.Cp866)
;
@Global
method Remove(ServiceName: String, RedirectOutputToConsole: Boolean = True): Number
return Processes.Run("cmd", ["/C sc delete \"${ServiceName}\""], RedirectOutputToConsole = RedirectOutputToConsole, OutputEncoding = Encoding.Cp866)
;
@Global
method ServiceExists(ServiceName: String): Boolean
return Processes.Run("cmd", ["/C sc query \"${ServiceName}\""], RedirectOutputToConsole = False, OutputEncoding = Encoding.Cp866) == 0
;

View File

@ -17,6 +17,13 @@ method GetInstalledPlatforms(): Array<V8Platform>
item.BinPath = IO.JoinPath(children.Path, "bin")
item.ExecutablePath = IO.JoinPath(item.BinPath, "1cv8.exe")
val ibsrvExecutable = new File(IO.JoinPath(item.BinPath, "ibsrv.exe"))
if ibsrvExecutable.Exists()
item.HasStandaloneServer = True
item.IbsrvPath = ibsrvExecutable.Path
item.IbcmdPath = IO.JoinPath(item.BinPath, "ibcmd.exe")
;
Items.Add(item)
;
@ -34,7 +41,7 @@ method GetInstalledPlatform(Version: String = ""): V8Platform?
@Global
method GetHighestInstalledPlatform(): V8Platform?
val platforms = V8Util.GetInstalledPlatforms()
val platforms = V8.GetInstalledPlatforms()
return platforms.Last()
;
@ -71,10 +78,20 @@ method WaitSshAgentIsStarted(Port: Number = 1545, TimoutSeconds: Number): Boolea
return Net.LocalPortIsOpen(Port, TimoutSeconds)
;
@Global
method ThrowIfHasNoStandaloneServer(Platform: V8Platform)
if not Platform.HasStandaloneServer
throw new IllegalStateException("Platform installation doesn't contains standalone server executable")
;
;
@Global
structure V8Platform
var Version: String = ""
var Architecture: Arch = Arch.X64
var BinPath: String = ""
var ExecutablePath: String = ""
var HasStandaloneServer: Boolean = False
var IbsrvPath: String = ""
var IbcmdPath: String = ""
;

26
Yaml.sbsl Normal file
View File

@ -0,0 +1,26 @@
#required IO.sbsl
@Global
method ReplaceValue(FilePath: String, KeyPath: String, Value: String)
var FileContent = IO.ReadFileToEnd(FilePath)
var PathParts = KeyPath.Split(".")
var IndexInContent = 0
for Index = 0 to PathParts.Bound()
if (Index == PathParts.Bound())
break
;
val Part = PathParts[Index]
val ToFindSpan = "${Part}:"
IndexInContent = FileContent.Find("${ToFindSpan}", IndexInContent)
;
val ToFindSpan = "${PathParts[PathParts.Bound()]}:"
val LastPartStartIndex = FileContent.Find(ToFindSpan, IndexInContent)
val LastPartEndIndex = FileContent.Find("\n", LastPartStartIndex)
var NewData = "${ToFindSpan} ${Value}"
FileContent = FileContent.ReplaceRange(NewData, LastPartStartIndex, LastPartEndIndex)
IO.WriteTextToFile(FilePath, FileContent)
;

21
Zip.sbsl Normal file
View File

@ -0,0 +1,21 @@
@Global
method ZipFolder(Folder: File, ArchivePath: String)
val ArchiveFile = new File(ArchivePath)
var Writer = new ZipWriter(ArchiveFile.OpenWritableStream())
for F in Folder.Children
AddToZipArchive(Writer, F, Folder)
;
Writer.Write()
;
method AddToZipArchive(Writer: ZipWriter, Source: File, Folder: File)
if Source.IsFile()
Writer.Add(Source.OpenReadableStream(), Source.Path.Replace(Folder.Path, ""))
;
for F in Source.Children
AddToZipArchive(Writer, F, Folder)
;
;

View File

@ -1,28 +0,0 @@
#required Helpers/Ras.sbsl
method Script(
Infobases: String,
User: String,
Password: String,
AccessPort: String,
RasAddress = "localhost",
RasPort = 1545): Number
for i in Infobases.Split(",")
try
Ras.BlockConnections(
i,
User,
Password,
AccessPort,
RasAddress,
RasPort)
Console.Write("Connections to ${i} are successfully blocked and terminated")
catch Exception: unknown
Console.WriteError("Failed to block connections to ${i}")
;
;
return 0
;

View File

@ -1,14 +0,0 @@
#required Helpers/SqlUtil.sbsl
method Script(
Server: String,
Database: String,
User: String,
Password: String,
NewDatabaseName: String)
try
SqlUtil.CreateDatabaseFromLastBackup(Server, Database, User, Password, NewDatabaseName)
catch Exception: unknown
Console.WriteError("Failed to restore database ${NewDatabaseName} from ${Database} backup: ${Exception.ToString()}")
;
;

View File

@ -1,25 +0,0 @@
#required Helpers/Ras.sbsl
method Script(
Infobases: String,
User: String,
Password: String,
RasAddress = "localhost",
RasPort = 1545): Number
for i in Infobases.Split(",")
try
Ras.UnblockConnections(
i,
User,
Password, RasAddress,
RasPort)
Console.Write("Connections to ${i} are successfully unblocked")
catch Exception: unknown
Console.WriteError("Failed to unblock connections to ${i}")
;
;
return 0
;

View File

@ -1,26 +0,0 @@
#required Helpers/V8Util.sbsl
#required Helpers/BatchMode.sbsl
#required Helpers/Ras.sbsl
method Script(
Server: String,
Infobases: String,
User: String,
Password: String,
AccessCode: String,
CfuPath: String,
PlatfromVersion = "")
val installedPlatform = V8Util.GetInstalledPlatform(PlatfromVersion)
for i in Infobases.Split(",")
BatchMode.UpdateConfiguration(
installedPlatform,
Server,
i,
User,
Password,
AccessCode,
CfuPath)
;
;

View File

@ -1,28 +0,0 @@
#required Helpers/V8Util.sbsl
#required Helpers/BatchMode.sbsl
#required Helpers/Ras.sbsl
method Script(
Server: String,
Infobases: String,
User: String,
Password: String,
AccessCode: String,
ExtensionName: String,
ExtensionArchive: String,
PlatfromVersion = "")
val installedPlatform = V8Util.GetInstalledPlatform(PlatfromVersion)
for i in Infobases.Split(",")
BatchMode.UpdateExtension(
installedPlatform,
Server,
i,
User,
Password,
AccessCode,
ExtensionName,
ExtensionArchive)
;
;