Project

General

Profile

Download (3.94 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-2013 BSD Perimeter
7
# Copyright (c) 2013-2016 Electric Sheep Fencing
8
# Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
# All rights reserved.
10
#
11
# Licensed under the Apache License, Version 2.0 (the "License");
12
# you may not use this file except in compliance with the License.
13
# You may obtain a copy of the License at
14
#
15
# http://www.apache.org/licenses/LICENSE-2.0
16
#
17
# Unless required by applicable law or agreed to in writing, software
18
# distributed under the License is distributed on an "AS IS" BASIS,
19
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
# See the License for the specific language governing permissions and
21
# limitations under the License.
22

    
23
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
24

    
25
scripts_path=$(dirname $(realpath $0))
26

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

    
32
. ${scripts_path}/common.subr
33

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

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

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

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

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

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

    
104
# Default obj dir to src/../obj
105
: ${objdir=${srcdir}/../obj}
106

    
107
[ -n "$objdir" -a -e "$objdir" -a ! -d "$objdir" ] \
108
	&& err "obj path already exists and is not a directory"
109

    
110
[ -z "$srcdir" ] \
111
	&& err "source directory is not defined"
112

    
113
[ -e $srcdir -a ! -d $srcdir ] \
114
	&& err "source path already exists and is not a directory"
115

    
116
[ -z "$destdir" ] \
117
	&& err "destination directory is not defined"
118

    
119
[ -e $destdir -a ! -d $destdir ] \
120
	&& err "destination path already exists and is not a directory"
121

    
122
for env_var in __MAKE_CONF SRCCONF SRC_ENV_CONF; do
123
	eval "value=\${$env_var}"
124
	[ -n "${value}" -a ! -f "${value}" ] \
125
		&& err "${env_var} is pointing to a nonexistent file ${value}"
126
done
127

    
128
[ ! -f ${srcdir}/sys/sys/param.h ] \
129
	&& err "Source directory is missing sys/sys/param.h"
130

    
131
ncpu=$(sysctl -qn hw.ncpu)
132
njobs=$((ncpu*2))
133
j="-j${njobs}"
134

    
135
[ -n "${objdir}" ] \
136
	&& export MAKEOBJDIRPREFIX=${objdir}
137

    
138
if [ -n "${installation_media}" ]; then
139
	export WITHOUT_RESCUE=yes
140
else
141
	export WITHOUT_BSDINSTALL=yes
142
fi
143

    
144
export DESTDIR=${destdir}
145

    
146
make_cmd="make -C ${srcdir} -s ${j}"
147

    
148
[ -z "${skip_world}" ] \
149
	&& run "Installing world" \
150
		"${make_cmd} installworld"
151

    
152
if [ -z "${skip_kernel}" ]; then
153
	run "Installing kernel" \
154
		"${make_cmd} KERNCONF=${KERNCONF:-pfSense} installkernel"
155

    
156
	[ -n "${gzip_kernel}" ] \
157
		&& run "Compressing kernel" \
158
			"gzip -f9 ${destdir}/boot/kernel/kernel"
159
fi
160

    
161
[ -z "${skip_distribution}" ] \
162
	&& run "Installing distribution" \
163
		"${make_cmd} distribution"
164

    
165
[ -n "${installation_media}" ] \
166
	&& run "Copying /etc/rc.local to start bsdinstall" \
167
		"cp ${srcdir}/release/rc.local ${destdir}/etc"
168

    
169
exit 0
(5-5/5)