Created
March 27, 2019 15:27
-
-
Save anyuser/4a8fd7c487aa653e0272c28ca2da7949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
public class MacosKeychain | |
{ | |
public static string GetKeychainPassword(string accountName,string serviceName) | |
{ | |
var value = ShellHelper.Bash($"security find-generic-password -a {accountName} -s {serviceName} -w -g"); | |
return value.TrimEnd( '\r', '\n' ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo | |
echo "Change android keystore passwords in keychain" | |
echo | |
echo "Enter keystore password" | |
security add-generic-password -U -T "" -a unity_android_keystore_password -s unity_android_keystore -w | |
echo | |
echo "Enter keyalias password" | |
security add-generic-password -U -T "" -a unity_android_keyalias_password -s unity_android_keyalias -w | |
echo "keychain passwords changed!" | |
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEditor.Build; | |
using UnityEditor.Build.Reporting; | |
public class SetAndroidPasswordsFromKeychain : IPreprocessBuildWithReport{ | |
public int callbackOrder { get; } | |
public void OnPreprocessBuild(BuildReport report) | |
{ | |
if (report.summary.platform == BuildTarget.Android) | |
{ | |
PlayerSettings.keyaliasPass = MacosKeychain.GetKeychainPassword("unity_android_keyalias_password","unity_android_keyalias"); | |
PlayerSettings.keystorePass = MacosKeychain.GetKeychainPassword("unity_android_keystore_password","unity_android_keystore"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
public static class ShellHelper | |
{ | |
public static string Bash(string cmd) | |
{ | |
var escapedArgs = cmd.Replace("\"", "\\\""); | |
var process = new Process() | |
{ | |
StartInfo = new ProcessStartInfo | |
{ | |
FileName = "/bin/bash", | |
Arguments = $"-c \"{escapedArgs}\"", | |
RedirectStandardOutput = true, | |
UseShellExecute = false, | |
CreateNoWindow = true, | |
} | |
}; | |
process.Start(); | |
string result = process.StandardOutput.ReadToEnd(); | |
process.WaitForExit(); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment