Project

General

Profile

Download (3.67 KB) Statistics
| Branch: | Tag: | Revision:
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
(5-5/5)