diff options
Diffstat (limited to 'images/debian/functions')
| -rw-r--r-- | images/debian/functions | 106 | +106 −0 |
1 files changed, 106 insertions, 0 deletions
diff --git a/images/debian/functions b/images/debian/functions new file mode 100644 --- /dev/null +++ b/images/debian/functions @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2017-2026 Drew DeVault +# SPDX-License-Identifier: AGPL-3.0-only + +poweroff_cmd="sudo systemctl poweroff" +default_arch=amd64 + +boot() { + case "$arch" in + amd64) + qemu=qemu-system-x86_64 + _boot $(cpu_opts x86_64) + ;; + arm64) + driveopts="id=root,if=none" + qemu=qemu-system-aarch64 + _boot \ + $(cpu_opts aarch64) \ + -device virtio-blk-pci,drive=root \ + -kernel "$wd/$arch/vmlinuz" \ + -initrd "$wd/$arch/initrd.img" \ + -append "root=/dev/vda3" + ;; + ppc64el) + driveopts="id=root,if=none" + qemu=qemu-system-ppc64 + _boot \ + $(cpu_opts ppc64le) \ + -device virtio-blk-pci,drive=root \ + -kernel "$wd/$arch/vmlinux" \ + -initrd "$wd/$arch/initrd.img" \ + -append "root=/dev/vda3" + ;; + *) + echo "Unsupported architecture $arch" >&2 + exit 1 + ;; + esac +} + +install() { + port=$1 + shift 1 + guest_ssh -p $port build@localhost sudo env DEBIAN_FRONTEND=noninteractive \ + apt-get update -y + guest_ssh -p $port build@localhost sudo env DEBIAN_FRONTEND=noninteractive \ + apt-get install -y "$@" +} + +add_repository() { + port=$1 + name=$2 + src=$3 + repo=$(echo $src | cut -d' ' -f1) + distro=$(echo $src | cut -d' ' -f2) + cmpnt=$(echo $src | cut -d' ' -f3) + key=$(echo $src | cut -d' ' -f4) + signed_by="" + if [ "$key" != "" ] + then + # Import the GPG key into a user trustdb + guest_ssh -p $port build@localhost sudo \ + gpg \ + --keyserver hkp://keyserver.ubuntu.com:80 \ + --recv-keys $key + + guest_ssh -p $port build@localhost sudo \ + mkdir -pm 0755 /etc/apt/keyrings + + # Export the GPG key to Apt's key directory + guest_ssh -p $port build@localhost sudo \ + gpg \ + --output /etc/apt/keyrings/$name.gpg \ + --export $key + + signed_by="[signed-by=/etc/apt/keyrings/$name.gpg]" + fi + printf 'deb %s %s %s %s\n' "$signed_by" "$repo" "$distro" "$cmpnt" \ + | guest_ssh -p $port build@localhost sudo tee -a /etc/apt/sources.list.d/$name.list + printf 'deb-src %s %s %s %s\n' "$signed_by" "$repo" "$distro" "$cmpnt" \ + | guest_ssh -p $port build@localhost sudo tee -a /etc/apt/sources.list.d/$name.list + guest_ssh -p "$port" build@localhost sudo apt-get update +} + +sanity_check() { + arch=$1 + shift + + echo "Booting..." + cmd_boot "$arch" 8022 qemu & + trap 'cmd_cleanup 8022' EXIT + _wait_boot 8022 + echo "Testing sudo..." + guest_ssh -p 8022 build@localhost sudo ls -a + echo "Testing apt..." + guest_ssh -p 8022 build@localhost sudo apt-get update + install 8022 curl + echo "Testing networking..." + guest_ssh -p 8022 build@localhost curl https://builds.sr.ht + echo "Testing git..." + guest_ssh -p 8022 build@localhost git --version + echo "Testing mercurial..." + guest_ssh -p 8022 build@localhost hg --version + echo "Everything works!" + guest_ssh -p 8022 build@localhost sudo systemctl poweroff || true +} |
