Project

General

Profile

« Previous | Next » 

Revision 468f236d

Added by Renato Botelho almost 9 years ago

Add install_freebsd.sh and use it

View differences:

build/scripts/install_freebsd.sh
1
#!/bin/sh
2
#
3
# install_freebsd.sh
4
#
5
# part of pfSense (https://www.pfsense.org)
6
# Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
# All rights reserved.
8
#
9
# Licensed under the Apache License, Version 2.0 (the "License");
10
# you may not use this file except in compliance with the License.
11
# You may obtain a copy of the License at
12
#
13
# http://www.apache.org/licenses/LICENSE-2.0
14
#
15
# Unless required by applicable law or agreed to in writing, software
16
# distributed under the License is distributed on an "AS IS" BASIS,
17
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
# See the License for the specific language governing permissions and
19
# limitations under the License.
20

  
21
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
22

  
23
scripts_path=$(dirname $(realpath $0))
24

  
25
if [ ! -f "${scripts_path}/common.subr" ]; then
26
	echo >&2 "ERROR: common.subr is missing"
27
	exit 1
28
fi
29

  
30
. ${scripts_path}/common.subr
31

  
32
usage() {
33
	cat >&2 <<END
34
Usage: $(basename $0) -s srcdir -d destdir [-o objdir] [-iWKDhz]
35

  
36
Options:
37
	-s srcdir  -- Path to src directory
38
	-d destdir -- Destination directory to install
39
	-o objdir  -- Obj directory used to build
40
	-i         -- Include BSDInstall
41
	-W         -- Skip installworld
42
	-K         -- Skip installkernel
43
	-D         -- Skip distribution
44
	-h         -- Show this help and exit
45
	-z         -- gzip kernel
46

  
47
Environment:
48
	__MAKE_CONF      -- Path to make.conf
49
	SRCCONF          -- Path to src.conf
50
	SRC_ENV_CONF     -- Path to src-env.conf
51
	KERNCONF         -- Kernel names
52
	MODULES_OVERRIDE -- List of kernel modules to install
53
	TARGET           -- Machine hardware name
54
	TARGET_ARCH      -- Machine processor arquitecture name
55
END
56
	exit 1
57
}
58

  
59
unset with_bsdinstall
60
unset skip_world
61
unset skip_kernel
62
unset skip_distribution
63
unset gzip_kernel
64
while getopts s:d:o:iWKDhz opt; do
65
	case "$opt" in
66
		s)
67
			srcdir=$OPTARG
68
			;;
69
		d)
70
			destdir=$OPTARG
71
			;;
72
		o)
73
			objdir=$OPTARG
74
			;;
75
		i)
76
			with_bsdinstall=1
77
			;;
78
		W)
79
			skip_world=1
80
			;;
81
		K)
82
			skip_kernel=1
83
			;;
84
		D)
85
			skip_distribution=1
86
			;;
87
		z)
88
			gzip_kernel=1
89
			;;
90
		*)
91
			usage
92
			;;
93
	esac
94
done
95

  
96
# Default obj dir to src/../obj
97
: ${objdir=$(realpath ${srcdir}../obj)}
98

  
99
[ -z "$srcdir" ] \
100
	&& err "source directory is not defined"
101

  
102
[ -e $srcdir -a ! -d $srcdir ] \
103
	&& err "source path already exists and is not a directory"
104

  
105
[ -z "$destdir" ] \
106
	&& err "destination directory is not defined"
107

  
108
[ -e $destdir -a ! -d $destdir ] \
109
	&& err "destination path already exists and is not a directory"
110

  
111
[ -n "$objdir" -a -e $objdir -a ! -d $objdir ] \
112
	&& err "obj path already exists and is not a directory"
113

  
114
for env_var in __MAKE_CONF SRCCONF SRC_ENV_CONF; do
115
	eval "value=\${$env_var}"
116
	[ -n "${value}" -a ! -f "${value}" ] \
117
		&& err "${env_var} is pointing to a nonexistent file ${value}"
118
done
119

  
120
[ ! -f ${srcdir}/sys/sys/param.h ] \
121
	&& err "Source directory is missing sys/sys/param.h"
122

  
123
ncpu=$(sysctl -n hw.ncpu)
124
njobs=$((ncpu*2))
125
j="-j${njobs}"
126

  
127
[ -n "${objdir}" ] \
128
	&& export MAKEOBJDIRPREFIX=${objdir}
129

  
130
[ -z "${with_bsdinstall}" ] \
131
	&& export WITHOUT_BSDINSTALL=yes
132

  
133
[ -d $destdir ] \
134
	&& force_rm ${destdir}
135

  
136
export DESTDIR=${destdir}
137

  
138
make_cmd="make -C ${srcdir} -s ${j}"
139

  
140
[ -z "${skip_world}" ] \
141
	&& run "Installing world" \
142
		"${make_cmd} installworld"
143

  
144
if [ -z "${skip_kernel}" ]; then
145
	run "Installing kernel" \
146
		"${make_cmd} KERNCONF=${KERNCONF:-pfSense} installkernel"
147

  
148
	[ -n "${gzip_kernel}" ] \
