DEVELOPMENT ENVIRONMENT

~liljamo/src.quest-anemos

src.quest-anemos/sqmeta/IMGBUILD -rw-r--r-- 1.7 KiB
1a58233cJonni Liljamo feat: persistent disk 7 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
imgname=sqmeta
target=alpine
format="custom"

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

  lsblk

  zstd
  curl

  openssh
  qemu-guest-agent
  ufw
"

services="
  networking:boot
  sshd
  qemu-guest-agent
  ufw
"

passwords="
  root:+pw_root_enc
"

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)
  echo "UUID=$uuidr / ext4 $opts 0 1" > "${imgroot}/etc/fstab"
  opts=$(findmnt -no OPTIONS /dev/vda1)
  echo "UUID=$uuidb /boot ext2 $opts,noauto 0 2" >> "${imgroot}/etc/fstab"

  # Persistent partition, see README
  echo "UUID=1ad73c24-2a0b-42a7-83e9-12e2dc3d2ef1 /mnt/persistent ext4 rw,relatime 0 2" >> "${imgroot}/etc/fstab"
}

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

provision() {
  case "$format" in
  "custom")
    # Bootloader
    echo "Setting up 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
    ;;
  *)
    echo "Not setting up bootloader"
    ;;
  esac

  # Create persistent mount directory
  mkdir -p /mnt/persistent

  ufw default deny incoming
  ufw limit SSH
  ufw enable
}