Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Support new build script
Browse files Browse the repository at this point in the history
  • Loading branch information
noahc3 committed Apr 19, 2020
1 parent 0b4ab08 commit 88927f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
4 changes: 3 additions & 1 deletion SDSetupUpdater/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ namespace SDSetupUpdater {
class Config {
public string GithubUsername { get; set; }
public string GithubAuthToken { get; set; }
public string GitlabAuthToken { get; set; }
public string WebhookEndpoint { get; set; }
public string BackendHostname { get; set; }
public string LibGetRepo { get; set; }
public string KosmosUpdaterScriptPath { get; set; }
public string KosmosScriptPath { get; set; }
public string KosmosUpdaterBuilderSubdirectory { get; set; }
public long KosmosRepositoryId { get; set; }
public string KosmosMasterUrl { get; set; }
public List<string> OldPackagesets { get; set; }
Expand Down
47 changes: 28 additions & 19 deletions SDSetupUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,29 @@ static void Main(string[] args) {
Log("============================================================");
Log("");
Log("Downloading latest Kosmos update script...");
string kosmosScriptPath = new FileInfo(config.KosmosUpdaterScriptPath).Directory.FullName;
Directory.Delete(kosmosScriptPath, true);
Directory.CreateDirectory(kosmosScriptPath);
string kosmosExtractPath = new FileInfo(config.KosmosScriptPath).Directory.FullName;
Directory.Delete(kosmosExtractPath, true);
Directory.CreateDirectory(kosmosExtractPath);
using (var client = new HttpClient()) {
File.WriteAllBytes(Path.Join(kosmosScriptPath, "master.zip"), client.GetByteArrayAsync(config.KosmosMasterUrl).Result);
File.WriteAllBytes(Path.Join(kosmosExtractPath, "master.zip"), client.GetByteArrayAsync(config.KosmosMasterUrl).Result);
FastZip zip = new FastZip();
zip.ExtractZip(Path.Join(kosmosScriptPath, "master.zip"), kosmosScriptPath, null);
File.Delete(Path.Join(kosmosScriptPath, "master.zip"));
zip.ExtractZip(Path.Join(kosmosExtractPath, "master.zip"), kosmosExtractPath, null);
File.Delete(Path.Join(kosmosExtractPath, "master.zip"));
}
string scriptMasterFolder = Directory.EnumerateDirectories(kosmosScriptPath).First();
foreach (string k in Directory.EnumerateFiles(scriptMasterFolder)) {
string masterFolder = Directory.EnumerateDirectories(kosmosExtractPath).First();
string scriptFolder = Path.Join(masterFolder, config.KosmosUpdaterBuilderSubdirectory);
foreach (string k in Directory.EnumerateFiles(scriptFolder)) {
FileInfo f = new FileInfo(k);
if (f.Name.StartsWith('.')) continue;
File.Move(f.FullName, Path.Join(f.Directory.Parent.FullName, f.Name));
File.Move(f.FullName, Path.Join(kosmosExtractPath, f.Name));
}
foreach (string k in Directory.EnumerateDirectories(scriptMasterFolder)) {
foreach (string k in Directory.EnumerateDirectories(scriptFolder)) {
DirectoryInfo f = new DirectoryInfo(k);
if (f.Name.StartsWith('.')) continue;
U.DirectoryCopy(f.FullName, Path.Join(f.Parent.Parent.FullName, f.Name), true);
U.DirectoryCopy(f.FullName, Path.Join(kosmosExtractPath, f.Name), true);
}
Directory.Delete(scriptMasterFolder, true);
("chmod -R 775 " + kosmosScriptPath).ExecuteAsBash();
Directory.Delete(masterFolder, true);
("chmod -R 775 " + kosmosExtractPath).ExecuteAsBash();
Log("Done!");
Log("");

Expand Down Expand Up @@ -179,7 +180,7 @@ static void Main(string[] args) {
} else {
KosmosOutdated = true;
Log($"Kosmos is outdated! Running auto script...");
Dictionary<string, string> kosmos = RunKosmosAutoScript();
Dictionary<string, string> kosmos = RunKosmosAutoScript(latestKosmos);

foreach (SDSetupCommon.Package sdPackage in SDPackages.Values) {
if (sdPackage.AutoUpdateType == AutoUpdateType.Kosmos) {
Expand Down Expand Up @@ -261,7 +262,7 @@ static void Main(string[] args) {
Log($"Detected {OutdatedPackagesKosmos.Count} outdated Kosmos packages. Updating...");

foreach (string k in OutdatedPackagesKosmos.Keys) {
string kosmosAutoPackageDirectory = Path.Join(new FileInfo(config.KosmosUpdaterScriptPath).Directory.FullName, "out", SDPackages[k].AutoUpdateHint);
string kosmosAutoPackageDirectory = Path.Join(new FileInfo(config.KosmosScriptPath).Directory.FullName, "out", SDPackages[k].AutoUpdateHint);
string packageFilesDirectory = Path.Join(nPackagesetDirectory, k, "latest", String.IsNullOrWhiteSpace(SDPackages[k].AutoUpdatePathOverride) ? "sd" : SDPackages[k].AutoUpdatePathOverride);

Directory.Delete(packageFilesDirectory, true);
Expand Down Expand Up @@ -364,16 +365,24 @@ static bool UpdateBackend(string uuid, string packageSet) {
}
}

static Dictionary<string, string> RunKosmosAutoScript() {
string scriptDirectory = new FileInfo(config.KosmosUpdaterScriptPath).Directory.FullName;
string scriptPath = new FileInfo(config.KosmosUpdaterScriptPath).FullName;
static Dictionary<string, string> RunKosmosAutoScript(string KosmosVersion) {
string scriptDirectory = new FileInfo(config.KosmosScriptPath).Directory.FullName;
string scriptPath = new FileInfo(config.KosmosScriptPath).FullName;
if (Directory.Exists(Path.Join(scriptDirectory, "out"))) {
Directory.Delete(Path.Join(scriptDirectory, "out"), true);
}

File.WriteAllLines((scriptDirectory + "/config.py").AsPath(), new string[] {
$"version = '{KosmosVersion}'\n",
$"github_username = '" + config.GithubUsername + "'\n",
$"github_password = '{config.GithubAuthToken}'\n",
$"gitlab_private_access_token = '{config.GitlabAuthToken}'"
});

Process process = new Process {
StartInfo = new ProcessStartInfo {
FileName = scriptPath,
Arguments = $"{Path.Join(scriptDirectory, "out")} {config.GithubUsername} {config.GithubAuthToken} auto",
Arguments = $"sdsetup {Path.Join(scriptDirectory, "out")} --auto",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
Expand Down

0 comments on commit 88927f2

Please sign in to comment.