Skip to content

Commit 336f023

Browse files
committed
Merge remote-tracking branch 'origin/main' into development
2 parents 1a2805c + 19b2293 commit 336f023

8 files changed

Lines changed: 200 additions & 51 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.*.swp
33
old/
44
output/
5+
/system*.json

‎image-factory/start.sh‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,30 @@ if [[ ! -f "${CONFIG_PATH}" ]]; then
4949
exit 1
5050
fi
5151

52-
VERSION="${2:-"latest"}"
53-
BUILDER_IMAGE="cuos-image-factory"
52+
OS_VERSION="${2:-"$(jq -r '.os_image_version // "latest"' "${CONFIG_PATH}")"}"
53+
54+
UPDATE_REGISTRY="$(jq -r '.update_registry' "${CONFIG_PATH}")"
55+
OS_IMAGE="cuos-image-factory"
56+
OS_IMAGE_DIGEST="$(jq -r '.os_image_digest // empty' "${CONFIG_PATH}")"
5457

5558

5659
dockerlogin
5760

5861
if [[ "${VERSION}" == "build" ]]; then
59-
IMAGE="dockerboot_imagebuilder"
60-
docker build -f "Dockerfile" -t "${IMAGE}" .. \
62+
IMAGE_VERSION="cuos_imagebuilder"
63+
docker build -f "Dockerfile" -t "${IMAGE_VERSION}" .. \
6164
|| raise "Failed to build image"
6265
else
63-
IMAGE="${UPDATE_REGISTRY}${BUILDER_IMAGE}:${VERSION}"
64-
docker image pull "${IMAGE}" \
66+
IMAGE_VERSION="${UPDATE_REGISTRY}${OS_IMAGE}:${OS_VERSION}"
67+
docker image pull "${IMAGE_VERSION}" \
6568
|| raise "Faild to fetch image"
6669
fi
6770

68-
touch "${HOME}/.docker/config.json"
71+
touch "${HOME}/.docker/config.json" 2>/dev/null
6972
docker run --rm \
7073
--pull=never \
71-
--network=host \
7274
--privileged \
7375
-v "${HOME}/.docker/config.json":/root/.docker/config.json:ro \
7476
-v "${SCRIPT_DIR}/../output/:/output/" \
75-
--name dockerboot-imagebuilder-container \
76-
"${IMAGE}"
77+
--name cuos-imagebuilder-container \
78+
"${IMAGE_VERSION}"

‎installer/Dockerfile‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
FROM debian:trixie-slim
22

3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV container=docker
5+
36
# Set entrypoint to the ISO creation script
47
ENTRYPOINT ["/create_iso.sh"]
58

