-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpac-build.in
executable file
·239 lines (212 loc) · 5.88 KB
/
pac-build.in
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env bash
# Copyright (c) 2013 PacBSD Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
mydir=`dirname "$(readlink -f $0)"`/library
libdir=${libdir:-${mydir}}
die() {
echo "$@"
exit 1
}
# some defaults, can be overwritten in the config
opt_zfs=0
opt_jail=0
opt_ports=0
opt_mountfs=()
source "${libdir}"/pac-build.build.sh || die "failed to load library file"
source "${libdir}"/pac-build.cmdline.sh || die "failed to load library file"
source "${libdir}"/pac-build.conf.sh || die "failed to load library file"
source "${libdir}"/pac-build.package.sh || die "failed to load library file"
source "${libdir}"/pac-build.zfs.sh || die "failed to load library file"
load_config
opt_install=()
opt_confirm=--noconfirm
cmd_usage="[options] <repo> <package>"
cmd_options=(
"h help show this help"
"k kill remove the build dir and quit"
"n noclean don't clean the build dir (useful for continuing)"
"x existing use the existing build dir instead of reinstalling"
"y nosync don't sync the repositories via pacman -Sy"
"u update update an existing chroot"
"C noconfirm do not use the --noconfirm option on commands"
"s usershell open a shell in the chroot as builder"
"S rootshell open a shell in the chroot as root"
"R repackage add -R to makepkg"
"e keepbuild pass -e to makepkg (keeping previous pkg/ and src/ dirs intact)"
"L kill_ld remove ld-elf.so.hints before trying to chroot"
"Z zfs use an existing ZFS base"
"M mountonly only mount the ZFS base and quit"
"P noprepare do not run the prepare script"
"p ports Build package using ports"
"i:PKG addpkg install this package before building (NOT recommended)"
"m:MNT mount mount additional standard filesystems such as proc"
"a:PROF prof select a build profile"
"o:OPT addopt add a makepkg option"
)
cmdopt_addpkg() {
opt_install+=("$OPTARG")
}
cmdopt_mount() {
opt_mountfs+=(${OPTARG//,/ })
}
cmdopt_prof() {
build_profile="$OPTARG"
}
cmdopt_noconfirm() {
opt_confirm=""
}
cmdopt_help() {
usage
cat <<EOF
mount options can be separated by comma or specified multiple
times:
proc mount procfs to /proc
linproc mount linprocfs to /compat/linux/proc
fdescfs mount fdescfs to /dev/fd
maintaining a ZFS base system:
$progname init initialize a new subvolume
$progname update update an existing subvolume
$progname remove remove the base subvolume
$progname enter start a shell in the base subvolume
EOF
exit 0
}
wantshell=0
opt_shell=0
cmdopt_usershell() {
opt_shell=1
}
cmdopt_rootshell() {
opt_shell=2
let wantshell++
}
cmdopt_zfs() {
zfs_check
zfs_exists 1
}
makepkgargs=()
cmdopt_addopt() {
makepkgargs+=("${OPTARG}")
}
cmd_parse "$@"
shift $((OPTIND-1))
while imply existing noclean || \
imply update existing || \
imply keepbuild existing || \
imply usershell keepbuild || \
imply rootshell keepbuild || \
imply repackage keepbuild || \
imply mountonly zfs
do :; done
# update vars affected by the options like $build_profile
postconf
run_zfsopts "$@"
if (( $opt_repackage )) ; then
makepkgargs+=(-R)
fi
if (( $opt_keepbuild )); then
makepkgargs+=(-e)
fi
if (( $# != 2 )); then
usage
exit 1
fi
msg "Additional packages: ${opt_install[*]}"
if (( $opt_kill )); then opt_noclean=0; fi
# package options:
repo="$1"
package="++DEPRECATED++"
package_name="$2"
package_safe="${2//+/_}"
# let the msg function use repo/package
newmsg
if (( $opt_ports )); then
fullpath="$porttree/$repo/$package_name"
portname="$package_name"
else
fullpath="$abstree/$repo/$package_name"
fi
fulloutput="$package_output/$repo/$build_profile"
builddir="$buildtop/$repo/$build_profile/$package_name"
install -dm755 "${fulloutput}"
install -dm755 "${builddir}"
#
# Check options
#
if (( ! $opt_kill && ! $opt_mountonly )); then
[ -d "$fullpath" ] || die "No such package found in abs-tree"
if (( ! $opt_ports )); then
[ -e "$fullpath/PKGBUILD" ] || die "No PKGBUILD found for package %s" "$package_name"
srcpkg=$(getsource)
check_source
fi
fi
#
# Clean previous stuff
if (( $opt_zfs )); then
zfs_configure
fi
# Create directories if they don't exist
install -dm755 "${buildtop}"
install -dm755 "${buildtop}/"{,output/}{core,extra,community,linux,devel}
if (( $opt_zfs )); then
install -dm755 "${buildtop}/subvol"
if (( ! $opt_noclean )); then
zfs_clean_previous
if (( $opt_kill )); then exit 0; fi
fi
zfs_create_chroot
if (( $opt_mountonly )); then
msg "mounted"
exit 0
fi
mount_into_chroot
else
if (( ! $opt_noclean )); then
clean_previous
if (( $opt_kill )); then exit 0; fi
fi
create_chroot
configure_chroot
fi
if (( ! $opt_noprepare )); then
run_prepare
fi
if (( $wantshell < 4 )); then
create_builder_home
fi
if (( $wantshell < 3 )); then
syncdeps
fi
if (( $opt_shell == 1 )); then
msg "Entering chroot as builder"
if (( $opt_jail )); then
jail -c path=${builddir} ${jail_args[@]} command="/usr/bin/su -l builder"
else
chroot "${builddir}" /usr/bin/su -l builder
fi
elif (( $opt_shell == 2 )); then
msg "Entering chroot as root"
if (( $opt_jail )); then
jail -c path=${builddir} ${jail_args[@]} command="/usr/bin/bash"
else
chroot "${builddir}" /usr/bin/bash
fi
else
start_build
move_packages
fi
msg "Unmounting stuff"
do_unmount