-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpr
executable file
·590 lines (475 loc) · 17 KB
/
cpr
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
#!/usr/local/bin/cbsd
#v11.0.16
CBSDMODULE="cpr"
MYARG="dstdir pkglist"
MYOPTARG="append arch attach autoremove basename batch ccache inter jname makeconf new package_fetch pause repoversion tmux_cpr usegcc ver"
MYDESC="Create pkg repository"
ADDHELP="
${H3_COLOR}Description${N0_COLOR}:
The 'cbsd cpr' script allows you to build your own 'pkg' repository by package list,
providing functionality similar to poudreire (but much simpler).
The script processes your ports list sequentially and as a result creates repository via
'pkg repo'. All work happens in a container named 'cpr<md5_of_template>'.
All selected options you choose interactively and they are saved in the appropriate directory.
Note: on first launch you will select all options for all ports. If you are mistaken with options,
you can go to the jail and re-select the option manually. Or remove all options dir in /var/db/ports-<id>.
${H3_COLOR}General Options${N0_COLOR}:
${N2_COLOR}append=${N0_COLOR} - '1': do not check for dstdir in not empty;
${N2_COLOR}arch=${N0_COLOR} - <name>, build non-native architectures.
${N2_COLOR}autoremove=${N0_COLOR} - '1' - run 'pkg autoremove' at the end of session. Default - '0'
${N2_COLOR}ccache=1${N0_COLOR} - '1' - enable ccache (default is 0, disabled);
${N2_COLOR}distcc=0${N0_COLOR} - '1': enable distcc (default is 0, disabled);
${N2_COLOR}dstdir=${N0_COLOR} - path to output packages or 'repo' for update repoversion;
${N2_COLOR}new=${N0_COLOR} - '1': new repo (remove path (default)) or 0 - continue;
${N2_COLOR}pkglist=${N0_COLOR} - path to ascii file with port list for install;
${N2_COLOR}makeconf=${N0_COLOR} - path to alternative cpr_make.conf to /etc/make.conf in chroot;
${N2_COLOR}jname=${N0_COLOR} - use 'jname' for cpr jail;
${N2_COLOR}package_fetch=${N0_COLOR} - install some packages via pkg, e.g.: package_fetch="llvm16";
${N2_COLOR}pause=${N0_COLOR} - '1': make pause (for example for chroot in env) before create pkg;
${N2_COLOR}repoversion=${N0_COLOR} - name of repo version (ports cfg version), default for system set;
${N2_COLOR}usegcc=${N0_COLOR} - path to gcc port;
${N2_COLOR}ver=${N0_COLOR} - base version, e.g: '14.1', 'head';
${H3_COLOR}Examples${N0_COLOR}:
Full example:
echo \"/usr/ports/www/nginx\" > /tmp/myrepo.list
echo \"/usr/ports/misc/mc\" >> /tmp/myrepo.list
echo \"/usr/ports/shells/bash\" >> /tmp/myrepo.list
cbsd cpr pkglist=/tmp/myrepo.list dstdir=/tmp/myrepo
"
#set -e
TRAP=""
#defines
_MYDIR=$( ${DIRNAME_CMD} `${REALPATH_CMD} $0` )
. ${subr}
readconf buildworld.conf
ver=
over=
package_fetch=
opackage_fetch=
oautoremove=
omakeconf=
makeconf=
jname=
. ${cbsdinit}
[ -n "${jname}" ] && ojname="${jname}"
[ -n "${makeconf}" ] && omakeconf="${makeconf}"
[ -n "${ver}" ] && over="${ver}"
[ -z "{package_fetch}" ] && opackage_fetch="${package_fetch}"
[ -n "${autoremove}" ] && oautoremove="${autoremove}"
[ -z "${autoremove}" ] && autoremove=0
. ${subrdir}/distccache.subr
. ${subrdir}/mailtools.subr
if [ -n "${over}" ]; then
ver="${over}"
elif [ -z "${ver}" ]; then
ver=$( ${SYSCTL_CMD} -n kern.osrelease | ${CUT_CMD} -d - -f 1 )
fi
# detect stable
strpos --str="${ver}" --search="."
# auto-detect for stable/release
pos=$?
if [ ${pos} -eq 0 ]; then
stable=1
else
stable=0
fi
. ${subrdir}/universe.subr
. ${subrdir}/build.subr
[ -z "${pause}" ] && pause=0
[ -z "${batch}" ] && batch=0
[ ! -r ${etcdir}/cpr.conf -a -r ${_MYDIR}/etc-sample/cpr.conf ] && ${CP_CMD} ${_MYDIR}/etc-sample/cpr.conf ${etcdir}/cpr.conf
show_tmux_session()
{
tmuxcmd=$( which tmux 2>/dev/null )
[ -z "${tmuxcmd}" ] && err 1 "${N1_COLOR}No such tmux${N0_COLOR}"
${ECHO} "${N1_COLOR}Active cpr session:${N0_COLOR}"
${tmuxcmd} list-sessions 2>/dev/null | ${GREP_CMD} "\-cpr: " | ${CUT_CMD} -d : -f 1
exit 0
}
post_action()
{
if [ -r ${data}/tmp/cpr_error ]; then
[ -r ${data}/tmp/build.log ] && ${TAIL_CMD} -n100 ${data}/tmp/build.log
err 1 "${N1_COLOR}CPR failed. See log for detail: /tmp/build.log${N0_COLOR}"
fi
if [ "${pause}" = "1" ]; then
${ECHO} "${N1_COLOR}Pause before create pkg.${N0_COLOR}"
${ECHO} "${N1_COLOR}You can enter in jail via: ${N2_COLOR}cbsd jlogin ${jname}${N0_COLOR}"
${ECHO} "${N1_COLOR}Press any key to continue.${N0_COLOR}"
read pause
fi
[ -n "${oautoremove}" ] && autoremove="${oautoremove}"
if [ "${autoremove}" = "1" ]; then
${ECHO} "${N1_COLOR}Run pkg autoremove: autoremove=1 ... ${N0_COLOR}"
${CHROOT_CMD} ${path} /bin/sh <<EOF
pkg autoremove -y
EOF
fi
${ECHO} "${N1_COLOR}Creating packages ... ${N0_COLOR}"
${CHROOT_CMD} ${path} /bin/sh << EOF
#export PACKAGES=/packages
export PACKAGES=/tmp/packages
[ ! -d \${PACKAGES}/All ] && mkdir \${PACKAGES}/All
for i in \$( pkg query %n-%v ); do
pkg create -n -g -o \${PACKAGES}/All/ \$i
done
cd \${PACKAGES}/All
${RM_CMD} -f digests.pkg packagesite.pkg repo.pkg
pkg repo .
EOF
TRAP="${TRAP} ${RM_CMD} -f ${LOCKFILE} ${_tmppkglist};"
trap "${TRAP}" HUP INT ABRT BUS TERM EXIT
DT_END=$( ${DATE_CMD} +%s )
DT_DIFF=$(( DT_END - DT_START ))
if [ "${dstdir}" = "repo" ]; then
${FIND_CMD} ${path}/packages/All -type f -name \*.pkg -exec ${MV_CMD} -f {} ${MYPKGDIR}/ \;
ROOTPKGDIR="${MYPKGDIR}"
else
# ${FIND_CMD} ${path}/packages/All -type f -name \*.pkg -exec ${MV_CMD} -f {} ${MYPKGDIR}/ \;
ROOTPKGDIR="${dstdir}"
[ ! -d ${ROOTPKGDIR} ] && mkdir -p ${ROOTPKGDIR}
echo "rsync -avz ${MYPKGDIR}/All/ ${ROOTPKGDIR}/"
rsync -avz ${MYPKGDIR}/All/ ${ROOTPKGDIR}/
${FIND_CMD} ${path}/packages/All -type f -name \*.pkg -exec ${CP_CMD} -n {} ${MYPKGDIR}/ \;
# bver=$( ${miscdir}/elf_tables --freebsdver ${path}/bin/sh )
# bosname=$( ${miscdir}/elf_tables --osname ${path}/bin/sh )
# barch=$( ${miscdir}/elf_tables --arch ${path}/bin/sh )
#
# case "${bosname}" in
# freebsd)
# bosname="FreeBSD"
# ;;
# *)
# err 1 "${N1_COLOR}Unknown osname: ${N2_COLOR}${bosname}${N0_COLOR}"
# ;;
# esac
#
# case "${barch}" in
# x86)
# barch="amd64"
# ;;
# *)
# err 1 "${N1_COLOR}Unknown arch: ${N2_COLOR}${barch}${N0_COLOR}"
# ;;
# esac
#
# ROOTPKGDIR="${dstdir}/${bosname}:${bver}:${barch}"
#
# [ -d "${ROOTPKGDIR}" ] && ${RM_CMD} -rf ${ROOTPKGDIR}
# ${MKDIR_CMD} -p ${ROOTPKGDIR}
#
##MYPKGDIR
# echo "* ${MV_CMD} ${MYPKGDIR} ${ROOTPKGDIR}/All"
#
#echo "ER"
#mkdir -p ${ROOTPKGDIR}
#echo "mv ${path}/packages/x ${ROOTPKGDIR}/"
#mv ${path}/packages/* ${ROOTPKGDIR}/
#echo "HE"
fi
# create pkg in symlinked /latest location (see pkg-repository(5))
echo "WORK : ${ROOTPKGDIR}"
cd ${ROOTPKGDIR}
# ${LN_CMD} -sf ./All ./latest
# cd ${ROOTPKGDIR}/All
[ ! -d Latest ] && ${MKDIR_CMD} Latest
${FIND_CMD} ./ -type f -name "pkg-[0-9]*.pkg" | while read _f; do
_f=$( ${BASENAME_CMD} ${_f} )
${LN_CMD} -sf ${_f} ./pkg.pkg
# back-compat
${LN_CMD} -sf ${_f} ./pkg.txz
cd ./Latest
${LN_CMD} -sf ../${_f} ./pkg.pkg
${LN_CMD} -sf ../${_f} ./pkg.txz
cd ..
done
# for some reason pkg <bootstrap/install> trying to get
# pkg from: <url>/FreeBSD:12:amd64/latest/Latest/pkg.pkg
# if [ -h ${ROOTPKGDIR}/All/pkg.pkg ]; then
# ${MKDIR_CMD} -p ${ROOTPKGDIR}/All/Latest
# orig_pkg=$( ${REALPATH_CMD} ${ROOTPKGDIR}/All/pkg.pkg )
# ${CP_CMD} ${orig_pkg} ${ROOTPKGDIR}/All/Latest/pkg.pkg
# fi
jstop ${jname}
send_notification -s "[CBSD ${nodename}] cpr ${ver} ${arch} ${repoversion} complete" -b "${DT_END}"
}
# $1 - src-session name
init_tmux()
{
local src_session
src_session="${1}"
if [ "${tmux_cpr}" = "0" -o -z "${src_session}" ]; then
tmux_cpr=0
return 0
fi
tmuxcmd=$( which tmux 2>/dev/null )
session_name="${src_session}"
if [ -n "${tmuxcmd}" ]; then
# tmux here and we preferred them
return 0
fi
# no tmux here
tmux_cpr=0
return 0
}
umount_temp_dirs()
{
# when error before path, we do not have any mounts by scripts
[ -z "${path}" -o ! -d "${path}" ] && return 0
umount_paths ${path}
#destroy md disk when he used
if [ "${CCACHEFS}" = "mdfs" -a -n "${MDDEV}" ]; then
${ECHO} "${N1_COLOR}Destroy md drive: ${N2_COLOR}${MDDEV}${N0_COLOR}"
${MDCONFIG_CMD} -d -u ${MDDEV}
fi
}
mount_temp_dirs()
{
local _tmpfstab="${ftmpdir}/mount_temp_dirs.$$"
TRAP="${TRAP} ${RM_CMD} -f ${_tmpfstab};"
trap "${TRAP}" HUP INT ABRT BUS TERM EXIT
[ ! -d "${PORTSCFG_SRC}" ] && ${MKDIR_CMD} -p ${PORTSCFG_SRC}
[ ! -d "${MYPKGDIR}" ] && ${MKDIR_CMD} -p ${MYPKGDIR}
[ ! -d "${data}/root/system" ] && ${MKDIR_CMD} -p ${data}/root/system
${CAT_CMD} >> ${_tmpfstab} << EOF
procfs /proc procfs rw 0 0
${PORTSCFG_SRC} /var/db/ports ${NULLFS} rw 0 0
${MYPKGDIR} /tmp/packages ${NULLFS} rw 0 0
${workdir}/jails-system/${jname} /root/system ${NULLFS} rw 0 0
EOF
if [ ${ccache} -eq 1 -a -n "${ccache_dir_source}" ]; then
[ ! -d ${path}/root/.ccache ] && ${MKDIR_CMD} -p ${path}/root/.ccache
${CAT_CMD} >> ${_tmpfstab} << EOF
${ccache_dir_source} /root/.ccache ${NULLFS} rw 0 0
EOF
fi
mountfstab jroot=$path fstab=${_tmpfstab} jname="${jname}"
${RM_CMD} -f ${_tmpfstab}
}
prepare_chroot()
{
${ECHO} "${N1_COLOR}Building packages... ${N0_COLOR}"
[ "${ccache}" = "1" ] && NEEDEDPORTS="${NEEDEDPORTS} /usr/ports/devel/ccache"
[ "${distcc}" = "1" ] && NEEDEDPORTS="/usr/ports/devel/distcc ${NEEDEDPORTS}"
export NEEDEDPORTS
[ -n "${usegcc}" ] && export usegcc
if [ -f "${makeconf}" ]; then
${ECHO} "${N1_COLOR}${CBSD_APP} copy ${makeconf}: ${N2_COLOR}${path}/etc/make.conf${N0_COLOR}"
${CP_CMD} ${makeconf} ${path}/etc/make.conf
fi
[ ! -r ${path}/etc/make.conf ] && ${TOUCH_CMD} ${path}/etc/make.conf
[ "${batch}" = "1" ] && /usr/local/cbsd/misc/cbsdsysrc -qf ${path}/etc/make.conf BATCH=no
# into options
#${CP_CMD} /etc/resolv.conf ${path}/etc
${CAT_CMD} > ${path}/etc/resolv.conf <<EOF
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
${TOUCH_CMD} ${path}/etc/src.conf
${CHROOT_CMD} ${path} /bin/sh << EOF
service ldconfig start
mv /etc/make.conf /tmp
env SIGNATURE_TYPE=none ASSUME_ALWAYS_YES=yes IGNORE_OSVERSION=yes pkg info
pkg info -e pkg
ret=\$?
if [ \${ret} -ne 0 ]; then
echo "/usr/ports/ports-mgmt/pkg not installed"
else
env BATCH=no env WRKDIRPREFIX=/tmp make -C /usr/ports/ports-mgmt/pkg clean
env BATCH=no env WRKDIRPREFIX=/tmp make -C /usr/ports/ports-mgmt/pkg deinstall
env BATCH=no env WRKDIRPREFIX=/tmp make -C /usr/ports/ports-mgmt/pkg clean
fi
mv /tmp/make.conf /etc/
[ -d /tmp/usr/ports ] && find /tmp/usr/ports -type d -name work -exec rm -rf {} \; > /dev/null 2>&1
if [ -n "\${usegcc}" ]; then
env BATCH=no make -C \$usegcc install
cp /etc/make.conf /tmp/mk.conf
grep -v USE_GCC /tmp/mk.conf > /etc/make.conf
echo USE_GCC=yes >> /etc/make.conf
fi
[ "${batch}" = "1" ] && /usr/local/cbsd/misc/cbsdsysrc -qf ${path}/etc/make.conf BATCH=no
for i in \${NEEDEDPORTS}; do
PORTNAME=\$( make -C \$i -V PORTNAME )
if [ -f /tmp/buildcontinue ]; then
cd /tmp/packages
pkg info -e \$PORTNAME >/dev/null 2>&1 || {
[ -f \${PORTNAME}.pkg ] && env ASSUME_ALWAYS_YES=yes pkg add -y ./\${PORTNAME}.pkg && echo -e "\033[40;35m\${PORTNAME} found and added from cache. \033[0m"
}
pkg info -e \$PORTNAME || {
make -C \$i clean
make -C \$i
make -C \$i install
}
else
pkg info -e \$PORTNAME && continue
echo "Installing \$PORTNAME from \$i "
make -C \$i install clean
fi
done
EOF
}
init_ccachedir_for_chroot()
{
ccache_dir_source="${dbdir}/ccache/ccache-${arch}-${ver}-${stable}"
${ECHO} "${N1_COLOR}Init ccache directory: ${N2_COLOR}${ccache_dir_source}${N1_COLOR}...${N0_COLOR}"
[ ! -d "${path}/root/.ccache" ] && ${MKDIR_CMD} -p ${path}/root/.ccache
[ ! -d "${ccache_dir_source}" ] && ${MKDIR_CMD} -p ${ccache_dir_source}
}
### MAIN
[ -z "${pkglist}" -o -z "${dstdir}" ] && show_tmux_session
[ -n "${tmux_cpr}" ] && orig_tmux_cpr="${tmux_cpr}"
readconf cpr.conf
init_target_arch
init_srcdir
init_supported_arch
init_basedir
init_kerneldir
#defaults
[ -z "${ccache}" ] && ccache=0
[ -z "${distcc}" ] && distcc=0
unset SRCCONF
[ -n "${orig_tmux_cpr}" ] && tmux_cpr="${orig_tmux_cpr}"
[ -z "${inter}" ] && inter="1"
if [ "$new" = "0" ]; then
new=0
else
new=1
fi
if [ -d "${dstdir}" ]; then
if [ "${new}" = "1" -a "${append}" != "1" ]; then
A=$( ${LS_CMD} -1 ${dstdir}/ | ${WC_CMD} -l | ${AWK_CMD} '{ printf $1 }' )
[ "${A}" != "0" ] && ${ECHO} "${N1_COLOR}Warning: ${N2_COLOR}${dstdir}/${N1_COLOR} is not empty. Please use ${N2_COLOR}append=1${N1_COLOR} or clean before cpr initialization:${N0_COLOR}" && err 1 $( ${LS_CMD} -1 ${dstdir} )
fi
else
${MKDIR_CMD} -p "${dstdir}"
fi
if [ $( ${UNAME_CMD} -m ) = "i386" -a "${arch}" = "amd64" ]; then
err 1 "Cannot install amd64 base on i386 hosts"
fi
[ -z "${makeconf}" ] && makeconf="${_MYDIR}/cpr_make.conf"
[ ! -f "${pkglist}" ] && err 1 "No pkglist file"
if [ -n "${ojname}" ]; then
jname="${jname}"
else
tpl_md5=$( ${miscdir}/cbsd_md5 -qs "${pkglist}" )
md5_postfix=$( substr --pos=0 --len=5 --str="${tpl_md5}" )
jname="cpr${md5_postfix}"
fi
_tmppkglist=""
jstatus jname=${jname} >/dev/null 2>&1
if [ $? -eq 0 ]; then
${ECHO} "${N1_COLOR}No such jail. Create from template: ${N2_COLOR}${jname}${N0_COLOR}"
[ -z "${cbsd_workdir}" ] && . /etc/rc.conf
[ -z "${cbsd_workdir}" ] && err 1 "${N1_COLOR}Empty cbsd_workdir variable${N0_COLOR}"
${CP_CMD} -a ${_MYDIR}/cbsdfile /tmp/cbsdfile.$$
TRAP="${TRAP} ${RM_CMD} -rf /tmp/cbsdfile.$$;"
trap "${TRAP}" HUP INT QUIT ABRT KILL ALRM TERM BUS EXIT
${SED_CMD} -i${SED_DELIMER}'' -e "s:%%JNAME%%:${jname}:g" /tmp/cbsdfile.$$/CBSDfile
${ECHO} "${N1_COLOR}Obtain new jail: ${N2_COLOR}${jname}${N0_COLOR}"
up cbsdfile=/tmp/cbsdfile.$$/CBSDfile || err 1 "Error jail creation via tpl ${tpl}"
pkg mode=update jname=${jname} || true
pkg mode=bootstrap jname=${jname} || true
${CAT_CMD} > ${workdir}/jails-system/${jname}/descr <<EOF
Created by cbsd cpr
Created: `${DATE_CMD}`
Pkg list: ${pkglist}
EOF
jstart ${jname}
else
${ECHO} "${N1_COLOR}Jail already created: ${N2_COLOR}${jname}${N0_COLOR}"
fi
. ${subrdir}/rcconf.subr
[ "${baserw}" = "1" ] && path=${data}
if [ ${jid} -eq 0 ]; then
${ECHO} "${N1_COLOR}Jail is not running. Starting... ${N2_COLOR}${jname}${N0_COLOR}"
jstart ${jname}
fi
if [ -z "${repoversion}" -o "${repoversion}" = "default" ]; then
# move to systemdir?
PORTSCFG_SRC="/var/db/ports-${jname}"
MYPKGDIR="${PKGDIRROOT}/pkgdir-${jname}"
else
# move to systemdir?
PORTSCFG_SRC="${dbdir}/ports-${repoversion}"
MYPKGDIR="${PKGDIRROOT}/${repoversion}"
fi
[ ! -d "${PORTSCFG_SRC}" ] && ${MKDIR_CMD} -p ${PORTSCFG_SRC}
[ -n "${opackage_fetch}" ] && package_fetch="${opackage_fetch}"
if [ -n "${package_fetch}" ]; then
${ECHO} "${N1_COLOR}Prefetch packages: ${N2_COLOR}${package_fetch}${N0_COLOR}"
pkg mode=install jname="${jname}" ${package_fetch} >> /tmp/pkg.txt 2>&1
ret=$?
echo "RET: ${ret}"
if [ ${ret} -ne 0 ]; then
${ECHO} "${W1_COLOR}Error: ${N2_COLOR}pkg mode=install jname=\"${jname}\" ${package_fetch}${N0_COLOR}"
${CAT_CMD} /tmp/pkg.txt
exit 1
fi
fi
if [ ${tmux_cpr} -eq 1 ]; then
init_tmux "${jname}-cpr"
${tmuxcmd} list-sessions | ${GREP_CMD} -qwF "${session_name}:"
_ret=$?
else
_ret=0
fi
if [ ${ccache} -eq 1 ]; then
if [ ! -x /usr/local/bin/ccache ]; then
${ECHO} "Ccache enabled but /usr/local/bin/ccache not found, disable"
ccache=0
else
echo "Go to init ccache"
ccache_dir_prefix="cpr"
init_ccache_dir
fi
fi
# start action
mount_temp_dirs
#[ "${MOUNT_PORTS}" = "0" -a $new -eq 1 ] && ${CHROOT_CMD} ${path} portsnap fetch extract
prepare_chroot
if [ ${ccache} -eq 1 -o ${distcc} -eq 1 ]; then
prepare_make_conf ${makeconf} ${path}/etc/make.conf
fi
# make sure we have work dir in /tmp for parallel builds
[ $( ${GREP_CMD} ^WRKDIRPREFIX= ${path}/etc/make.conf | ${WC_CMD} -l ) = 0 ] && echo WRKDIRPREFIX=/tmp >> ${path}/etc/make.conf
[ "${batch}" = "1" ] && /usr/local/cbsd/misc/cbsdsysrc -qf ${path}/etc/make.conf BATCH=no
DT_START=$( ${DATE_CMD} +%s )
send_notification -s "[CBSD ${nodename}] cpr ${ver} ${arch} ${repoversion} started" -b "${DT_START}"
${CP_CMD} ${_MYDIR}/cpr_packages.sh ${path}/tmp/cpr_packages.sh
${GREP_CMD} -v "^#" ${pkglist} | ${GREP_CMD} . > ${path}/tmp/ports_list.txt
add_args=
[ ${ccache} -eq 1 ] && add_args="${add_args} -c 1"
[ ${distcc} -eq 1 ] && add_args="${add_args} -d 1"
jexec="cbsd jexec jname=${jname} sh /tmp/cpr_packages.sh ${add_args}"
if [ ${tmux_cpr} -eq 1 ]; then
if [ ${_ret} -eq 1 ]; then
# start action
${ECHO} "${N1_COLOR}${tmuxcmd} new -s ${N2_COLOR}${session_name}${N0_COLOR}"
${tmuxcmd} new -s "${session_name}" "eval ${jexec}"
else
${tmuxcmd} attach-session -t "${session_name}"
fi
else
eval "${jexec}"
fi
sync
echo "${path}/tmp/cpr_build_status.txt test"
sleep 2 # lets wait for store /tmp/cpr_build_status.txt
if [ -r ${path}/tmp/cpr_build_status.txt ]; then
FAILED=0
. "${path}/tmp/cpr_build_status.txt"
${ECHO} "${N1_COLOR}Progress: ${N2_COLOR}${pkg_left}/${pkg_all} ${N1_COLOR}(Failed: ${W2_COLOR}${FAILED}${N1_COLOR})${N0_COLOR}"
${ECHO} "${N1_COLOR}Current build: ${N2_COLOR}${current_build}${N0_COLOR}"
${ECHO} "${N1_COLOR}Failed: ${N2_COLOR}${FAILED}/${pkg_all}"
if [ "${FAILED}" != "0" ]; then
find ${path}/tmp/ -name *.err -exec basename {} \; | while read _f; do
echo "=== tail -n40 ${_f} ==="
tail -n40 ${path}/tmp/${_f}
echo "=== tail -n40 ${_f} ==="
done
${ECHO} "${N1_COLOR}Failed list: ${FAILED_LIST}${N0_COLOR}"
exit 1
fi
fi
post_action
exit 0