Skip to content

Commit

Permalink
login check actually works lol
Browse files Browse the repository at this point in the history
  • Loading branch information
Crash0v3r1de committed May 14, 2022
1 parent eafbbff commit 993daf1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 25 additions & 0 deletions Core/Balena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ public class Balena
{
private readonly string _gitLoc = Environment.CurrentDirectory + "\\helium-rak";

public bool NeedsAuth() {
ProcessStartInfo gitInfo = new ProcessStartInfo();
gitInfo.CreateNoWindow = true;
gitInfo.RedirectStandardError = true;
gitInfo.RedirectStandardOutput = true;
gitInfo.FileName = SettingsStatic.Settings.BalenaPath + @"\balena.cmd";
Process gitProcess = new Process();


gitInfo.Arguments = "fleets";
gitInfo.WorkingDirectory = _gitLoc;

gitProcess.StartInfo = gitInfo;
gitProcess.Start();

string stderr_str = gitProcess.StandardError.ReadToEnd();
string stdout_str = gitProcess.StandardOutput.ReadToEnd();

gitProcess.WaitForExit();
gitProcess.Close();

if (stderr_str.Contains("Login required")) return true;

return false;
}
public bool BalenaLogin() {
ProcessStartInfo gitInfo = new ProcessStartInfo();
gitInfo.CreateNoWindow = true;
Expand Down
7 changes: 5 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
SettingsStatic.Settings.FleetName = con.FleetName();
}

BalenaStatus.NeedsAuth = true;
if (bel.NeedsAuth()) bel.BalenaLogin(); BalenaStatus.NeedsAuth = false;

while (true) {
// Version checking with github logic - may be organized into it's own class down the road
bool updated = false;
if (git.NeedsCloned())
{
git.CloneRepo();
git.CloneRepo();
}
if (git.NeedsPulled())
{
git.PullRepo(); // Update
if (BalenaStatus.NeedsAuth) bel.BalenaLogin(); // Prompt for login if initial run
if (BalenaStatus.NeedsAuth) bel.BalenaLogin(); BalenaStatus.NeedsAuth = false; // Prompt for login if initial run
bel.FleetPush(); // Push update to balena for building
if (!String.IsNullOrEmpty(SettingsStatic.Settings.webhook)) Discord.SendWebhook();
Console.WriteLine($"{DateTime.Now} | Fleet updated!");
Expand Down

0 comments on commit 993daf1

Please sign in to comment.