-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuilder
executable file
·176 lines (138 loc) · 3.18 KB
/
builder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
#
umask 0022
pre()
{
workdir="`mktemp -d -t builder`" || exit 1
mount -o size=$((1<<30)) -t tmpfs tmpfs $workdir
}
post()
{
umount $workdir || true
rmdir $workdir
}
mk_kernel()
{
local _conf
make -s -C $src -j $jobs buildkernel KERNCONF=$kernconf KERNCONFDIR=$kernconfdir
make -s -C $src installkernel KERNCONF=$kernconf KERNCONFDIR=$kernconfdir DESTDIR=$workdir
for _conf in $conf; do
$pkgdir/helper $pkgdir/${_conf} $workdir $repo
done
}
mk_rescue()
{
local _conf
make -s -C $src/rescue
make -s -C $src hierarchy DESTDIR=$workdir > /dev/null
make -s -C $src/rescue install DESTDIR=$workdir
make -s -C $src/rescue clean
make -s -C $src/rescue cleandepend
cp /usr/local/sbin/pkg-static $workdir/rescue/pkg
for _conf in $conf; do
$pkgdir/helper $pkgdir/${_conf} $workdir $repo
done
}
mk_world()
{
local _conf
make -s -C $src -j $jobs buildworld
make -s -C $src installworld DESTDIR=$workdir
make -s -C $src distribution DESTDIR=$workdir
cp $workdir/etc/master.passwd $workdir/usr/share/examples/etc
cp /usr/local/sbin/pkg-static $workdir/rescue/pkg
for _conf in $conf; do
$pkgdir/helper $pkgdir/${_conf} $workdir $repo
done
}
mk_zoneinfo()
{
local _conf
make -s -C $src/share/zoneinfo
make -s -C $src hierarchy DESTDIR=$workdir > /dev/null
make -s -C $src/share/zoneinfo install DESTDIR=$workdir
make -s -C $src/share/zoneinfo clean
for _conf in $conf; do
$pkgdir/helper $pkgdir/${_conf} $workdir $repo
done
}
usage()
{
echo 1>&2 "usage: buidler [options] <kernel|rescue|world|zoneinfo>"
echo 1>&2 ""
echo 1>&2 " Options:"
echo 1>&2 " -c path List of configuration files"
echo 1>&2 " -j num Number of parallel jobs (default: number of CPUs)"
echo 1>&2 " -k path Path to kernel configuration file"
echo 1>&2 " -r path Path to pkgng repo"
echo 1>&2 " -s path Alternate path to src (default: /usr/src)"
echo 1>&2 ""
exit 1
}
if [ $# -lt 1 ]; then
usage
fi
kernel_conf="freebsd-kernel.conf freebsd-kernel-symbols.conf"
rescue_conf="freebsd-rescue.conf"
world_conf="freebsd-base.conf freebsd-lib32.conf freebsd-rescue.conf freebsd-zoneinfo.conf"
zoneinfo_conf="freebsd-zoneinfo.conf"
jobs="`sysctl -n hw.ncpu`"
src="/usr/src"
pkgdir="`dirname $0`" # XXX
while getopts "c:j:hk:r:s:" opt; do
case "$opt" in
c) conf="$OPTARG" ;;
j) jobs="$OPTARG" ;;
k) kernconf="$OPTARG" ;;
r) repo="$OPTARG" ;;
s) src="$OPTARG" ;;
*) usage ;;
esac
shift $(($OPTIND - 1))
done
if [ $# -ne 1 ]; then
usage
fi
target="$1"
if [ "$target" = "kernel" -a -z "${kernconf:-}" ]; then
echo 1>&2 "Please specify kernel config file"
exit 1
fi
if [ -z "${repo:-}" ]; then
echo 1>&2 "Please specify repo directory"
exit 1
fi
repo="`realpath $repo`"
if [ ! -d "$repo" -o ! -d "$repo/All" ]; then
echo 1>&2 "Please create \"$repo\" and \"$repo/All\""
exit 1
fi
set -eux
trap "post" EXIT
trap "exit 0" SIGINT
pre
case "$target" in
kernel)
kernconf="`realpath $kernconf`"
kernconfdir="`dirname $kernconf`"
kernconf="`basename $kernconf`"
: ${conf:=$kernel_conf}
mk_kernel
;;
rescue)
: ${conf:=$rescue_conf}
mk_rescue
;;
world)
: ${conf:=$world_conf}
mk_world
;;
zoneinfo)
: ${conf:=$zoneinfo_conf}
mk_zoneinfo
;;
*)
usage
;;
esac
pkg repo $repo