DEVELOPMENT ENVIRONMENT

~liljamo/src.quest-anemos

5f73da826c357b8958b02b0690a444199b2a85c3 — Jonni Liljamo 8 days ago a3e1282
feat(sqmeta): init as first host
A justfile => justfile +30 -0
@@ 0,0 1,30 @@
_default:
    just --list

# Check if host directory exists
host-dir-exists host:
    #!/usr/bin/env sh
    if [ ! -d {{host}} ]; then
        echo "{{host}} does not exist"
        exit 1
    fi

# Check host reachability via ping
host-reachable host: (host-dir-exists host)
    #!/usr/bin/env sh
    ping -w 1 -c 1 $(cat ./{{host}}/ADDRESS)
    if [ $? -ne 0 ]; then
        echo "{{host}} is not reachable"
        exit 1
    fi

# Test the IMGBUILD by building an image
test host: (host-dir-exists host)
    #!/usr/bin/env sh
    cd ./{{host}}
    sudo makeimg --format "raw 4g msdos ext4"

get-anemos host: (host-reachable host)
    #!/usr/bin/env/sh
    address=$(cat ./{{host}}/ADDRESS)
    ssh root@$address wget https://git.sr.ht/~bitfehler/anemos-cli/blob/master/anemos

A sqmeta/ADDRESS => sqmeta/ADDRESS +1 -0
@@ 0,0 1,1 @@
10.1.33.169

A sqmeta/IMGBUILD => sqmeta/IMGBUILD +66 -0
@@ 0,0 1,66 @@
imgname=sqmeta
target=alpine
format="custom"

# Sections
#  Core system
#  Provisioning
#  Anemos
#  Other
packages="
  alpine-base
  linux-virt
  syslinux
  e2fsprogs

  lsblk

  zstd
  curl

  openssh
"

services="
  networking:boot
  sshd
"

setup() {
  # Repartition
  parted -s -- /dev/vda mklabel msdos \
    mkpart primary 2048s 256MiB \
    mkpart primary 256MiB -1s \
    set 1 boot on
  partprobe /dev/vda

  # wait for hotplug events to settle...
  sleep 1 && mdev -sf

  uuidr=$(uuidgen)
  uuidb=$(uuidgen)
  mkfs.ext2 -q -F -U "$uuidb" /dev/vda1
  mkfs.ext4 -q -F -U "$uuidr" /dev/vda2
  mount /dev/vda2 "${imgroot}"
  mkdir "${imgroot}/boot"
  mount /dev/vda1 "${imgroot}/boot"
  mkdir "${imgroot}/etc"
  opts=$(findmnt -no OPTIONS /dev/vda2)
  printf "UUID=%s\t/\t%s\t%s\t0 1\n" "${uuidr}" "ext4" "${opts}" > "${imgroot}/etc/fstab"
  opts=$(findmnt -no OPTIONS /dev/vda1)
  printf "UUID=%s\t/boot\t%s\t%s\t0 2\n" "${uuidb}" "ext2" "${opts},noauto" >> "${imgroot}/etc/fstab"
}

cleanup() {
  umount "${imgroot}/boot"
  umount "${imgroot}"
}

provision() {
  # Bootloader
  uuid=$(lsblk -rno UUID /dev/vda2)
  sed -e "s|^root=|root=/dev/disk/by-uuid/${uuid}|" -i /etc/update-extlinux.conf
  dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of="${BLKDEV}"
  extlinux --install /boot
  update-extlinux -v
}

A sqmeta/files/etc/anemos.conf => sqmeta/files/etc/anemos.conf +9 -0
@@ 0,0 1,9 @@
ANEMOS_INITRAMFS_URL="https://anemos.io/initramfs/3.22/initramfs-anemos"
ANEMOS_KERNEL_URL="https://anemos.io/initramfs/3.22/vmlinuz-anemos"

ANEMOS_PAYLOAD_URL="file:///root/payload.tar.gz"

ANEMOS_EXEC="destructive"
ANEMOS_OVERWRITE_KERNEL="/boot/$(cat /proc/cmdline | tr ' ' '\n' | grep BOOT_IMAGE= | cut -c 12-)"
ANEMOS_OVERWRITE_INITRAMFS="$(echo "${ANEMOS_OVERWRITE_KERNEL}" | sed -e s/vmlinuz/initramfs/)"
ANEMOS_OVERWRITE_BACKUP_EXT="yes"

A sqmeta/files/etc/hostname => sqmeta/files/etc/hostname +1 -0
@@ 0,0 1,1 @@
sqmeta

A sqmeta/files/etc/network/interfaces => sqmeta/files/etc/network/interfaces +5 -0
@@ 0,0 1,5 @@
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp