You've already forked akpaevj-executor-scripts
mirror of
https://github.com/akpaevj/executor-scripts.git
synced 2025-07-17 07:12:23 +02:00
Init
This commit is contained in:
40
.vscode/launch.json
vendored
Normal file
40
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Executor",
|
||||
"type": "sbsl",
|
||||
"request": "launch",
|
||||
"scriptFile": "${file}",
|
||||
"args": [
|
||||
"localhost",
|
||||
"erp_tehnogerm_test_update",
|
||||
"Администратор",
|
||||
"zNrtZ5jb",
|
||||
"12345",
|
||||
"C:\\Users\\akpaev.e\\AppData\\Roaming\\1C\\1cv8\\tmplts\\1c\\Enterprise20\\2_5_15_65\\1cv8.cfu",
|
||||
"8.3.23.2040"
|
||||
]
|
||||
// "args": [
|
||||
// "C:\\Users\\akpaev.e\\git\\erp-main-extension.zip",
|
||||
// "localhost",
|
||||
// "erp_dev",
|
||||
// "Администратор",
|
||||
// "zNrtZ5jb",
|
||||
// "8.3.23.2040"
|
||||
// ]
|
||||
// "args": [
|
||||
// "erp_dev",
|
||||
// "Администратор",
|
||||
// "zNrtZ5jb",
|
||||
// ]
|
||||
// "args": [
|
||||
// "C:\\Users\\akpaev.e\\AppData\\Local\\1C\\1cedtstart\\installations\\1C_EDT 2023.3_\\1cedt\\1cedtcli.exe",
|
||||
// "C:\\Users\\akpaev.e\\git\\erp-main-extension"
|
||||
// ]
|
||||
}
|
||||
]
|
||||
}
|
48
Helpers/BatchMode.sbsl
Normal file
48
Helpers/BatchMode.sbsl
Normal file
@ -0,0 +1,48 @@
|
||||
#required ProcessHelper.sbsl
|
||||
#required V8Util.sbsl
|
||||
|
||||
@Global
|
||||
method UpdateConfiguration(
|
||||
Platform: V8Util.V8Platform,
|
||||
Server: String,
|
||||
Infobase: String,
|
||||
User: String,
|
||||
Password: String,
|
||||
AccessCode: String,
|
||||
CfuPath: String): Number
|
||||
val OutFile = Files.CreateTempFile()
|
||||
|
||||
val args = [
|
||||
"DESIGNER",
|
||||
"/S${Server}\\${Infobase}",
|
||||
"/N${User}",
|
||||
"/P${Password}",
|
||||
"/DisableStartupMessages",
|
||||
"/DisableStartupDialogs",
|
||||
"/Out\"${OutFile}\"",
|
||||
"/UC${AccessCode}",
|
||||
"/UpdateCfg\"${CfuPath}\"",
|
||||
"-force",
|
||||
"/UpdateDBCfg",
|
||||
"-Dynamic-",
|
||||
"-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})")
|
||||
;
|
||||
|
||||
use OutputStream = OutFile.OpenReadableStream()
|
||||
val OutputStreamText = OutputStream.ReadAsString()
|
||||
if (OutputStreamText.Length() > 0)
|
||||
Console.Write(OutputStreamText)
|
||||
;
|
||||
|
||||
return Process.GetExitCode()
|
||||
;
|
52
Helpers/IO.sbsl
Normal file
52
Helpers/IO.sbsl
Normal file
@ -0,0 +1,52 @@
|
||||
@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)
|
||||
;
|
||||
;
|
27
Helpers/Net.sbsl
Normal file
27
Helpers/Net.sbsl
Normal file
@ -0,0 +1,27 @@
|
||||
@Global
|
||||
method LocalPortIsOpen(Port: Number, TimeoutSeconds: Number): Boolean
|
||||
val Args = [
|
||||
"/c",
|
||||
"netstat -a | find \":${Port.ToString().Replace(" ", "")}\""
|
||||
]
|
||||
val Process = new OsProcess("cmd.exe", Args)
|
||||
Process.Start()
|
||||
use Output = Process.GetOutputStream()
|
||||
|
||||
val FinishTimestamp = DateTime.Now().AddSeconds(TimeoutSeconds)
|
||||
|
||||
while DateTime.Now() < FinishTimestamp
|
||||
Pause(Duration.OfMilliseconds(100))
|
||||
|
||||
val Text = Output.ReadAsString()
|
||||
|
||||
if Text.Length() > 0
|
||||
Process.Stop()
|
||||
return True
|
||||
;
|
||||
;
|
||||
|
||||
Process.Stop()
|
||||
|
||||
return False
|
||||
;
|
18
Helpers/ProcessHelper.sbsl
Normal file
18
Helpers/ProcessHelper.sbsl
Normal file
@ -0,0 +1,18 @@
|
||||
@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()
|
||||
;
|
59
Helpers/Ras.sbsl
Normal file
59
Helpers/Ras.sbsl
Normal file
@ -0,0 +1,59 @@
|
||||
@Global
|
||||
method BlockConnections(
|
||||
Infobase: String,
|
||||
User: String,
|
||||
Password: String,
|
||||
AccessCode: String,
|
||||
RasAddress = "localhost",
|
||||
RasPort = 1545)
|
||||
use administration = new V8ServerAdministration(RasAddress, RasPort)
|
||||
administration.Authenticate()
|
||||
|
||||
val cluster = administration.GetClusters().FirstOrDefault()
|
||||
cluster.Authenticate()
|
||||
|
||||
val infobaseDescription = cluster.GetInfobases().Filter(c -> c.Name.ToLowerCase() == Infobase.Trim().ToLowerCase()).FirstOrDefault()
|
||||
val ib = infobaseDescription.Authenticate(User, Password)
|
||||
|
||||
val beginTimestamp = DateTime.Now()
|
||||
ib.LockBeginTime = beginTimestamp.ToInstant(TimeZone.Current())
|
||||
|
||||
ib.LockMessage = "Технические работы"
|
||||
ib.SessionStartPermissionCode = AccessCode
|
||||
ib.LockScheduledJobs = True
|
||||
ib.SessionsLockEnabled = True
|
||||
ib.Write()
|
||||
|
||||
ib.GetConnections()
|
||||
.Filter(c -> c.ApplicationName.ToUpperCase() != "RAS")
|
||||
.ForEach(c -> CloseConnection(c))
|
||||
;
|
||||
|
||||
method CloseConnection(Connection: V8Connection)
|
||||
try
|
||||
Connection.Disconnect()
|
||||
catch Exception: unknown
|
||||
|
||||
;
|
||||
;
|
||||
|
||||
@Global
|
||||
method UnblockConnections(
|
||||
Infobase: String,
|
||||
User: String,
|
||||
Password: String,
|
||||
RasAddress = "localhost",
|
||||
RasPort = 1545)
|
||||
use administration = new V8ServerAdministration(RasAddress, RasPort)
|
||||
administration.Authenticate()
|
||||
|
||||
val cluster = administration.GetClusters().FirstOrDefault()
|
||||
cluster.Authenticate()
|
||||
|
||||
val infobaseDescription = cluster.GetInfobases().Filter(c -> c.Name.ToLowerCase() == Infobase.Trim().ToLowerCase()).FirstOrDefault()
|
||||
val ib = infobaseDescription.Authenticate(User, Password)
|
||||
|
||||
ib.LockScheduledJobs = False
|
||||
ib.SessionsLockEnabled = False
|
||||
ib.Write()
|
||||
;
|
43
Helpers/SshAgentConnection.sbsl
Normal file
43
Helpers/SshAgentConnection.sbsl
Normal file
@ -0,0 +1,43 @@
|
||||
@Global
|
||||
method Open(
|
||||
Address: String,
|
||||
Port: Number,
|
||||
User: String,
|
||||
Password: String): SshConnection
|
||||
return new SshConnection(Address, Port, User, Password)
|
||||
;
|
||||
|
||||
@Global
|
||||
method ConnectIB(Connection: SshConnection)
|
||||
Connection.Execute("common connect-ib")
|
||||
;
|
||||
|
||||
@Global
|
||||
method LoadFile(
|
||||
Address: String,
|
||||
Port: Number,
|
||||
User: String,
|
||||
Password: String,
|
||||
FilePath: String)
|
||||
use ssh = new SshConnection(Address, Port, User, Password)
|
||||
use Sftp = ssh.OpenSftpConnection()
|
||||
|
||||
Sftp.SetCurrentDirectory("/")
|
||||
Sftp.Put(FilePath)
|
||||
Sftp.Close()
|
||||
;
|
||||
|
||||
@Global
|
||||
method DisconnectIB(Connection: SshConnection)
|
||||
Connection.Execute("common diconnect-ib")
|
||||
;
|
||||
|
||||
@Global
|
||||
method Shutdown(Connection: SshConnection)
|
||||
Connection.Execute("common shutdown")
|
||||
;
|
||||
|
||||
@Global
|
||||
method Close(Connection: SshConnection)
|
||||
Connection.Close()
|
||||
;
|
80
Helpers/V8Util.sbsl
Normal file
80
Helpers/V8Util.sbsl
Normal file
@ -0,0 +1,80 @@
|
||||
#required IO.sbsl
|
||||
#required Net.sbsl
|
||||
|
||||
@Global
|
||||
method GetInstalledPlatforms(): Array<V8Platform>
|
||||
val Items = new Array<V8Platform>()
|
||||
|
||||
val onecRootFolder = new File("1cv8", ExecutionEnvironment.GetVariable("ProgramFiles"))
|
||||
|
||||
val pattern = new Pattern("\\d+\\.\\d+\\.\\d+\\.\\d+")
|
||||
val platfromPaths = onecRootFolder.Children.Filter(c -> pattern.FindMatches(c.Name, 1).Size() > 0)
|
||||
|
||||
for children in platfromPaths
|
||||
val item = new V8Platform()
|
||||
item.Version = children.Name
|
||||
item.Architecture = Arch.X64
|
||||
item.BinPath = IO.JoinPath(children.Path, "bin")
|
||||
item.ExecutablePath = IO.JoinPath(item.BinPath, "1cv8.exe")
|
||||
|
||||
Items.Add(item)
|
||||
;
|
||||
|
||||
return Items.SortBy(c -> c.Version)
|
||||
;
|
||||
|
||||
@Global
|
||||
method GetInstalledPlatform(Version: String = ""): V8Platform?
|
||||
if Version == ""
|
||||
return GetHighestInstalledPlatform()
|
||||
else
|
||||
return GetInstalledPlatforms().Filter(c -> c.Version == Version).Last()
|
||||
;
|
||||
;
|
||||
|
||||
@Global
|
||||
method GetHighestInstalledPlatform(): V8Platform?
|
||||
val platforms = V8Util.GetInstalledPlatforms()
|
||||
return platforms.Last()
|
||||
;
|
||||
|
||||
@Global
|
||||
enum Arch
|
||||
X86,
|
||||
X64
|
||||
;
|
||||
|
||||
@Global
|
||||
method StartSshAgent(
|
||||
InstalledPlatform: V8Platform,
|
||||
Server: String,
|
||||
Infobase: String,
|
||||
AgentBaseBir: File,
|
||||
Port: Number = 1545): OsProcess
|
||||
val args = [
|
||||
"DESIGNER",
|
||||
"/S ${Server}",
|
||||
"/IBName ${Infobase}",
|
||||
"/AgentMode",
|
||||
"/AgentPort ${Port.ToString().Replace(" ", "")}",
|
||||
"/AgentSSHHostKeyAuto",
|
||||
"/AgentBaseDir ${AgentBaseBir.Path}"
|
||||
]
|
||||
val Process = new OsProcess(InstalledPlatform.ExecutablePath, args, True)
|
||||
Process.Start()
|
||||
|
||||
return Process
|
||||
;
|
||||
|
||||
@Global
|
||||
method WaitSshAgentIsStarted(Port: Number = 1545, TimoutSeconds: Number): Boolean
|
||||
return Net.LocalPortIsOpen(Port, TimoutSeconds)
|
||||
;
|
||||
|
||||
@Global
|
||||
structure V8Platform
|
||||
var Version: String = ""
|
||||
var Architecture: Arch = Arch.X64
|
||||
var BinPath: String = ""
|
||||
var ExecutablePath: String = ""
|
||||
;
|
27
block_connections.sbsl
Normal file
27
block_connections.sbsl
Normal file
@ -0,0 +1,27 @@
|
||||
#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
|
||||
;
|
43
build_xml_files.sbsl
Normal file
43
build_xml_files.sbsl
Normal file
@ -0,0 +1,43 @@
|
||||
#required Helpers/V8Util.sbsl
|
||||
|
||||
method Script(
|
||||
CliPath: String,
|
||||
ProjectPath: String): Number
|
||||
|
||||
if not IO.PathExists(CliPath)
|
||||
Console.WriteError("Couldn't find edt cli executable by passed path")
|
||||
return 1
|
||||
;
|
||||
|
||||
if not IO.PathExists(ProjectPath)
|
||||
Console.WriteError("Couldn't find project folder by passed path")
|
||||
return 1
|
||||
;
|
||||
|
||||
val DataPath = Files.CreateTempDirectory()
|
||||
val BuildPath = Files.CreateTempDirectory()
|
||||
|
||||
val args = [
|
||||
"-data",
|
||||
DataPath,
|
||||
"-command",
|
||||
"export",
|
||||
"--project",
|
||||
ProjectPath,
|
||||
"--configuration-files",
|
||||
BuildPath
|
||||
]
|
||||
|
||||
val edtCli = new OsProcess(CliPath, args, True)
|
||||
edtCli.Start()
|
||||
edtCli.WaitForCompletion()
|
||||
|
||||
Files.Delete(DataPath)
|
||||
|
||||
val ArchivePath = IO.JoinPath(new File(ProjectPath).Directory.Path, "${new File(ProjectPath).Name}.zip")
|
||||
IO.ZipFolder(BuildPath, ArchivePath)
|
||||
|
||||
Files.Delete(BuildPath)
|
||||
|
||||
return edtCli.GetExitCode()
|
||||
;
|
25
unblock_connections.sbsl
Normal file
25
unblock_connections.sbsl
Normal file
@ -0,0 +1,25 @@
|
||||
#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
|
||||
;
|
49
update_configuration.sbsl
Normal file
49
update_configuration.sbsl
Normal file
@ -0,0 +1,49 @@
|
||||
#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(",")
|
||||
Console.Write("Processing \"${i}\"")
|
||||
|
||||
Console.Write("Blocking connections")
|
||||
|
||||
Ras.BlockConnections(
|
||||
i,
|
||||
User,
|
||||
Password,
|
||||
AccessCode,
|
||||
Server)
|
||||
|
||||
Console.Write("Updating infobase")
|
||||
|
||||
BatchMode.UpdateConfiguration(
|
||||
installedPlatform,
|
||||
Server,
|
||||
i,
|
||||
User,
|
||||
Password,
|
||||
AccessCode,
|
||||
CfuPath)
|
||||
|
||||
Console.Write("Unblocking connections")
|
||||
|
||||
Ras.UnblockConnections(
|
||||
i,
|
||||
User,
|
||||
Password,
|
||||
Server)
|
||||
|
||||
Console.Write("Processing is finished")
|
||||
;
|
||||
;
|
38
update_extension.sbsl
Normal file
38
update_extension.sbsl
Normal file
@ -0,0 +1,38 @@
|
||||
#required Helpers/V8Util.sbsl
|
||||
#required Helpers/SshAgentConnection.sbsl
|
||||
|
||||
method Script(
|
||||
ExtensionArchivePath: String,
|
||||
Server: String,
|
||||
Infobases: String,
|
||||
User: String,
|
||||
Password: String,
|
||||
PlatfromVersion = "")
|
||||
val installedPlatform = PlatfromVersion == "" ? V8Util.GetHighestInstalledPlatform() : V8Util.GetInstalledPlatform("8.3.23.2040")
|
||||
|
||||
var startPort = 10000
|
||||
|
||||
for i in Infobases.Split(",")
|
||||
val agentBaseDir = Files.CreateTempDirectory()
|
||||
|
||||
val agentProcess = V8Util.StartSshAgent(
|
||||
installedPlatform,
|
||||
Server,
|
||||
i,
|
||||
agentBaseDir,
|
||||
startPort
|
||||
)
|
||||
|
||||
V8Util.WaitSshAgentIsStarted(startPort, 10)
|
||||
|
||||
// SshAgentConnection.LoadExtensionFiles("localhost", startPort, User, Password, ExtensionArchivePath)
|
||||
|
||||
use connection = SshAgentConnection.Open("localhost", startPort, User, Password)
|
||||
SshAgentConnection.ConnectIB(connection)
|
||||
|
||||
SshAgentConnection.Shutdown(connection)
|
||||
SshAgentConnection.Close(connection)
|
||||
|
||||
agentProcess.Stop()
|
||||
;
|
||||
;
|
Reference in New Issue
Block a user