Skip to content

Commit

Permalink
Firmware update improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fhunleth committed Apr 29, 2021
1 parent b5e8f57 commit a2fa66d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/nerves_livebook/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ defmodule NervesLivebook.Application do
end

defp initialize_data_directory() do
destination_path = "/data/livebooks"
source_path = Application.app_dir(:nerves_livebook, "priv")
destination_dir = "/data/livebooks"
source_dir = Application.app_dir(:nerves_livebook, "priv")

# Best effort create everything
_ = File.mkdir_p(destination_path)
Enum.each(["welcome.livemd", "samples"], &symlink(source_path, destination_path, &1))
_ = File.mkdir_p(destination_dir)
Enum.each(["welcome.livemd", "samples"], &symlink(source_dir, destination_dir, &1))
end

defp symlink(source_dir, destination_dir, filename) do
Expand Down
18 changes: 14 additions & 4 deletions priv/samples/firmware_update.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ from [Github releases](https://github.com/fhunleth/nerves_livebook/releases).

## Walk through

Evaluate the following to see what you're currently running:
Evaluate the following to see what firmware version you're running:

```elixir
IO.puts("You're currently running Nerves Livebook #{NervesLivebook.version()} on the target \"#{NervesLivebook.target()}\".")
IO.write("""
You're running Nerves Livebook #{NervesLivebook.version()}.
More details:
Target: #{NervesLivebook.target()}
Firmware UUID: #{Nerves.Runtime.KV.get_active("nerves_fw_uuid")}
Firmware partition: #{Nerves.Runtime.KV.get("nerves_fw_active")}
""")
```

Nerves Livebook firmware images are hosted on GitHub under the [releases
Expand Down Expand Up @@ -42,6 +49,7 @@ on a slow connection. Watch the evaluating circle pulse to know that it's workin
IO.puts("Downloading #{firmware_url}...")

firmware_path = "/data/update.fw"
File.rm_rf!(firmware_path)

{:ok, :saved_to_file} =
:httpc.request(:get, {firmware_url, []}, [], stream: to_charlist(firmware_path))
Expand All @@ -61,8 +69,10 @@ IO.puts("Validating archive...")
IO.write(output)
```

The UUID metadata field is important. All firmware archives have a unique UUID,
so if someone makes a change and doesn't update the version number, you'll know.
The UUID metadata field is important. The UUID is computed from the contents
of the firmware archive and uniquely identifies what's running. If you're
ever unsure if you're running the exact same bits that you verified in QA,
check the UUID.

Ok, now we're ready for the big step. This won't erase any of your livebooks or
settings. It just updates the Nerves Livebook firmware. After this completes
Expand Down

0 comments on commit a2fa66d

Please sign in to comment.