Make sure to reboot if called from fe

This commit is contained in:
connor rigby 2018-01-03 15:04:45 -08:00 committed by Connor Rigby
parent 7e09c64fd4
commit f26413955e
2 changed files with 9 additions and 8 deletions

View file

@ -5,7 +5,7 @@ defmodule Farmbot.CeleryScript.AST.Node.CheckUpdates do
def execute(%{package: :farmbot_os}, _, env) do
env = mutate_env(env)
case Farmbot.System.Updates.check_updates() do
case Farmbot.System.Updates.check_updates(true) do
:ok -> {:ok, env}
:no_update -> {:ok, env}
_ -> {:error, "Failed to check updates", env}

View file

@ -21,13 +21,13 @@ defmodule Farmbot.System.Updates do
end
@doc "Force check updates."
def check_updates do
def check_updates(reboot) do
token = ConfigStorage.get_config_value(:string, "authorization", "token")
if token do
case Farmbot.Jwt.decode(token) do
{:ok, %Farmbot.Jwt{os_update_server: update_server}} ->
override = ConfigStorage.get_config_value(:string, "settings", "os_update_server_overwrite")
do_check_updates_http(override || update_server)
do_check_updates_http(override || update_server, reboot)
_ -> no_token()
end
else
@ -40,7 +40,7 @@ defmodule Farmbot.System.Updates do
:ok
end
defp do_check_updates_http(url) do
defp do_check_updates_http(url, reboot) do
Logger.info 3, "Checking: #{url} for updates."
with {:ok, %{body: body, status_code: 200}} <- Farmbot.HTTP.get(url),
{:ok, data} <- Poison.decode(body),
@ -53,7 +53,9 @@ defmodule Farmbot.System.Updates do
{:ok, current_version} <- Version.parse(@current_version),
{:ok, fw_url} <- find_fw_url(data, new_version) do
needs_update = if prerelease do
new_commit == @current_commit
val = new_commit == @current_commit
Logger.info 1, "Checking prerelease commits: current_commit: #{@current_commit} new_commit: #{new_commit} #{val}"
!val
else
case Version.compare(current_version, new_version) do
s when s in [:gt, :eq] ->
@ -72,7 +74,7 @@ defmodule Farmbot.System.Updates do
IO.puts cl
# Logger.info 1, "Downloading update. Here is the release notes"
# Logger.info 1, cl
do_download_and_apply(fw_url, new_version)
do_download_and_apply(fw_url, new_version, reboot)
else
:no_update
end
@ -133,12 +135,11 @@ defmodule Farmbot.System.Updates do
true
end
defp do_download_and_apply(dl_url, new_version) do
defp do_download_and_apply(dl_url, new_version, reboot) do
dl_fun = Farmbot.BotState.download_progress_fun("FBOS_OTA")
dl_path = Path.join(@data_path, "#{new_version}.fw")
case Farmbot.HTTP.download_file(dl_url, dl_path, dl_fun, "", []) do
{:ok, path} ->
reboot = ConfigStorage.get_config_value(:bool, "settings", "os_auto_update")
apply_firmware(path, reboot)
{:error, reason} ->
Logger.error 1, "Failed to download update file: #{inspect reason}"