   @dl_path '/root/upgrade.fw'
   @double_flash_error "A software update is already in progress. Please wait."
 
-  def prevent_double_installation!(path \\ to_string(@dl_path)) do
-    if File.exists?(path) do
-      FarmbotCore.Logger.error(3, @double_flash_error)
-      raise @double_flash_error
-    end
-  end
-
   def check_update() do
     get_target()
     |> download_meta_data()


    # Probably never returns?
    :ok
  end

  def get_target() do

  end

  def install_update(url) do
    try do
      prevent_double_installation!()
      download_update_file(url)
      do_flash_firmware()
    after
      finalize_installation()
    end
  end

  def finalize_installation() do
    if has_artifacts?() do
      clean_up()
      FarmbotCore.Logger.debug(3, "Going down for reboot.")
      FarmbotCeleryScript.SysCalls.reboot()
    end
  end

  def clean_up() do
    FarmbotCore.Logger.debug(3, "Cleaning up file artifacts.")
    File.rm!(to_string(@dl_path))
  end

  def do_flash_firmware() do
    msg = "Finished downloading upgrade. Begin installation."
    FarmbotCore.Logger.debug(3, msg)

    path_string = to_string(@dl_path)
    args = ["-a", "-i", path_string, "-d", "/dev/mmcblk0", "-t", "upgrade"]

    {_, 0} = System.cmd("fwup", args)
  end

  def download_update_file(url) do
    FarmbotCore.Logger.debug(3, "Downloading FBOS upgrade from #{url}")
    params = {to_charlist(url), []}

    {:ok, :saved_to_file} = :httpc.request(:get, params, [], stream: @dl_path)
  end

  def handle_http_response({:ok, {_status_line, _response_headers, body}}) do
