~sircmpwn/builds.sr.ht

builds.sr.ht/images/debian/functions -rw-r--r-- 2.2 KiB
c2e5cf82Simon Ser contrib/crontab: add freebsd/13.x job 4 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
#!/usr/bin/env bash
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)
	if [ "$key" != "" ]
	then
		guest_ssh -p $port build@localhost sudo \
			apt-key adv \
			--keyserver hkp://keyserver.ubuntu.com:80 \
			--recv-keys $key
	fi
	printf 'deb %s %s %s\n' "$repo" "$distro" "$cmpnt" \
		| guest_ssh -p $port build@localhost sudo tee -a /etc/apt/sources.list
	printf 'deb-src %s %s %s\n' "$repo" "$distro" "$cmpnt" \
		| guest_ssh -p $port build@localhost sudo tee -a /etc/apt/sources.list
	guest_ssh -p "$port" build@localhost sudo apt-get update
}

sanity_check() {
	echo "Booting..."
	cmd_boot amd64 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://example.org
	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
}