Skip to content

Commit 9d5b4b6

Browse files
committed
updates
0 parents  commit 9d5b4b6

File tree

308 files changed

+84633
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

308 files changed

+84633
-0
lines changed

.formatter.exs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Used by "mix format"
2+
[
3+
inputs: [
4+
"{mix,.formatter}.exs",
5+
"{config,lib,test}/**/*.{ex,exs}",
6+
"rootfs_overlay/etc/iex.exs"
7+
]
8+
]

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# KioskTest
2+
3+
**TODO: Add description**
4+
5+
## Targets
6+
7+
Nerves applications produce images for hardware targets based on the
8+
`MIX_TARGET` environment variable. If `MIX_TARGET` is unset, `mix` builds an
9+
image that runs on the host (e.g., your laptop). This is useful for executing
10+
logic tests, running utilities, and debugging. Other targets are represented by
11+
a short name like `rpi3` that maps to a Nerves system image for that platform.
12+
All of this logic is in the generated `mix.exs` and may be customized. For more
13+
information about targets see:
14+
15+
https://hexdocs.pm/nerves/targets.html#content
16+
17+
## Getting Started
18+
19+
To start your Nerves app:
20+
* `export MIX_TARGET=my_target` or prefix every command with
21+
`MIX_TARGET=my_target`. For example, `MIX_TARGET=rpi3`
22+
* Install dependencies with `mix deps.get`
23+
* Create firmware with `mix firmware`
24+
* Burn to an SD card with `mix firmware.burn`
25+
26+
## Learn more
27+
28+
* Official docs: https://hexdocs.pm/nerves/getting-started.html
29+
* Official website: https://nerves-project.org/
30+
* Forum: https://elixirforum.com/c/nerves-forum
31+
* Discussion Slack elixir-lang #nerves ([Invite](https://elixir-slackin.herokuapp.com/))
32+
* Source: https://github.com/nerves-project/nerves

config/config.exs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Mix.Config module.
3+
#
4+
# This configuration file is loaded before any dependency and
5+
# is restricted to this project.
6+
import Config
7+
8+
# Enable the Nerves integration with Mix
9+
Application.start(:nerves_bootstrap)
10+
11+
config :kiosk_test, target: Mix.target()
12+
13+
# Customize non-Elixir parts of the firmware. See
14+
# https://hexdocs.pm/nerves/advanced-configuration.html for details.
15+
16+
config :nerves, :firmware, rootfs_overlay: "rootfs_overlay"
17+
18+
# Set the SOURCE_DATE_EPOCH date for reproducible builds.
19+
# See https://reproducible-builds.org/docs/source-date-epoch/ for more information
20+
21+
config :nerves, source_date_epoch: "1623628165"
22+
23+
# Use Ringlogger as the logger backend and remove :console.
24+
# See https://hexdocs.pm/ring_logger/readme.html for more information on
25+
# configuring ring_logger.
26+
27+
config :logger, backends: [RingLogger]
28+
29+
if Mix.target() == :host or Mix.target() == :"" do
30+
import_config "host.exs"
31+
else
32+
import_config "target.exs"
33+
end

config/host.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Config
2+
3+
# Add configuration that is only needed when running on the host here.

