Guest User

Untitled

a guest
May 25th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use File::Copy;
  3. use File::Find;
  4. use File::Path;
  5. use Cwd;
  6.  
  7. # Exoa SignAndPackage script v1.3
  8. # Author : Anthony Kozak :: exoa.fr
  9. # Place this script in the same folder as the generated .app file from Unity
  10. # YOU WOULD NEED IN THIS DIRECTOY:
  11. # - a filled Info.plist file
  12. # - a PlayerIcon.icns file
  13. # - a filled entitlements.entitlements file
  14. # - a UnityPlayerIcon.png file
  15. # YOU CAN CHECK YOUR INSTALLED CERTIFICATES NAMES USING
  16. # security find-identity -p codesigning
  17.  
  18. logit("Hello !");
  19.  
  20.  
  21.  
  22. my $app_found = found_app_indir();
  23. my $appName = ask("What's the .app name in this directory ?", $app_found);
  24. my $appPath = getcwd . "/".$appName.".app";
  25. my $appType = ask("Is this app for the MacAppStore or External ?","MacAppStore");
  26. my $appPathSigned = getcwd . "/".$appType."/".$appName.".app";
  27. my $packagePath = getcwd . "/".$appType."/".$appName.".pkg";
  28.  
  29.  
  30.  
  31. #my $profile = ask("What's the provision profile name to use in this directory ?","profile.provisionprofile");
  32. my $doCodeSigning = ask("Sign the app ?", "true");
  33. my $doCreatePackage = ask("Generate package ?","true");
  34. my $copyInfopList = ask("Copy Info.plist from this directory inside the .app ?","true");
  35. my $copyIcons = ask("Copy PlayerIcon.icns from this directory inside the .app ?","false");
  36. my $copyIcon = ask("Copy UnityPlayerIcon.png from this directory inside the .app ?","true");
  37.  
  38. my $srcAssetPath = "/";
  39.  
  40. my $certificateApplication = ask("What's the application certificate name ?", $appType eq "MacAppStore" ? "3rd Party Mac Developer Application:" : "Developer ID Application:");
  41. my $certificateInstaller = "";
  42. if($doCreatePackage eq "true")
  43. {
  44. $certificateInstaller = ask("What's the installer certificate name ?", $appType eq "MacAppStore" ? "3rd Party Mac Developer Installer:" : "Developer ID Installer:");
  45. }
  46. my $entitlementsFileName = "";
  47. if($appType eq "MacAppStore")
  48. {
  49. $entitlementsFileName = ask("What's the .entitlements file name in this directory ?", "entitlements.entitlements");
  50. $entitlementsFileName = "--entitlements \"".$entitlementsFileName."\"";
  51. }
  52.  
  53. logit("*** Starting Process - Building at '$appPath' ***");
  54.  
  55.  
  56. # src and dest are temp variables. Just ignore them... 🙂
  57. my $src = "";
  58. my $dest = "";
  59.  
  60. # Removing previous dir
  61. rmtree $appType;
  62.  
  63. # Creating target dir
  64. mkdir $appType, 0755;
  65.  
  66. # this copies your own /Info.plist to the generated game
  67. if($copyInfopList eq "true")
  68. {
  69. $plist = getcwd . $srcAssetPath . "Info.plist";
  70. $dest = $appPath . "/Contents/Info.plist";
  71. print ("\n*** Copying " . getShort($plist). " to " . getShort($dest));
  72. copy($plist, $dest) or die "File can not be copied: " . $plist;
  73. }
  74.  
  75. # this copies PlayerIcon.icns to your generated game replacing the original app icon by your own
  76. if($copyIcons eq "true")
  77. {
  78. $icons = getcwd . $srcAssetPath . "PlayerIcon.icns";
  79. $dest = $appPath . "/Contents/Resources/PlayerIcon.icns";
  80. print ("\n*** Copying " . $icons . " to " . $dest);
  81. copy($icons, $dest) or die "File can not be copied: " . $icons;
  82. }
  83. # this copies /UnityPlayerIcon.png to your generated game replacing the original Unity Player Icon by your own
  84. if($copyIcon eq "true")
  85. {
  86. $playericon = getcwd . $srcAssetPath . "UnityPlayerIcon.png";
  87. $dest = $appPath . "/Contents/Resources/UnityPlayerIcon.png";
  88. print ("\n*** Copying " . getShort($playericon) . " to " . getShort($dest));
  89. copy($playericon, $dest) or die "File can not be copied: " . $playericon;
  90. }
  91. # this copies $profile to your generated game
  92. #$src = getcwd . $srcAssetPath . $profile;
  93. #$dest = $appPath . "/Contents/embedded.provisionprofile";
  94. #print ("\n*** Copying " . getShort($src) . " to " . getShort($dest));
  95. #copy($src, $dest) or die "File can not be copied: " . $src;
  96.  
  97. # this copies appPath to appPathSigned and use it
  98. print ("\n*** Copying " . getShort($appPath) . " to " . getShort($appPathSigned));
  99. system("cp -r \"".$appPath."\" \"".$appPathSigned."\"");
  100.  
  101.  
  102.  
  103. ## Chmod and remove unecessary files
  104. system("/bin/chmod -R a+rwx \"$appPathSigned\"");
  105. system("find \"$appPathSigned\" -name \*.meta -exec rm -r \"{}\" \\;");
  106. system("/usr/sbin/chown -RH \"cestdesbullshit1:staff\" \"$appPathSigned\"");
  107. system("/bin/chmod -RH u+w,go-w,a+rX \"$appPathSigned\"");
  108. my $CodesignEnvironment = $ENV{'CODESIGN_ALLOCATE'};
  109. $ENV{'CODESIGN_ALLOCATE'}="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate";
  110.  
  111.  
  112. # Auto code signing
  113. if ($doCodeSigning eq "true") {
  114. recursiveCodesign("$appPathSigned/Contents/Frameworks");
  115. recursiveCodesign("$appPathSigned/Contents/Plugins");
  116. recursiveCodesign("$appPathSigned/Contents/MacOS");
  117. logit ("*** Start signing");
  118. system("/usr/bin/codesign --force --timestamp=none --sign \"" . $certificateApplication . "\" ".$entitlementsFileName." \"" . $appPathSigned . "\"");
  119. logit ("*** Verify signing");
  120. system("codesign --verify --verbose \"" . $appPathSigned . "\"");
  121. }
  122.  
  123. # Auto creating a package file?
  124. if ($doCreatePackage eq "true") {
  125. logit("*** Start packaging");
  126. system("productbuild --component \"" . $appPathSigned . "\" /Applications --sign \"". $certificateInstaller . "\" --product \"$appPathSigned/Contents/Info.plist\" \"" . $packagePath . "\"");
  127. }
  128. $ENV{'CODESIGN_ALLOCATE'}=$CodesignEnvironment;
  129. logit("*** ALL DONE ! ***");
  130.  
  131. sub ask{
  132. my $text = shift;
  133. my $default = shift;
  134. logit($text . " [default: ".$default."]");
  135. my $answer = <STDIN>;
  136. chomp $answer;
  137. return ($answer eq "") ? $default : $answer;
  138.  
  139. }
  140. sub logit{
  141. my $text = shift;
  142. print("\n".$text."\n");
  143. }
  144. sub recursiveCodesign {
  145.  
  146. my $dirName = shift;
  147. print("\n*** Recursive Codesigning ".getShort($dirName)."\n");
  148. opendir my($dh), $dirName or return;
  149. my @files = readdir($dh);
  150. closedir $dh;
  151. foreach my $currentFile (@files) {
  152. next if $currentFile =~ /^\.{1,2}$/;
  153. if ( lc($currentFile) =~ /.bundle$/ or lc($currentFile) =~ /.dylib$/ or lc($currentFile) =~ /.a$/ or lc($currentFile) =~ /.so$/ or lc($currentFile) =~ /.lib$/ or (-f "$dirName/$currentFile" && $currentFile =~ /^[^.]*$/ && `file "$dirName/$currentFile"` =~ /Mach-O/) ) {
  154. print("\tCodesigning ".getShort($currentFile)."\n");
  155. system("/usr/bin/codesign --force --timestamp=none --sign \"".$certificateApplication."\" \"$dirName/$currentFile\"");
  156. }
  157. if (-d "$dirName/$currentFile") {
  158. recursiveCodesign("$dirName/$currentFile");
  159. }
  160. }
  161. }
  162. sub found_app_indir()
  163. {
  164. opendir(my $dh, '.') || die "cant open dir";
  165. my @list_found = grep { /.app$/ } readdir($dh);
  166. my $app_found = @list_found[0];
  167. chop($app_found); chop($app_found);chop($app_found); chop($app_found);
  168. return $app_found;
  169. }
  170. sub getShort() {
  171. my $subject = shift;
  172. my $search = getcwd . "/";
  173. my $replace = "";
  174. my $pos = index($subject, $search);
  175. while($pos > -1) {
  176. substr($subject, $pos, length($search), $replace);
  177. $pos = index($subject, $search, $pos + length($replace));
  178. }
  179. return $subject;
  180. }
Add Comment
Please, Sign In to add comment