提交 afdbb776 编写于 作者: T tanghai

增加Rsync同步配置工具

上级 99a0005e
1234567890
\ No newline at end of file
{ "_t" : "RsyncConfig", "Host" : "192.168.12.188", "Account" : "tanghai", "Password" : "1234567890", "RelativePath" : "Source/Egametang", "Exclude" : [".git/", "Log/", "Tools/", "Server/Bin/", "Server/packages/", "Server/Temp/", "Server/Server.sdf", "Unity/Library/", "Unity/Temp/", "*/obj"] }
\ No newline at end of file
uid = root
gid = root
#strict modes = no
use chroot = no
max connections = 100
read only = no
write only = no
log file=/var/log/rsyncd.log
# Remote sync configuration module
[Tanghai]
log file =/var/log/rsyncd.log
[Upload]
path = /home/tanghai/
auth users = tanghai
secrets file = /etc/rsyncd.secrets
......
tanghai:1234567890
\ No newline at end of file
123456
\ No newline at end of file
using System.Collections.Generic;
namespace MyEditor
{
public class RsyncConfig
{
public string Host = "";
public string Account = "";
public string Password = "";
public string RelativePath = "";
public List<string> Exclude = new List<string>();
}
}
fileFormatVersion: 2
guid: 09fcb878a3792c84fb09f0c0f1ef2572
timeCreated: 1477277139
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using Base;
using UnityEditor;
using UnityEngine;
namespace MyEditor
{
public class RsyncEditor : EditorWindow
{
[MenuItem("Tools/同步到Linux")]
private static void ShowUnDisposeObjects()
private const string ConfigFile = @"..\Config\Rsync\rsyncConfig.txt";
private RsyncConfig rsyncConfig;
private bool isFold = true;
[MenuItem("Tools/Rsync同步")]
private static void ShowWindow()
{
GetWindow(typeof(RsyncEditor));
}
[MenuItem("Tools/Rsync同步")]
private static void ShowTool()
{
GetWindow(typeof(RsyncEditor));
}
private void OnEnable()
{
if (!File.Exists(ConfigFile))
{
this.rsyncConfig = new RsyncConfig();
return;
}
string s = File.ReadAllText(ConfigFile);
this.rsyncConfig = MongoHelper.FromJson<RsyncConfig>(s);
}
private void OnGUI()
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"Tools\cwRsync\rsync.exe";
startInfo.Arguments = "-vzrtopg --password-file=./Tools/cwRsync/rsync.secrets --exclude-from=./Tools/cwRsync/exclude.txt --delete ./ tanghai@192.168.1.134::Tanghai/Source/Egametang --chmod=ugo=rwX";
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = @"..\";
Process p = Process.Start(startInfo);
p.WaitForExit();
Log.Info("同步完成!");
rsyncConfig.Host = EditorGUILayout.TextField("服务器地址", rsyncConfig.Host);
rsyncConfig.Account = EditorGUILayout.TextField("账号(必须是Linux已有的账号)", rsyncConfig.Account);
rsyncConfig.Password = EditorGUILayout.TextField("密码", rsyncConfig.Password);
rsyncConfig.RelativePath = EditorGUILayout.TextField("相对路径", rsyncConfig.RelativePath);
if (GUILayout.Button("添加排除项目"))
{
this.rsyncConfig.Exclude.Add("");
}
this.isFold = EditorGUILayout.Foldout(isFold, $"排除列表:");
if (!this.isFold)
{
for (int i = 0; i < this.rsyncConfig.Exclude.Count; ++i)
{
GUILayout.BeginHorizontal();
this.rsyncConfig.Exclude[i] = EditorGUILayout.TextField(this.rsyncConfig.Exclude[i]);
if (GUILayout.Button("删除"))
{
this.rsyncConfig.Exclude.RemoveAt(i);
break;
}
GUILayout.EndHorizontal();
}
}
if (GUILayout.Button("保存"))
{
File.WriteAllText(ConfigFile, MongoHelper.ToJson(this.rsyncConfig));
using (StreamWriter sw = new StreamWriter(new FileStream(@"..\Config\Rsync\rsync.secrets", FileMode.Create)))
{
foreach (string s in this.rsyncConfig.Exclude)
{
sw.Write(s + "\n");
}
}
File.WriteAllText($@"..\Config\Rsync\rsync.secrets", this.rsyncConfig.Password);
File.WriteAllText($@"..\Config\Rsync\rsyncd.secrets", $"{this.rsyncConfig.Account}:{this.rsyncConfig.Password}");
string rsyncdConf =
"uid = root\n" +
"gid = root\n" +
"use chroot = no\n" +
"max connections = 100\n" +
"read only = no\n" +
"write only = no\n" +
"log file =/var/log/rsyncd.log\n" +
"[Upload]\n" +
$"path = /home/{this.rsyncConfig.Account}/\n" +
$"auth users = {this.rsyncConfig.Account}\n" +
"secrets file = /etc/rsyncd.secrets\n" +
"list = yes";
File.WriteAllText($@"..\Config\Rsync\rsyncd.conf", rsyncdConf);
}
if (GUILayout.Button("同步"))
{
string arguments = $"-vzrtopg --password-file=./Config/Rsync/rsync.secrets --exclude-from=./Config/Rsync/exclude.txt --delete ./ {this.rsyncConfig.Account}@{this.rsyncConfig.Host}::Upload/{this.rsyncConfig.RelativePath} --chmod=ugo=rwX";
Log.Debug(arguments);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @".\Tools\cwRsync\rsync.exe";
startInfo.Arguments = arguments;
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = @"..\";
Process p = Process.Start(startInfo);
p.WaitForExit();
Log.Info("同步完成!");
}
}
}
}
fileFormatVersion: 2
guid: 24f0b40b39c2f954d9e5e63bbb17f3d6
folderAsset: yes
timeCreated: 1476673759
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -116,6 +116,7 @@
<Compile Include="Assets\Editor\EditorInit.cs" />
<Compile Include="Assets\Editor\ObjectManagerToolsEditor\ObjectManagerToolsWindow.cs" />
<Compile Include="Assets\Editor\ReferenceCollectorEditor\ReferenceCollectorEditor.cs" />
<Compile Include="Assets\Editor\RsyncEditor\RsyncConfig.cs" />
<Compile Include="Assets\Editor\RsyncEditor\RsyncEditor.cs" />
<Compile Include="Assets\Editor\ServerCommandLineEditor\ServerCommandLineEditor.cs" />
</ItemGroup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册