config/target.exs

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import Config
2+
3+
# Use shoehorn to start the main application. See the shoehorn
4+
# docs for separating out critical OTP applications such as those
5+
# involved with firmware updates.
6+
7+
config :shoehorn,
8+
init: [:nerves_runtime, :nerves_pack],
9+
app: Mix.Project.config()[:app]
10+
11+
# Nerves Runtime can enumerate hardware devices and send notifications via
12+
# SystemRegistry. This slows down startup and not many programs make use of
13+
# this feature.
14+
15+
config :nerves_runtime, :kernel, use_system_registry: false
16+
17+
# Erlinit can be configured without a rootfs_overlay. See
18+
# https://github.com/nerves-project/erlinit/ for more information on
19+
# configuring erlinit.
20+
21+
config :nerves,
22+
erlinit: [
23+
hostname_pattern: "nerves-%s"
24+
]
25+
26+
# Configure the device for SSH IEx prompt access and firmware updates
27+
#
28+
# * See https://hexdocs.pm/nerves_ssh/readme.html for general SSH configuration
29+
# * See https://hexdocs.pm/ssh_subsystem_fwup/readme.html for firmware updates
30+
31+
keys =
32+
[
33+
Path.join([System.user_home!(), ".ssh", "id_rsa.pub"]),
34+
Path.join([System.user_home!(), ".ssh", "id_ecdsa.pub"]),
35+
Path.join([System.user_home!(), ".ssh", "id_ed25519.pub"])
36+
]
37+
|> Enum.filter(&File.exists?/1)
38+
39+
if keys == [],
40+
do:
41+
Mix.raise("""
42+
No SSH public keys found in ~/.ssh. An ssh authorized key is needed to
43+
log into the Nerves device and update firmware on it using ssh.
44+
See your project's config.exs for this error message.
45+
""")
46+
47+
config :nerves_ssh,
48+
authorized_keys: Enum.map(keys, &File.read!/1)
49+
50+
# Configure the network using vintage_net
51+
# See https://github.com/nerves-networking/vintage_net for more information
52+
config :vintage_net,
53+
regulatory_domain: "US",
54+
config: [
55+
{"usb0", %{type: VintageNetDirect}},
56+
{"eth0",
57+
%{
58+
type: VintageNetEthernet,
59+
ipv4: %{method: :dhcp}
60+
}},
61+
{"wlan0", %{type: VintageNetWiFi}}
62+
]
63+
64+
config :mdns_lite,
65+
# The `host` key specifies what hostnames mdns_lite advertises. `:hostname`
66+
# advertises the device's hostname.local. For the official Nerves systems, this
67+
# is "nerves-<4 digit serial#>.local". mdns_lite also advertises
68+
# "nerves.local" for convenience. If more than one Nerves device is on the
69+
# network, delete "nerves" from the list.
70+
71+
host: [:hostname, "nerves"],
72+
ttl: 120,
73+
74+
# Advertise the following services over mDNS.
75+
services: [
76+
%{
77+
name: "SSH Remote Login Protocol",
78+
protocol: "ssh",
79+
transport: "tcp",
80+
port: 22
81+
},
82+
%{
83+
name: "Secure File Transfer Protocol over SSH",
84+
protocol: "sftp-ssh",
85+
transport: "tcp",
86+
port: 22
87+
},
88+
%{
89+
name: "Erlang Port Mapper Daemon",
90+
protocol: "epmd",
91+
transport: "tcp",
92+
port: 4369
93+
}
94+
]
95+
96+
# Import target specific config. This must remain at the bottom
97+
# of this file so it overrides the configuration defined above.
98+
# Uncomment to use target specific configurations
99+
100+
# import_config "#{Mix.target()}.exs"

lib/kiosk_test.ex

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule KioskTest do
2+
@moduledoc """
3+
Documentation for KioskTest.
4+
"""
5+
6+
@doc """
7+
Hello world.
8+
9+
## Examples
10+
11+
iex> KioskTest.hello
12+
:world
13+
14+
"""
15+
def hello do
16+
:world
17+
end
18+
end

