1#!/bin/sh
2
3BASE_DIR="/var/buildmaster"
4SOURCE_DIR="/var/sources"
5
6if [ -z "$1" ]
7then
8	echo "usage: $0 <arch> [<secondaryArch1> [<secondaryArch2> ...]]"
9	echo ""
10	echo "This tool bootstraps a HaikuPorter buildmaster instance for the"
11	echo "specified architecture(s). It builds the needed tools and gets the"
12	echo "set of initial packages by building a Haiku image for the target"
13	echo "architecture. It then clones a HaikuPorts repository and configures"
14	echo "the ports tree and buildmaster."
15	exit 1
16fi
17
18set -e
19
20unset ARCH
21unset SECONDARY_ARCHS
22
23while [ $# -ne 0 ]
24do
25	case "$1" in
26		--*)
27			echo "Invalid option: \"$1\""
28			exit 1
29		;;
30
31		*)
32			if [ -z "$ARCH" ]
33			then
34				ARCH=$1
35			else
36				SECONDARY_ARCHS="$SECONDARY_ARCHS $1"
37			fi
38		;;
39	esac
40
41	shift
42done
43
44BUILDTOOLS_DIR=$SOURCE_DIR/buildtools
45HAIKU_DIR=$SOURCE_DIR/haiku
46GENERATED_DIR=$BASE_DIR/generated
47PORTS_DIR=$BASE_DIR/haikuports
48OUTPUT_DIR=$BASE_DIR/output
49BUILDERS_DIR=$PORTS_DIR/buildmaster/builders
50
51if [ -z "$ARCH" ]
52then
53	echo "No architecture specified"
54	exit 1
55fi
56
57if [ -z "$BASE_DIR" ]
58then
59	BASE_DIR=$(realpath "buildmaster_$ARCH")
60	echo "Using default base directory $BASE_DIR"
61else
62	echo "Using base directory $BASE_DIR"
63fi
64
65mkdir -p "$BASE_DIR"
66cd "$BASE_DIR"
67
68### Get HaikuPorts
69if [ ! -d "$PORTS_DIR" ]; then
70	echo "Cloning HaikuPorts repository to $PORTS_DIR"
71	git clone --depth=1 https://github.com/haikuports/haikuports "$PORTS_DIR"
72else
73	echo "Using existing HaikuPorts repository at $PORTS_DIR"
74fi
75
76### Get Haiku
77
78if [ ! -d "$HAIKU_DIR" ]; then
79	echo "Cloning Haiku repository to $HAIKU_DIR"
80	git clone --depth=1 https://review.haiku-os.org/haiku "$HAIKU_DIR"
81else
82	echo "Using existing Haiku repository at $HAIKU_DIR"
83fi
84
85# Configure the ports tree.
86
87cd "$PORTS_DIR"
88echo "Configuring ports tree"
89
90echo "TREE_PATH=\"$PORTS_DIR\"" > haikuports.conf
91echo "LICENSES_DIRECTORY=\"$HAIKU_DIR/data/system/data/licenses\"" \
92	>> haikuports.conf
93echo "PACKAGE_COMMAND=\"package\"" >> haikuports.conf
94echo "PACKAGE_REPO_COMMAND=\"package_repo\"" >> haikuports.conf
95echo "PACKAGER=\"buildmaster $ARCH$SECONDARY_ARCHS" \
96		"<buildmaster@haiku-os.org>\"" >> haikuports.conf
97echo "TARGET_ARCHITECTURE=\"$ARCH\"" >> haikuports.conf
98if [ ! -z "$SECONDARY_ARCHS" ]
99then
100	echo "SECONDARY_TARGET_ARCHITECTURES=\"$SECONDARY_ARCHS\"" \
101		>> haikuports.conf
102fi
103
104# Create some buildmaster paths
105mkdir -p $OUTPUT_DIR
106mkdir -p $BUILDERS_DIR
107
108# Done.
109
110echo ""
111echo "Buildmaster instance bootstrapped in $BASE_DIR."
112echo ""
113echo "Next Steps:"
114echo "  * Prepare a set of system-packages, place in $BASE_DIR/system-packages/<branch>"
115echo "  * Use createbuilder to generate builder configurations"
116echo "  * Switch container to 'loop' to enter monitoring loop"
117