Project

General

Profile

Download (3.85 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 Rubicon Communications, LLC (Netgate)
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         -- Install system for installation media
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 installation_media
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
			installation_media=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
[ -z "$srcdir" ] \
97
	&& err "source directory is not defined"
98

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

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

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

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

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

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

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

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

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

    
129
ncpu=$(sysctl -n hw.ncpu)
130
njobs=$((ncpu*2))
131
j="-j${njobs}"
132

    
133
[ -n "${objdir}" ] \
134
	&& export MAKEOBJDIRPREFIX=${objdir}
135

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

    
142
export DESTDIR=${destdir}
143

    
144
make_cmd="make -C ${srcdir} -s ${j}"
145

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

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

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

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

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

    
167
exit 0
(5-5/5)