~sircmpwn/builds.sr.ht

builds.sr.ht/images/netbsd/functions -rw-r--r-- 2.0 KiB View raw
4a7a4327Drew DeVault Use joinedload on jobs page 3 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
#!/bin/sh
poweroff_cmd="sudo poweroff"
default_arch=amd64

boot() {
	case "$arch" in
		amd64)
			qemu=qemu-system-x86_64
			_boot $(cpu_opts x86_64)
			;;
		*)
			echo "Unsupported architecture $arch" >&2
			exit 1
			;;
	esac
}

pkgin_install() {
	port=$1
	shift 1
	guest_ssh -p $port build@localhost -- sudo pkgin -y update
	guest_ssh -p $port build@localhost -- sudo pkgin -y install "$@"
}

pkgsrc_install() {
	port=$1
	shift 1
	echo "Updating pkgsrc (this could take a while)..."
	guest_ssh -p $port build@localhost \
		"cd /usr/pkgsrc/ && sudo cvs update -dPp" >/dev/null 2>&1
	echo "Tip: want to speed up pkgsrc builds?" \
		"Consider installing dependencies via pkgin"
	for pkg in $@
	do
		# We use chronic to keep the noise to a minimum, because dear god, it
		# is noisy
		date
		echo "Building $pkg (logs hidden unless it fails - this could take a while)..."
		guest_ssh -p $port build@localhost -- \
			"cd /usr/pkgsrc/$pkg && sudo chronic make && sudo chronic make install"
		guest_ssh -p $port build@localhost -- \
			"cd /usr/pkgsrc/$pkg && sudo chronic make clean clean-depends"
		echo "Done."
		date
	done
}

install() {
	port=$1
	shift 1
	pkgin_pkgs=""
	pkgsrc_pkgs=""
	for pkg in $@
	do
		if [ -n "${pkg##*/*}" ]
		then
			pkgin_pkgs="$pkg $pkgin_pkgs"
		else
			pkgsrc_pkgs="$pkg $pkgsrc_pkgs"
		fi
	done
	if [ -n "${pkgin_pkgs%% }" ]
	then
		pkgin_install "$port" $pkgin_pkgs
	fi
	if [ -n "${pkgsrc_pkgs%% }" ]
	then
		pkgsrc_install "$port" $pkgsrc_pkgs
	fi
}

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 networking..."
	guest_ssh -p 8022 build@localhost curl https://example.org
	echo "Testing pkgin..."
	guest_ssh -p 8022 build@localhost sudo pkgin update
	guest_ssh -p 8022 build@localhost sudo pkgin -y install htop
	echo "Testing git..."
	guest_ssh -p 8022 build@localhost git --version
	echo "Everything works!"
	guest_ssh -p 8022 build@localhost sudo poweroff || true
}