config: explicitly point to the sparkleshare private key in ssh config. Closes #396
This commit is contained in:
parent
bb1d277cb0
commit
20c6ac32d0
|
@ -89,6 +89,8 @@ namespace SparkleLib {
|
|||
} finally {
|
||||
Load (FullPath);
|
||||
}
|
||||
|
||||
ConfigureSSH ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,6 +153,52 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
private void ConfigureSSH ()
|
||||
{
|
||||
string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
|
||||
|
||||
if (!(SparkleBackend.Platform == PlatformID.Unix ||
|
||||
SparkleBackend.Platform == PlatformID.MacOSX)) {
|
||||
|
||||
path = Environment.ExpandEnvironmentVariables ("%HOMEDRIVE%%HOMEPATH%");
|
||||
}
|
||||
|
||||
string ssh_config_path = Path.Combine (path, ".ssh");
|
||||
string ssh_config_file_path = SparkleHelpers.CombineMore (path, ".ssh", "config");
|
||||
string ssh_config = "IdentityFile " +
|
||||
Path.Combine (SparkleConfig.ConfigPath, "sparkleshare." + User.Email + ".key\n");
|
||||
|
||||
if (!Directory.Exists (ssh_config_path))
|
||||
Directory.CreateDirectory (ssh_config_path);
|
||||
|
||||
if (File.Exists (ssh_config_file_path)) {
|
||||
string current_config = File.ReadAllText (ssh_config_file_path);
|
||||
if (current_config.Contains (ssh_config))
|
||||
return;
|
||||
|
||||
if (current_config.EndsWith ("\n\n"))
|
||||
ssh_config = "# SparkleShare's key\n" + ssh_config;
|
||||
else if (current_config.EndsWith ("\n"))
|
||||
ssh_config = "\n# SparkleShare's key\n" + ssh_config;
|
||||
else
|
||||
ssh_config = "\n\n# SparkleShare's key\n" + ssh_config;
|
||||
|
||||
TextWriter writer = File.AppendText (ssh_config_file_path);
|
||||
writer.Write (ssh_config);
|
||||
writer.Close ();
|
||||
|
||||
} else {
|
||||
File.WriteAllText (ssh_config_file_path, ssh_config);
|
||||
}
|
||||
|
||||
//UnixFileSystemInfo file_info = new UnixFileInfo (ssh_config_file_path);
|
||||
//file_info.FileAccessPermissions = (FileAccessPermissions.UserRead |
|
||||
// FileAccessPermissions.UserWrite); TODO
|
||||
|
||||
SparkleHelpers.DebugInfo ("Config", "Added key to " + ssh_config_file_path);
|
||||
}
|
||||
|
||||
|
||||
public List<string> Folders {
|
||||
get {
|
||||
List<string> folders = new List<string> ();
|
||||
|
|
|
@ -209,7 +209,7 @@ namespace SparkleLib {
|
|||
} else {
|
||||
File.WriteAllText (ssh_config_file_path, new_ssh_config.Trim ());
|
||||
|
||||
//UnixFileSystemInfo file_info = new UnixFileInfo (ssh_config_file_path);
|
||||
//UnixFileSystemInfo file_info = new UnixFileInfo (ssh_config_file_path);
|
||||
//file_info.FileAccessPermissions = (FileAccessPermissions.UserRead |
|
||||
// FileAccessPermissions.UserWrite); TODO
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue