Skip to content

Instantly share code, notes, and snippets.

@anyuser
Created March 27, 2019 15:27
Show Gist options
  • Save anyuser/4a8fd7c487aa653e0272c28ca2da7949 to your computer and use it in GitHub Desktop.
Save anyuser/4a8fd7c487aa653e0272c28ca2da7949 to your computer and use it in GitHub Desktop.
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' );
}
}
#!/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
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");
}
}
}
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