6-
# Install required packages
7-
RUN apt-get update && apt-get install -y \
9+
RUN apt-get update && apt-get install --no-install-recommends -y \
810
initramfs-tools \
9-
linux-image-amd64 \
10-
xorriso \
11-
syslinux \
12-
isolinux \
13-
grub-pc-bin \
11+
zstd \
12+
&& echo "btrfs" >>/etc/initramfs-tools/modules \
13+
&& echo "ahci" >>/etc/initramfs-tools/modules \
14+
&& echo "nvme" >>/etc/initramfs-tools/modules \
15+
&& echo "sd_mod" >>/etc/initramfs-tools/modules \
16+
&& echo "sdhci" >>/etc/initramfs-tools/modules \
17+
&& echo "sdhci_pci" >>/etc/initramfs-tools/modules \
18+
&& echo "usb_storage" >>/etc/initramfs-tools/modules \
19+
&& echo "mmc_block" >>/etc/initramfs-tools/modules \
20+
&& echo "mmc_core" >>/etc/initramfs-tools/modules \
21+
&& echo "sr_mod" >>/etc/initramfs-tools/modules \
22+
&& echo "microcode" >>/etc/initramfs-tools/modules \
23+
&& echo "RESUME=none" >>/etc/initramfs-tools/conf.d/resume \
24+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
25+
26+
27+
# Install required packages
28+
RUN apt-get update && apt-get install --no-install-recommends -y \
29+
btrfs-progs \
30+
busybox \
31+
cpio \
32+
dialog \
33+
dosfstools \
34+
grub-common \
1435
grub-efi-amd64-bin \
36+
grub-pc-bin \
37+
kmod \
1538
mtools \
16-
dosfstools \
17-
cpio \
18-
busybox \
19-
&& rm -rf /var/lib/apt/lists/*
39+
isolinux \
40+
linux-image-amd64 \
41+
selinux-policy-default \
42+
syslinux \
43+
xorriso \
44+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
2045

2146
COPY create_iso.sh /
47+
COPY cuos-installer /etc/initramfs-tools/scripts/init-premount/cuos-installer
48+
COPY hooks-cuos-installer /etc/initramfs-tools/hooks/cuos-installer

‎installer/create_iso.sh‎

100644100755
Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
set -e
3+
set -x
34

45
# Define paths
56
WORKDIR="/build"
@@ -13,9 +14,10 @@ if [[ ! -d "${OUTPUT_DIR}" ]]; then
1314
fi
1415

1516

17+
rm -f "${OUTPUT_DIR}/installer.iso"
18+
1619
# Prepare initramfs-tools config
1720
mkdir -p "/etc/initramfs-tools/conf.d"
18-
mkdir -p "/usr/share/initramfs-tools/scripts/init-bottom"
1921

2022
# Add required modules
2123
cat <<EOF >"/etc/initramfs-tools/modules"
@@ -35,24 +37,17 @@ EOF
3537
# Disable resume
3638
echo "RESUME=none" > "/etc/initramfs-tools/conf.d/resume"
3739

38-
# Add custom installer script
39-
cat <<'EOF' > "/etc/initramfs-tools/scripts/init-premount/cuos-installer"
40-
#!/bin/sh
41-
echo "Running custom installer..."
42-
# Your install logic here
43-
sleep 5
44-
reboot
45-
46-
EOF
47-
chmod +x "/etc/initramfs-tools/scripts/init-premount/cuos-installer"
40+
mkdir -p "${WORKDIR}" "${ISO_DIR}"
4841

4942
# Build initrd.img
50-
mkinitramfs -o "${INITRD_IMAGE}"
43+
KVER="$(basename /lib/modules/* | head -n1)"
44+
mkinitramfs -o "${INITRD_IMAGE}" "${KVER}"
5145

5246
# Prepare ISO directory
5347
mkdir -p "${ISO_DIR}/boot/grub"
5448
cp "/boot/vmlinuz"-* "${ISO_DIR}/boot/vmlinuz"
5549
cp "${INITRD_IMAGE}" "${ISO_DIR}/boot/initrd.img"
50+
cp "/output/image.img" "${ISO_DIR}"
5651

5752
# Create grub config
5853
cat <<EOF >"${ISO_DIR}/boot/grub/grub.cfg"
@@ -65,20 +60,13 @@ menuentry "CuOS Installer" {
6560
}
6661
EOF
6762

68-
# Build hybrid ISO
69-
xorriso -as mkisofs \
63+
64+
VOLID="CUOS"
65+
grub-mkrescue \
66+
-o "${OUTPUT_DIR}/installer.iso" \
67+
-V "${VOLID}" \
7068
-iso-level 3 \
7169
-full-iso9660-filenames \
72-
-volid "CuOSInstaller" \
73-
-output "${OUTPUT_DIR}/installer.iso" \
74-
-eltorito-boot boot/grub/i386-pc/eltorito.img \
75-
-no-emul-boot -boot-load-size 4 -boot-info-table \
76-
-eltorito-catalog boot/grub/boot.cat \
77-
-eltorito-alt-boot \
78-
-e --interval:appended_partition_2:all:: \
79-
-no-emul-boot \
80-
-append_partition 2 0xef "${ISO_DIR}/boot/grub/efi.img" \
81-
-isohybrid-gpt-basdat \
82-
-isohybrid-apm-hfsplus \
83-
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
8470
"${ISO_DIR}"
71+
72+

‎installer/cuos-installer‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/sh
2+
3+
case "$1" in
4+
prereqs)
5+
echo ""
6+
exit 0
7+
;;
8+
esac
9+
10+
# shellcheck source=/dev/null
11+
. /scripts/functions
12+
13+
echo "Running custom installer..."
14+
#dialog --msgbox Hallo 10 40
15+
16+
17+
IMAGE="/image.img"
18+
19+
# Collect disks: TYPE=disk, RO=0
20+
DISKS=""
21+
while read -r name type ro size model; do
22+
[ "$type" = "disk" ] || continue
23+
[ "$ro" = "0" ] || continue
24+
safe_model=$(echo "$model" | tr ' ' '_')
25+
label="${size}_${safe_model}"
26+
DISKS="$DISKS $name $label off"
27+
done <<INNEREOF
28+
$(lsblk -dn -o NAME,TYPE,RO,SIZE,MODEL)
29+
INNEREOF
30+
31+
COUNT=$(echo "$DISKS" | wc -w)
32+
# Each disk adds 3 words (name label off), so count/3
33+
COUNT=$((COUNT / 3))
34+
35+
if [ "$COUNT" -eq 0 ]; then
36+
dialog --clear --backtitle "Installer" \
37+
--title "Error" \
38+
--msgbox "No writable disks found" 20 40
39+
reboot -f
40+
exit 1
41+
fi
42+
43+
#if [ "$COUNT" -eq 1 ]; then
44+
# TARGET=$(echo "$DISKS" | awk '{print $1}')
45+
#else
46+
# shellcheck disable=SC2086
47+
CHOICE=$(dialog --clear --backtitle "Installer" \
48+
--title "Select Target Disk" \
49+
--radiolist "Select disk to overwrite:" 20 70 10 \
50+
$DISKS 3>&1 1>&2 2>&3)
51+
clear
52+
TARGET="$CHOICE"
53+
#fi
54+
55+
if [ -z "$TARGET" ]; then
56+
dialog --clear --backtitle "Installer" \
57+
--title "Error" \
58+
--msgbox "No disk selected" 20 40
59+
reboot -f
60+
exit 1
61+
fi
62+
63+
wait_for_udev 10
64+
65+
iso_label="CUOS"
66+
iso_dev=""
67+
if [ -e "/dev/disk/by-label/$iso_label" ]; then
68+
iso_dev="/dev/disk/by-label/$iso_label"
69+
else
70+
# Fallback: try /dev/sr0 or the first iso9660 device
71+
[ -b /dev/sr0 ] && iso_dev="/dev/sr0"
72+
[ -z "$iso_dev" ] && iso_dev="$(blkid -t TYPE=iso9660 -o device | head -n1)"
73+
fi
74+
75+
if [ -z "$iso_dev" ]; then
76+
echo "iso-img: ERROR: Could not locate ISO device (label=$iso_label)" >&2
77+
exit 0
78+
fi
79+
80+
mkdir -p /cdrom
81+
if ! mount -t iso9660 -o ro "$iso_dev" /cdrom; then
82+
echo "iso-img: ERROR: mount ISO failed: $iso_dev" >&2
83+
exit 0
84+
fi
85+
86+
# Loop-mount the embedded image (read-only by default)
87+
if [ ! -e "/cdrom$IMAGE" ]; then
88+
echo "iso-img: WARNING: /cdrom$IMAGE not found" >&2
89+
exit 0
90+
fi
91+
92+
echo "Writing $IMAGE to /dev/$TARGET... (this may take a while)"
93+
dd if="/cdrom$IMAGE" of="/dev/$TARGET" bs=4M iflag=fullblock
94+
sync
95+
echo "Done."
96+
97+
#sh
98+
99+
reboot -f
100+

‎installer/hooks-cuos-installer‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
case "${1:-}" in
4+
prereqs) echo ""; exit 0;;
5+
esac
6+
7+
[ -r /usr/share/initramfs-tools/hook-functions ] || exit 0
8+
# shellcheck source=/dev/null
9+
. /usr/share/initramfs-tools/hook-functions
10+
11+
copy_exec /usr/bin/dialog
12+
copy_exec /usr/bin/lsblk
13+
14+
mkdir -p "$DESTDIR/usr/share/terminfo/l/"
15+
cp -p /usr/share/terminfo/l/linux "$DESTDIR/usr/share/terminfo/l/linux"
16+
17+

‎installer/shell.sh‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
docker build -t minimal-installer . || exit "$?"
4+
docker run --rm \
5+
-it \
6+
-v "$(pwd)/output:/output" \
7+
--entrypoint /bin/bash \
8+
minimal-installer

‎installer/start.sh‎

100644100755
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/bin/bash
22

3-
docker build -t minimal-installer .
3+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
4+
5+
if [[ "${1:-}" != "" ]]; then
6+
"${SCRIPT_DIR}/../image-factory/start.sh" "$@" || exit "$?"
7+
fi
8+
9+
docker build -t minimal-installer . || exit "$?"
410
docker run --rm \
5-
-v "$(pwd)/output:/output" \
6-
minimal-installer
11+
-v "${SCRIPT_DIR}/../output/:/output/" \
12+
minimal-installer || exit "$?"
713

8-
echo "ISO created at ./output/installer.iso"
14+
echo "ISO created at ../output/installer.iso"
915

0 commit comments

Comments
 (0)