Fix fwupdates requireing a reboot

pull/420/head^2
connor rigby 2018-01-22 13:01:14 -08:00
parent 97cae33e8d
commit 34ba1797f4
5 changed files with 32 additions and 13 deletions

View File

@ -1 +1 @@
6.1.0
6.1.1

View File

@ -12,4 +12,7 @@ defmodule Farmbot.System.UpdateHandler do
@doc "Setup updates."
@callback setup(atom) :: :ok | {:error, term}
@doc "If a fw has already been applied."
@callback requires_reboot? :: boolean
end

View File

@ -22,6 +22,15 @@ defmodule Farmbot.System.Updates do
@doc "Force check updates."
def check_updates(reboot) do
if @handler.requires_reboot? do
if reboot do
Logger.info 1, "Farmbot applied an update. Rebooting."
Farmbot.System.reboot("Update reboot required")
else
Logger.info 1, "Farmbot already applied an update. Please reboot."
:ok
end
else
token = ConfigStorage.get_config_value(:string, "authorization", "token")
if token do
case Farmbot.Jwt.decode(token) do
@ -38,6 +47,7 @@ defmodule Farmbot.System.Updates do
no_token()
end
end
end
defp no_token do
Logger.debug 3, "Not checking for updates. (No token)"

View File

@ -21,4 +21,6 @@ defmodule Farmbot.Host.UpdateHandler do
def setup(_env) do
:ok
end
def requires_reboot?, do: false
end

View File

@ -28,4 +28,8 @@ defmodule Farmbot.Target.UpdateHandler do
def setup(_) do
:ok
end
def requires_reboot? do
!Nerves.Firmware.allow_upgrade?
end
end