#!/bin/sh -e HOSTNAME="$1" [ -n "$HOSTNAME" ] || { echo "usage: $0 hostname"; exit 1; } OVERLAY="${BEE_OVERLAY_DIR}" [ -n "$OVERLAY" ] || { echo "ERROR: BEE_OVERLAY_DIR not set"; exit 1; } cleanup() { rm -rf "$tmp"; } tmp="$(mktemp -d)" trap cleanup EXIT makefile() { OWNER="$1" PERMS="$2" FILENAME="$3"; cat > "$FILENAME"; chown "$OWNER" "$FILENAME"; chmod "$PERMS" "$FILENAME"; } rc_add() { mkdir -p "$tmp/etc/runlevels/$2"; ln -sf /etc/init.d/"$1" "$tmp/etc/runlevels/$2/$1"; } mkdir -p "$tmp/etc" makefile root:root 0644 "$tmp/etc/hostname" </dev/null || true [ -n "$BEE_BUILD_INFO" ] && sed -i "s/%%BUILD_INFO%%/${BEE_BUILD_INFO}/" "$tmp/etc/motd" 2>/dev/null || true fi mkdir -p "$tmp/usr" if [ -d "$OVERLAY/usr" ]; then cp -r "$OVERLAY/usr/." "$tmp/usr/" chmod +x "$tmp/usr/local/bin/"* 2>/dev/null || true fi if [ -d "$OVERLAY/root" ]; then mkdir -p "$tmp/root" cp -r "$OVERLAY/root/." "$tmp/root/" chmod 700 "$tmp/root/.ssh" 2>/dev/null || true chmod 600 "$tmp/root/.ssh/authorized_keys" 2>/dev/null || true fi if [ -d "$OVERLAY/lib" ]; then mkdir -p "$tmp/lib" cp -r "$OVERLAY/lib/." "$tmp/lib/" fi mkdir -p "$tmp/etc/dropbear" "$tmp/etc/conf.d" # -R: auto-generate host keys if missing # no dependency on networking service — bee-network handles DHCP independently makefile root:root 0644 "$tmp/etc/conf.d/dropbear" </dev/null | gzip -9n > "$HOSTNAME.apkovl.tar.gz"