lib/kiosk_test/application.ex

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
defmodule KioskTest.Application do
2+
# See https://hexdocs.pm/elixir/Application.html
3+
# for more information on OTP Applications
4+
@moduledoc false
5+
6+
use Application
7+
require Logger
8+
9+
def start(_type, _args) do
10+
# See https://hexdocs.pm/elixir/Supervisor.html
11+
# for other strategies and supported options
12+
opts = [strategy: :one_for_one, name: KioskTest.Supervisor]
13+
14+
children =
15+
[
16+
# Children for all targets
17+
# Starts a worker by calling: KioskTest.Worker.start_link(arg)
18+
# {KioskTest.Worker, arg},
19+
] ++ children(target())
20+
21+
Supervisor.start_link(children, opts)
22+
end
23+
24+
# List all child processes to be supervised
25+
def children(:host) do
26+
[
27+
# Children that only run on the host
28+
# Starts a worker by calling: KioskTest.Worker.start_link(arg)
29+
# {KioskTest.Worker, arg},
30+
]
31+
end
32+
33+
def children(_target) do
34+
[
35+
# Children for all targets except host
36+
# Starts a worker by calling: KioskTest.Worker.start_link(arg)
37+
# {KioskTest.Worker, arg},
38+
]
39+
end
40+
41+
def target() do
42+
Application.get_env(:kiosk_test, :target)
43+
end
44+
45+
def platform_init_events(udev_init_delay_ms \\ 5_000) do
46+
# Initialize eudev
47+
:os.cmd('udevd -d');
48+
:os.cmd('udevadm trigger --type=subsystems --action=add');
49+
:os.cmd('udevadm trigger --type=devices --action=add');
50+
:os.cmd('udevadm settle --timeout=30');
51+
Process.sleep(udev_init_delay_ms)
52+
end
53+
54+
def init_kiosk(udev_init \\ true) do
55+
if udev_init, do: platform_init_events()
56+
57+
System.put_env("XDG_RUNTIME_DIR", "/root/cache/")
58+
System.put_env("QTWEBENGINE_CHROMIUM_FLAGS", " --no-sandbox --remote-debugging-port=1234 ")
59+
60+
File.rm_rf "/root/shm"
61+
File.mkdir_p! "/root/shm"
62+
# File.rmdir! "/dev/shm"
63+
File.rm_rf "/dev/shm"
64+
File.ln_s! "/root/shm", "/dev/shm"
65+
66+
Process.sleep(100)
67+
Logger.info("starting web kiosk")
68+
69+
{:ok, kiosk} = WebengineKiosk.start_link(
70+
fullscreen: true,
71+
data_dir: "/root/browser/",
72+
homepage: "blank",
73+
background_color: "black",
74+
sounds: false,
75+
run_as_root: true)
76+
77+
kiosk
78+
end
79+
end

mix.exs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
defmodule KioskTest.MixProject do
2+
use Mix.Project
3+
4+
@app :kiosk_test
5+
@version "0.1.0"
6+
@all_targets [:rpi3, :rpi3a, :rpi4, :x86_64, :rpi4_kiosk]
7+
8+
def project do
9+
[
10+
app: @app,
11+
version: @version,
12+
elixir: "~> 1.9",
13+
archives: [nerves_bootstrap: "~> 1.10"],
14+
start_permanent: Mix.env() == :prod,
15+
build_embedded: true,
16+
deps: deps(),
17+
releases: [{@app, release()}],
18+
preferred_cli_target: [run: :host, test: :host]
19+
]
20+
end
21+
22+
# Run "mix help compile.app" to learn about applications.
23+
def application do
24+
[
25+
mod: {KioskTest.Application, []},
26+
extra_applications: [:logger, :runtime_tools]
27+
]
28+
end
29+
30+
# Run "mix help deps" to learn about dependencies.
31+
defp deps do
32+
[
33+
# Dependencies for all targets
34+
{:nerves, "~> 1.7.8", runtime: false},
35+
{:shoehorn, "~> 0.7.0"},
36+
{:ring_logger, "~> 0.8.1"},
37+
{:toolshed, "~> 0.2.13"},
38+
39+
# Dependencies for all targets except :host
40+
{:nerves_runtime, "~> 0.11.3", targets: @all_targets},
41+
{:nerves_pack, "~> 0.4.0", targets: @all_targets},
42+
43+
{:webengine_kiosk, "~> 0.3.0", github: "nerves-web-kiosk/webengine_kiosk"},
44+
45+
# Dependencies for specific targets
46+
# {:nerves_system_rpi4, "~> 1.13", runtime: false, targets: :rpi4},
47+
48+
{:nerves_system_rpi4, "~> 1.16.0-webengineV2",
49+
github: "elcritch/nerves_system_rpi4",
50+
tag: "v1.16.0-webengineV2",
51+
runtime: false,
52+
targets: [:rpi4_kiosk]},
53+
54+
]
55+
end
56+
57+
def release do
58+
[
59+
overwrite: true,
60+
# Erlang distribution is not started automatically.
61+
# See https://hexdocs.pm/nerves_pack/readme.html#erlang-distribution
62+
cookie: "#{@app}_cookie",
63+
include_erts: &Nerves.Release.erts/0,
64+
steps: [&Nerves.Release.init/1, :assemble],
65+
strip_beams: Mix.env() == :prod or [keep: ["Docs"]]
66+
]
67+
end
68+
end

0 commit comments

Comments
 (0)