add dl updater to bot state
This commit is contained in:
parent
8fe2d1b949
commit
b07ae9c2fb
|
@ -116,15 +116,17 @@ defmodule Farmbot.System.Updates.SlackUpdater do
|
|||
if match?(<< <<"farmbot-">>, @target, <<"-">>, _rest :: binary>>, name) do
|
||||
Logger.warn(3, "Downloading and applying an image from slack!")
|
||||
if Farmbot.System.ConfigStorage.get_config_value(:bool, "settings", "os_auto_update") do
|
||||
alias Farmbot.System.Updates.FwupStream
|
||||
{:ok, stream} = FwupStream.start_link()
|
||||
stream_fun = fn(http_status_code, chunk) ->
|
||||
if http_status_code not in [301, 302, 303, 307, 308] do
|
||||
FwupStream.send_chunk(stream, chunk)
|
||||
end
|
||||
end
|
||||
case Farmbot.HTTP.download_file(dl_url, Path.join(@data_path, name), nil, "", [{'Authorization', 'Bearer #{state.token}'}], stream_fun) do
|
||||
{:ok, _path} ->
|
||||
# alias Farmbot.System.Updates.FwupStream
|
||||
# {:ok, stream} = FwupStream.start_link()
|
||||
# stream_fun = fn(http_status_code, chunk) ->
|
||||
# if http_status_code not in [301, 302, 303, 307, 308] do
|
||||
# FwupStream.send_chunk(stream, chunk)
|
||||
# end
|
||||
# end
|
||||
dl_fun = Farmbot.BotState.download_progress_fun("FBOS_OTA")
|
||||
case Farmbot.HTTP.download_file(dl_url, Path.join(@data_path, name), dl_fun, "", [{'Authorization', 'Bearer #{state.token}'}]) do
|
||||
{:ok, path} ->
|
||||
Nerves.Firmware.upgrade_and_finalize(path)
|
||||
Farmbot.System.reboot("Slack update.")
|
||||
{:stop, :normal, %{state | updating: true}}
|
||||
{:error, reason} ->
|
||||
|
|
Loading…
Reference in a new issue