149
		&& run "Compressing kernel" \
150
			"gzip -f9 ${destdir}/boot/kernel/kernel"
151
fi
152

  
153
[ -z "${skip_distribution}" ] \
154
	&& run "Installing distribution" \
155
		"${make_cmd} distribution"
156

  
157
[ -n "${with_bsdinstall}" ] \
158
	&& run "Copying /etc/rc.local to start bsdinstall" \
159
		"cp ${srcdir}/release/rc.local ${destdir}/etc"
160

  
161
exit 0
tools/builder_common.sh
326 326
	[ -d "${INSTALLER_CHROOT_DIR}" ] \
327 327
		|| mkdir -p ${INSTALLER_CHROOT_DIR}
328 328

  
329
	makeargs="${MAKEJ} DESTDIR=${INSTALLER_CHROOT_DIR}"
330
	echo ">>> Installing world for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
331
	echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} installworld" | tee -a ${LOGFILE}
332
	(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} installworld || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
333
	cp ${FREEBSD_SRC_DIR}/release/rc.local ${INSTALLER_CHROOT_DIR}/etc
334
	echo ">>> Installing world for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
335

  
336
	echo ">>> Distribution world for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
337
	echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} distribution " | tee -a ${LOGFILE}
338
	(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} distribution  || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
339
	echo ">>> Distribution world for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
340

  
341
	makeargs="${MAKEJ} WITHOUT_BSDINSTALL=1 DESTDIR=${STAGE_CHROOT_DIR}"
342
	echo ">>> Installing world for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
343
	echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} installworld" | tee -a ${LOGFILE}
344
	(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} installworld || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
345
	echo ">>> Installing world for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
346

  
347
	echo ">>> Distribution world for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
348
	echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} distribution " | tee -a ${LOGFILE}
349
	(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} distribution  || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
350
	echo ">>> Distribution world for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
329
	echo ">>> Installing world with bsdinstall for ${TARGET} architecture..." | tee -a ${LOGFILE}
330
	script -aq $LOGFILE ${SCRIPTS_DIR}/install_freebsd.sh -i -K \
331
		-s ${FREEBSD_SRC_DIR} \
332
		-d ${INSTALLER_CHROOT_DIR} \
333
		|| print_error_pfS
334

  
335
	echo ">>> Installing world without bsdinstall for ${TARGET} architecture..." | tee -a ${LOGFILE}
336
	script -aq $LOGFILE ${SCRIPTS_DIR}/install_freebsd.sh -K \
337
		-s ${FREEBSD_SRC_DIR} \
338
		-d ${STAGE_CHROOT_DIR} \
339
		|| print_error_pfS
351 340

  
341
	# XXX It must go to the scripts
352 342
	[ -d "${STAGE_CHROOT_DIR}/usr/local/bin" ] \
353 343
		|| mkdir -p ${STAGE_CHROOT_DIR}/usr/local/bin
354
	makeargs="${MAKEJ} DESTDIR=${STAGE_CHROOT_DIR}"
344
	makeargs="DESTDIR=${STAGE_CHROOT_DIR}"
355 345
	echo ">>> Building and installing crypto tools and athstats for ${TARGET} architecture... (Starting - $(LC_ALL=C date))" | tee -a ${LOGFILE}
356
	echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/crypto ${makeargs} clean all install " | tee -a ${LOGFILE}
357 346
	(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/crypto ${makeargs} clean all install || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
358 347
	# XXX FIX IT
359
#	echo ">>> Builder is running the command: script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/ath/athstats ${makeargs} clean all install" | tee -a ${LOGFILE}
360 348
#	(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR}/tools/tools/ath/athstats ${makeargs} clean all install || print_error_pfS;) | egrep '^>>>' | tee -a ${LOGFILE}
361 349
	echo ">>> Building and installing crypto tools and athstats for ${TARGET} architecture... (Finished - $(LC_ALL=C date))" | tee -a ${LOGFILE}
362 350

  
......
1616 1604
	fi
1617 1605

  
1618 1606
	mkdir -p ${STAGE_CHROOT_DIR}/boot
1619
	makeargs="${MAKEJ} DESTDIR=${_destdir}"
1620
	echo ">>> Builder is running the command: script -aq $LOGFILE make ${makeargs} installkernel KERNCONF=${KERNCONF}"  | tee -a $LOGFILE
1621
	(script -aq $LOGFILE make -C ${FREEBSD_SRC_DIR} ${makeargs} installkernel KERNCONF=${KERNCONF} || print_error_pfS;) | egrep '^>>>'
1622
	gzip -f9 ${_destdir}/boot/kernel/kernel
1607
	echo ">>> Installing kernel (${KERNCONF}) for ${TARGET} architecture..." | tee -a ${LOGFILE}
1608
	script -aq $LOGFILE ${SCRIPTS_DIR}/install_freebsd.sh -W -D -z \
1609
		-s ${FREEBSD_SRC_DIR} \
1610
		-d ${_destdir} \
1611
		|| print_error_pfS
1623 1612
}
1624 1613

  
1625 1614
# Launch is ran first to setup a few variables that we need

Also available in: Unified diff