From b78548770451fa13567de06ffe5465f980a3c653 Mon Sep 17 00:00:00 2001 From: Justin Schneck Date: Tue, 8 May 2018 07:42:37 -0700 Subject: [PATCH] v1.0.0 --- example/mix.lock.x86_64 | 8 ++-- lib/mix/nerves.gen.qemu_script.ex | 72 +++++++++++++++++++++++++++++++ mix.exs | 6 ++- mix.lock | 2 + 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 lib/mix/nerves.gen.qemu_script.ex diff --git a/example/mix.lock.x86_64 b/example/mix.lock.x86_64 index 295f7b5..949b2e9 100644 --- a/example/mix.lock.x86_64 +++ b/example/mix.lock.x86_64 @@ -5,16 +5,16 @@ "logger_circular_buffer": {:hex, :logger_circular_buffer, "0.2.0", "fd3dfd4720ef9e26a20e1d405d4bfbd6b88507e2fb0cccbe00a1fff38862e5ca", [:mix], [], "hexpm"}, "mdns": {:hex, :mdns, "0.1.7", "7b949773ff5809bb720256171767db1c9bf21eea477128b361a92b0c5e6af220", [:mix], [{:dns, "~> 1.0", [hex: :dns, repo: "hexpm", optional: false]}], "hexpm"}, "muontrap": {:hex, :muontrap, "0.2.1", "ecf61fd9265c186f8f8fe6014aa054c61e1fc36ed3f7ab9db35a9d13ee808d5a", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, - "nerves": {:hex, :nerves, "1.0.0-rc.0", "5c6cf122611d0024d06b88593aa9af46180d30712fc6ff07fa25fb9100125f1e", [:mix], [{:distillery, "~> 1.4", [hex: :distillery, repo: "hexpm", optional: false]}], "hexpm"}, + "nerves": {:hex, :nerves, "1.0.0", "c5b91388fc15661149bfbe8e85fec70b7034f291a484f2b4f10994d20a03d6d1", [:mix], [{:distillery, "~> 1.4", [hex: :distillery, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, "nerves_firmware_ssh": {:hex, :nerves_firmware_ssh, "0.3.1", "e8b1967fa0aff255230be539c68ec868d33884193a385caff957ebad7d6aa8af", [:mix], [{:nerves_runtime, "~> 0.4", [hex: :nerves_runtime, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_init_gadget": {:hex, :nerves_init_gadget, "0.2.1", "20f36dd062fb00e2be8817ddff1b9ced9762877cfe23f6ec1d5936a37e3fc2c8", [:mix], [{:mdns, "~> 0.1", [hex: :mdns, repo: "hexpm", optional: false]}, {:nerves_firmware_ssh, "~> 0.2", [hex: :nerves_firmware_ssh, repo: "hexpm", optional: false]}, {:nerves_network, "~> 0.3", [hex: :nerves_network, repo: "hexpm", optional: false]}, {:nerves_runtime, "~> 0.3", [hex: :nerves_runtime, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_network": {:hex, :nerves_network, "0.3.6", "c95779283ace071e9d12882d6a80e31edc8c476012adc61aba2ff6c306ef97b3", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nerves_network_interface, "~> 0.4.0", [hex: :nerves_network_interface, repo: "hexpm", optional: false]}, {:nerves_wpa_supplicant, "~> 0.3.0", [hex: :nerves_wpa_supplicant, repo: "hexpm", optional: false]}, {:system_registry, "~> 0.4", [hex: :system_registry, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_network_interface": {:hex, :nerves_network_interface, "0.4.4", "200b1a84bc1a7fdeaf3a1e0e2d4e9b33e240b034e73f39372768d43f8690bae0", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_runtime": {:hex, :nerves_runtime, "0.5.3", "7447a3e718762f3901046f72cc824e528f8d0565a581b8ae58f4f5b6436bca7f", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:system_registry, "~> 0.5", [hex: :system_registry, repo: "hexpm", optional: false]}], "hexpm"}, - "nerves_system_br": {:hex, :nerves_system_br, "1.0.0-rc.0", "63400e1a12baa307603d9d0b30fe87de1f67623f71156b278f0be5ce74c7d117", [:mix], [], "hexpm"}, + "nerves_system_br": {:hex, :nerves_system_br, "1.0.0", "ea53a05d3a9c5eed1a632757b7014a205cb17f7e415f5f3f3832d48c58aadfb8", [:mix], [], "hexpm"}, "nerves_system_linter": {:hex, :nerves_system_linter, "0.3.0", "84e0f63c8ac196b16b77608bbe7df66dcf352845c4e4fb394bffd2b572025413", [:mix], [], "hexpm"}, - "nerves_toolchain_ctng": {:hex, :nerves_toolchain_ctng, "1.4.0-rc.0", "1766752c2a854af5e0f102892d947f787f8f47ee500f564e7fdb50c4d1c4789c", [:mix], [{:nerves, "~> 1.0-rc", [hex: :nerves, repo: "hexpm", optional: false]}], "hexpm"}, - "nerves_toolchain_x86_64_unknown_linux_gnu": {:hex, :nerves_toolchain_x86_64_unknown_linux_gnu, "1.0.0-rc.0", "885b813d416ca9428b81def8a45c6abdb16618ec3a87351f7964e297064d2f7d", [:mix], [{:nerves, "~> 1.0-rc", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_toolchain_ctng, "~> 1.4-rc", [hex: :nerves_toolchain_ctng, repo: "hexpm", optional: false]}], "hexpm"}, + "nerves_toolchain_ctng": {:hex, :nerves_toolchain_ctng, "1.4.0", "ec844dd286a5281223e023edb1359c8763fef79a3af9daac45397713cff1cb88", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}], "hexpm"}, + "nerves_toolchain_x86_64_unknown_linux_gnu": {:hex, :nerves_toolchain_x86_64_unknown_linux_gnu, "1.0.0", "96ba1449387a2445db907ba33ef750648e6637565e4613db0e9a16b82c1430e0", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_toolchain_ctng, "~> 1.4", [hex: :nerves_toolchain_ctng, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_wpa_supplicant": {:hex, :nerves_wpa_supplicant, "0.3.2", "19dc7e1248336e7f542b11b2b857ceb5b088d3eb41a6ca75b7b76628dcf67aad", [:make, :mix], [{:elixir_make, "~> 0.3", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, "ring_logger": {:hex, :ring_logger, "0.4.0", "d58b2d9be6350d291fde90c734dcd56cb50b9be7cae4868163088db84a499e92", [:mix], [], "hexpm"}, "shoehorn": {:hex, :shoehorn, "0.2.0", "6aa80804145c545c59af01980d255209483b14826f53411b4a8797b24c323c20", [:mix], [{:distillery, "~> 1.0", [hex: :distillery, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/lib/mix/nerves.gen.qemu_script.ex b/lib/mix/nerves.gen.qemu_script.ex new file mode 100644 index 0000000..a14aa15 --- /dev/null +++ b/lib/mix/nerves.gen.qemu_script.ex @@ -0,0 +1,72 @@ +defmodule Mix.Tasks.Nerves.Gen.QemuScript do + use Mix.Task + + @shortdoc "Generate QEMU start script" + + @moduledoc """ + Generates a shell script for starting QEMU on a firmware image that + uses `kiosk_system_x86_64`. + + To use the generated script, first create the firmware image using: + + `$ mix firmware.image [path/to/my_app.img]` + + Place this image somewhere where it won't get overwritten. This image + has a similar purpose to the MicroSD card, Flash memory or hard drive + that a real target would use. + + Next, run this command and specify the path to the image. This path + may be overridden when invoking the script. + + Example usage: + + `$ mix nerves.gen.qemu_script [path/to/my_app.img]` + + If the `.img` file isn't specified, it will default to the OTP + application's name plus the `.img` extension. + + ## Options + + None + """ + + @script_name "run-qemu.sh" + + def run(["--" <> _arg | _argv]) do + error_image() + end + + def run([image_path | _argv]) do + if File.exists?(@script_name) do + Mix.shell().yes?("Overwrite #{@script_name}?") || Mix.raise("Aborted") + end + + source = + :code.priv_dir(:nerves_system_x86_64) + |> to_string + |> Path.join(@script_name) + + bindings = [image_path: image_path] + contents = EEx.eval_file(source, bindings, trim: true) + File.write!(@script_name, contents) + File.chmod!(@script_name, 0o755) + + Mix.shell().info("Created #{@script_name}") + end + + def run([]) do + otp_app = Mix.Project.config()[:app] + image_path = "#{otp_app}.img" + run([image_path]) + end + + def run(_), do: error_image() + + defp error_image do + Mix.raise(""" + Unexpected arguments. Expecting to be run as follows: + + $ mix nerves.gen.qemu_script [path/to/app.img] + """) + end +end diff --git a/mix.exs b/mix.exs index bbb0dae..11280fe 100644 --- a/mix.exs +++ b/mix.exs @@ -25,7 +25,8 @@ defmodule KioskSystemx8664.Mixfile do description: description(), package: package(), deps: deps(), - aliases: ["loadconfig": [&bootstrap/1]] + aliases: ["loadconfig": [&bootstrap/1]], + docs: [extras: ["README.md"], main: "readme"] ] end @@ -59,7 +60,8 @@ defmodule KioskSystemx8664.Mixfile do {:nerves, "~> 1.0", runtime: false}, {:nerves_system_br, "~> 1.0.0", runtime: false}, {:nerves_toolchain_x86_64_unknown_linux_gnu , "~> 1.0.0", runtime: false}, - {:nerves_system_linter, "~> 0.3.0", runtime: false} + {:nerves_system_linter, "~> 0.3.0", runtime: false}, + {:ex_doc, "~> 0.18", only: :dev} ] end diff --git a/mix.lock b/mix.lock index 6b3af4d..12205a6 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,7 @@ %{ "distillery": {:hex, :distillery, "1.5.2", "eec18b2d37b55b0bcb670cf2bcf64228ed38ce8b046bb30a9b636a6f5a4c0080", [:mix], [], "hexpm"}, + "earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "nerves": {:hex, :nerves, "1.0.0", "c5b91388fc15661149bfbe8e85fec70b7034f291a484f2b4f10994d20a03d6d1", [:mix], [{:distillery, "~> 1.4", [hex: :distillery, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, "nerves_system_br": {:hex, :nerves_system_br, "1.0.0", "ea53a05d3a9c5eed1a632757b7014a205cb17f7e415f5f3f3832d48c58aadfb8", [:mix], [], "hexpm"}, "nerves_system_linter": {:hex, :nerves_system_linter, "0.3.0", "84e0f63c8ac196b16b77608bbe7df66dcf352845c4e4fb394bffd2b572025413", [:mix], [], "hexpm"},