Skip to content

Commit

Permalink
rootfs-overlay: add flashing script as rootfs-overlay
Browse files Browse the repository at this point in the history
Add installer specific rootfs modifications, specifically the flashing
script (haos-flash) and LED control.

Signed-off-by: Stefan Agner <stefan@agner.ch>
  • Loading branch information
agners committed Aug 22, 2023
1 parent c5630ab commit 0d5ab64
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
11 changes: 11 additions & 0 deletions configs/green_installer_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ BR2_LINUX_KERNEL_INTREE_DTS_NAME="rockchip/rk3566-ha-green"

BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y

BR2_PACKAGE_OPENSSL=y
BR2_PACKAGE_LIBCURL=y
BR2_PACKAGE_LIBCURL_CURL=y
# BR2_PACKAGE_LIBCURL_EXTRA_PROTOCOLS_FEATURES is not set
BR2_PACKAGE_LIBCURL_OPENSSL=y
BR2_PACKAGE_CA_CERTIFICATES=y
BR2_PACKAGE_XZ=y
BR2_PACKAGE_JQ=y
BR2_PACKAGE_UTIL_LINUX=y
BR2_PACKAGE_UTIL_LINUX_BINARIES=y
BR2_PACKAGE_ROCKCHIP_BLOBS=y
BR2_PACKAGE_ROCKCHIP_BLOBS_VERSION="b4558da0860ca48bf1a571dd33ccba580b9abe23"
BR2_PACKAGE_ROCKCHIP_BLOBS_ATF="bin/rk35/rk3568_bl31_v1.43.elf"
Expand All @@ -56,5 +66,6 @@ BR2_PACKAGE_HOST_MTOOLS=y
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_CPIO_ZSTD=y

BR2_ROOTFS_OVERLAY="rootfs-overlay/"
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/nabucasa/green/post-image.sh"
BR2_ROOTFS_POST_BUILD_SCRIPT="board/nabucasa/green/post-build.sh"
4 changes: 4 additions & 0 deletions rootfs-overlay/etc/systemd/timesyncd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Time]
FallbackNTP=time.cloudflare.com
# Speed-up boot as first attempt is done before network is up
ConnectionRetrySec=10
53 changes: 53 additions & 0 deletions rootfs-overlay/usr/bin/haos-flash
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/ash
# shellcheck shell=dash

set -e
set -o pipefail

# Abort if already running
if pidof dd
then
echo "dd already running, aborting..."
exit 1
fi

if [ "$1" = "dev" ]; then
echo "Getting latest Home Assistant OS version from channel dev..."
channel="https://version.home-assistant.io/dev.json"
else
echo "Getting latest Home Assistant OS version from channel stable..."
channel="https://version.home-assistant.io/stable.json"
fi

version=$(curl --no-progress-meter -L "${channel}" | jq -r '.hassos.green')
echo -n "Installing Home Assitant OS ${version} to "

if [ "$1" = "dev" ]; then
url="https://os-builds.home-assistant.io/${version}/haos_green-${version}.img.xz"
else
url="https://github.com/home-assistant/operating-system/releases/download/${version}/haos_green-${version}.img.xz"
fi

if [ -b /dev/mmcblk0 ]
then
echo "mmcblk0."
device=/dev/mmcblk0
else
echo "nowhere."
echo "No storage media found, exiting."
echo none > /sys/class/leds/yellow:heartbeat/trigger
exit 1
fi

echo timer > /sys/class/leds/yellow:heartbeat/trigger
echo 100 > /sys/class/leds/yellow:heartbeat/delay_on
echo 100 > /sys/class/leds/yellow:heartbeat/delay_off
if curl --no-progress-meter -L "$url" | unxz --stdout | dd of=${device} bs=4M
then
echo "Successfully installed Home Assistant OS, shutting down the system"
echo default-on > /sys/class/leds/yellow:heartbeat/trigger
poweroff
else
echo "Error during Home Assistant OS installation."
echo none > /sys/class/leds/yellow:heartbeat/trigger
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable systemd-time-wait-sync.service
13 changes: 13 additions & 0 deletions rootfs-overlay/usr/lib/systemd/system/install-autostart.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Autostart Home Assistant OS installation
Wants=network-online.target time-sync.target
After=network-online.target time-sync.target
DefaultDependencies=no

[Service]
Type=idle
ExecStart=-/usr/bin/haos-flash stable
StandardOutput=journal+console

[Install]
WantedBy=basic.target

0 comments on commit 0d5ab64

Please sign in to comment.