-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule FarmbotOS.SysCalls.CheckUpdate do | ||
@moduledoc false | ||
require FarmbotCore.Logger | ||
|
||
alias FarmbotOS.{ | ||
UpdateSupport, | ||
UpdateProgress | ||
} | ||
|
||
def check_update() do | ||
if UpdateSupport.in_progress?() do | ||
dont_check_update() | ||
else | ||
do_check_update() | ||
end | ||
end | ||
|
||
def dont_check_update() do | ||
{:error, "Installation already started. Please wait or reboot."} | ||
end | ||
|
||
def do_check_update() do | ||
{:ok, progress_pid} = UpdateProgress.start_link([]) | ||
# Try to find the upgrade image URL (might be `nil`) | ||
url_or_nil = | ||
UpdateSupport.get_target() | ||
|> UpdateSupport.download_meta_data() | ||
|> Map.get("image_url", nil) | ||
|
||
with :ok <- UpdateSupport.install_update(url_or_nil) do | ||
UpdateProgress.set(progress_pid, 100) | ||
FarmbotCeleryScript.SysCalls.reboot() | ||
else | ||
{:error, error} -> terminate(error, progress_pid) | ||
error -> terminate(error, progress_pid) | ||
end | ||
end | ||
|
||
def terminate(error, progress_pid) do | ||
FarmbotCore.Logger.debug(3, "Upgrade halted: #{inspect(error)}") | ||
UpdateProgress.set(progress_pid, 100) | ||
{:error, error} | ||
end | ||
end |