summaryrefslogtreecommitdiff
path: root/Tools/portbuild/scripts/dopackages
blob: 47ba4a7dd8c6aacf67ce3a6e11cded3bb9898bfb (plain) (blame)
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
#!/bin/sh

# configurable variables
pb=/var/portbuild

. ${pb}/portbuild.conf

# packages for dependencies only
dummyports="x11/XFree86 x11-toolkits/Motif-dummy"

# packages with very long dependency lists -- try to start building these first
quickports="x11/kde11 x11/kde11-i18n x11/gnome"

status=${pb}/status

errorexit () {
  echo "$1" > ${status}
  exit $1
}

usage () {
  echo "usage: [-nobuild] [-noindex] [-noduds] [-nocvsup] [-nocvs] [-norestr] [-noplistcheck] [-nodummy] branch date"
  errorexit 1
}

# usage: makeindex pb scripts branch user
makeindex () {
  pb=$1
  scripts=$2
  branch=$3
  user=$4

  cd ${pb}/usr/ports
  echo "================================================"
  echo "generating index"
  echo "================================================"
  echo "index generation started at $(date)"
  ${scripts}/makeindex ${branch} || errorexit 1
  echo "index generation ended at $(date)"
  echo $(wc -l <INDEX) "lines in INDEX"
  chown ${user} INDEX
  cp -p INDEX INDEX-${branch}
}

# usage: checkindex pb
checkindex () {
  pb=$1

  cd ${pb}/usr/ports
  if grep -q non-existent INDEX; then
    echo "errors in INDEX:"
    grep -n non-existent INDEX
    errorexit 1
#    grep -C non-existent INDEX
#    grep -v non-existent INDEX > INDEX.tmp
#    mv -f INDEX.tmp INDEX
  fi
  if ! awk -F '|' '{if (NF != 10) { error=1; printf("line %d: %s\n", NR, $0)}} END {if (error == 1) exit(1)}' INDEX; then
    echo "error in INDEX"
    errorexit 1
  fi
}

# usage: makeduds pb scripts branch
makeduds () {
  pb=$1
  scripts=$2
  branch=$3

  cd ${pb}/usr/ports
  echo "================================================"
  echo "generating duds"
  echo "================================================"
  echo "duds generation started at $(date)"
  if ! ${scripts}/makeduds ${branch}; then
    echo "error(s) detected, exiting script at $(date)"
    errorexit 1
  fi
  echo "duds generation ended at $(date)"
  echo $(wc -l < ${pb}/${branch}/duds) "items in duds"
  echo "duds diff:"
  diff ${pb}/${branch}/duds.old ${pb}/${branch}/duds
  cp -p ${pb}/${branch}/duds ${pb}/${branch}/duds.old
}

# usage: setupnode pb scripts branch me node md5
setupnode () {
  pb=$1
  scripts=$2
  branch=$3
  me=$4
  node=$5
  md5=$6

  echo "setting up of $node started at $(date)"
  ssh -n ${node} mkdir -p ${scripts}
  scp -p ${scripts}/setupnode ${node}:${scripts}
  ssh -n ${node} ${scripts}/setupnode ${me} ${pb} ${branch} ${md5}
  echo "setting up of $node ended at $(date)"
}

# usage: restrictedlist pb scripts branch
restrictedlist () {
  pb=$1
  scripts=$2
  branch=$3

  cd ${pb}/usr/ports
  echo "================================================"
  echo "creating restricted list"
  echo "================================================"
  echo "restricted list generation started at $(date)"
  make ECHO_MSG=/usr/bin/true clean-restricted-list \
    | sed -e "s./usr/ports/distfiles/./distfiles/.g" \
          -e "s./usr/ports/./${branch}/.g" \
      > ${pb}/${branch}/restricted.sh
  echo "restricted list generation ended at $(date)"
  echo $(grep -c '^#' ${pb}/${branch}/restricted.sh) "ports in ${pb}/${branch}/restricted.sh"
}
  
# usage: cdromlist pb scripts branch
cdromlist () {
  pb=$1
  scripts=$2
  branch=$3

  cd ${pb}/usr/ports
  echo "================================================"
  echo "creating cdrom list"
  echo "================================================"
  echo "cdrom list generation started at $(date)"
  make ECHO_MSG=/usr/bin/true clean-for-cdrom-list \
    | sed -e "s./usr/ports/distfiles/./distfiles/.g" \
          -e "s./usr/ports/./${branch}/.g" \
      > ${pb}/${branch}/cdrom.sh
  echo "cdrom list generation ended at $(date)"
  echo $(grep -c '^#' ${pb}/${branch}/cdrom.sh) "ports in ${pb}/${branch}/cdrom.sh"
}

scripts=${pb}/scripts

umask 002
export PORTSDIR=${pb}/usr/ports

me=$(hostname -s)

echo "Subject: $me package building logs"
echo
echo "Called with arguments: "${1+"$@"}
echo "Started at $(date)"

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin

if [ $# = 0 ]; then
  usage
fi

nobuild=0
noindex=0
noduds=0
nocvsup=0
nocvs=0
norestr=0
noplistcheck=0
nodummy=0

# optional arguments
while [ $# -gt 2 ]; do
  case "x$1" in
    x-nobuild)
      nobuild=1
      ;;
    x-noindex)
      noindex=1
      ;;
    x-noduds)
      noduds=1
      ;;
    x-nocvsup)
      nocvsup=1
      ;;
    x-nocvs)
      nocvs=1
      ;;
    x-norestr)
      norestr=1
      ;;
    x-noplistcheck)
      noplistcheck=1
      ;;
    x-nodummy)
      nodummy=1
      ;;
    *)
      usage
      ;;
  esac
  shift
done

# mandatory arguments
branch=$1
date=$2
if [ "x$branch" != x3 -a "x$branch" != x4 -a "x$branch" != x5 ]; then
  usage
fi

if [ "$norestr" = 1 ]; then
  export NO_RESTRICTED=t
fi

if [ "$noplistcheck" = 1 ]; then
  export NOPLISTCHECK=t
fi

if [ "$nodummy" = 1 ]; then
  export NODUMMY=t
  export MOTIF_OPEN=t
  export XFREE86_VERSION=4
fi

cd ${pb}/usr/ports
if [ "$nocvsup" = 0 ]; then
  echo "================================================"
  echo "running cvsup"
  echo "================================================"
  su ${user} -c 'cvsup -g -L 0 /etc/supfile.cvsup'
  date > ${pb}/cvsdone
  echo "================================================"
  echo "running cvs update on /usr/ports"
  echo "================================================"
  su ${user} -c 'cvs -q update -d -P'
  echo "================================================"
  echo "running make checksubdirs"
  echo "================================================"
  make checksubdirs 
  echo "================================================"
  echo "running cvs update on /usr/opt/doc"
  echo "================================================"
  cd ${pb}/usr/opt/doc
  su ${user} -c 'cvs -q update -d -P'
fi

if [ "$nocvs" = 0 ]; then
  echo "================================================"
  echo "running cvs update on /${branch}/src"
  echo "================================================"
  cd ${pb}/${branch}/src
  su ${user} -c 'cvs -q update -d -P'
fi

# this one not in background to check return status

if [ "$noduds" = 0 ]; then
  makeduds ${pb} ${scripts} ${branch}
fi

if [ "$noindex" = 0 ]; then
  makeindex ${pb} ${scripts} ${branch} ${user} &
fi

md5=$(/sbin/md5 ${pb}/${branch}/tarballs/bindist.tar | awk '{print $4}')
echo "================================================"
echo "setting up nodes"
echo "================================================"
for node in $(awk '{print $1}' ${pb}/mlist); do
  setupnode ${pb} ${scripts} ${branch} ${me} ${node} ${md5} &
  sleep 2
done

restrictedlist ${pb} ${scripts} ${branch} &
sleep 2

cdromlist ${pb} ${scripts} ${branch} &

wait

checkindex ${pb}

echo "all preparation ended at $(date)"

cd ${pb}/usr/ports
make parallel branch=${branch} > ../../${branch}/Makefile

cd ${pb}/usr/ports

if [ "$nodummy" = 0 ]; then
  dummypkgs=""
  for i in ${dummyports}; do
    if [ -d $i ]; then
      dummypkgs="${dummypkgs} $(cd $i; make package-name).tgz"
    else
      echo "dummy port directory \"$i\" does not exist -- skipping"
    fi
  done
fi

quickpkgs=""
for i in ${quickports}; do
  if [ -d $i ]; then
    quickpkgs="${quickpkgs} $(cd $i; make package-name).tgz"
  else
    echo "quick port directory \"$i\" does not exist -- skipping"
  fi
done

cd ${pb}
if [ "$nobuild" = 0 ]; then
###  rm -rf bak/distfiles
###  mv -f distfiles bak
  mkdir -p distfiles
  chown -R ${user} distfiles
  cd ${pb}/${branch}/bak
  rm -rf errors logs packages old-errors
  cd ${pb}/${branch}
  mv -f errors logs packages old-errors make.* bak
###delete old packages -- use when diskspace is scarce
#  if cd bak/packages/All; then
#    for i in *.tgz; do
#      cp /dev/null $i
#    done
#  fi
  cd ${pb}/${branch}
  mkdir -p packages/All
  mkdir -p ${pb}/archive/errorlogs
  rm -rf ${pb}/archive/errorlogs/e.${branch}.${date}
  mkdir -p ${pb}/archive/errorlogs/e.${branch}.${date}
  ln -sf ${pb}/archive/errorlogs/e.${branch}.${date} ${pb}/${branch}/errors
  rm -rf ${pb}/archive/errorlogs/a.${branch}.${date}
  mkdir -p ${pb}/archive/errorlogs/a.${branch}.${date}
  ln -sf ${pb}/archive/errorlogs/a.${branch}.${date} ${pb}/${branch}/logs
  cp -p ${pb}/cvsdone ${pb}/archive/errorlogs/e.${branch}.${date}/cvsdone
  cp -p ${pb}/cvsdone ${pb}/archive/errorlogs/a.${branch}.${date}/cvsdone
  cp -p ${pb}/usr/ports/INDEX-${branch} ${pb}/archive/errorlogs/e.${branch}.${date}/INDEX
  cp -p ${pb}/usr/ports/INDEX-${branch} ${pb}/archive/errorlogs/a.${branch}.${date}/INDEX
  chown -RL ${user} errors logs packages
  echo "error logs in ${pb}/archive/errorlogs/e.${branch}.${date}"
  if [ "$nodummy" = 0 ]; then
    for dir in ${dummyports}; do
      cp -p tarballs/$(cd ${pb}/usr/ports/$dir; make package-name).tgz packages/All
    done
  fi

  count=$(awk '{sum+=$2}END{print sum+NR/2}' ${pb}/mlist | sed -e 's/\..*$//')
  cd ${pb}/${branch}/packages/All
  ln -sf ../../Makefile .
  echo "================================================"
  echo "building packages (phase 1)"
  echo "================================================"
  echo "started at $(date)"
  make -k -j$count ${quickpkgs} all > ../../make.0 2>&1 </dev/null
  echo "ended at $(date)"
  echo $(echo $(ls -1 ${pb}/${branch}/packages/All | wc -l) - 2 | bc) "packages built"
  echo $(echo $(du -sk ${pb}/${branch}/packages | awk '{print $1}') / 1024 | bc) "MB of packages"
  echo $(echo $(du -sk ${pb}/distfiles | awk '{print $1}') / 1024 | bc) "MB of distfiles"
  cd ${pb}/${branch}
  if grep -qE '(ptimeout|pnohang): killing' make.0; then
    echo "The following port(s) timed out:"
    grep -E '(ptimeout|pnohang): killing' make.0 | sed -e 's/^.*ptimeout:/ptimeout:/' -e 's/^.*pnohang:/pnohang:/' 
  fi
  cp -rp errors old-errors
  cd ${pb}/${branch}/old-errors
  ${pb}/scripts/processlogs

  md5=$(/sbin/md5 ${pb}/${branch}/tarballs/bindist.tar | awk '{print $4}')
  echo "================================================"
  echo "setting up nodes"
  echo "================================================"
  for node in $(awk '{print $1}' ${pb}/mlist); do
    setupnode ${pb} ${scripts} ${branch} ${me} ${node} ${md5} &
    sleep 2
  done

  wait

  echo "setting up of nodes ended at $(date)"

  count=$(awk '{sum+=$2}END{print sum+NR/2}' ${pb}/mlist | sed -e 's/\..*$//')
  cd ${pb}/${branch}/packages/All
  echo "================================================"
  echo "building packages (phase 2)"
  echo "================================================"
  echo "started at $(date)"
  make -k -j$count ${quickpkgs} all > ../../make.1 2>&1 </dev/null
  echo "ended at $(date)"
  rm Makefile
  if [ "$nodummy" = 0 ]; then
    rm ${dummypkgs}
  fi
  ${pb}/scripts/chopindex ${pb}/usr/ports/INDEX-${branch} ${pb}/${branch}/packages > \
    ${pb}/${branch}/packages/INDEX
  echo $(ls -1 ${pb}/${branch}/packages/All | wc -l) "packages built"
  echo $(cat ${pb}/${branch}/packages/INDEX | wc -l) "lines in INDEX"
  echo $(echo $(du -sk ${pb}/${branch}/packages | awk '{print $1}') / 1024 | bc) "MB of packages"
  echo $(echo $(du -sk ${pb}/distfiles | awk '{print $1}') / 1024 | bc) "MB of distfiles"
  if [ "$norestr" = 0 ]; then
    echo "deleting restricted ports"
    sh ${pb}/${branch}/restricted.sh
    ${pb}/scripts/chopindex ${pb}/usr/ports/INDEX ${pb}/${branch}/packages > \
      ${pb}/${branch}/packages/INDEX
    echo $(ls -1 ${pb}/${branch}/packages/All | wc -l) "packages built"
    echo $(cat ${pb}/${branch}/packages/INDEX | wc -l) "lines in INDEX"
    echo $(echo $(du -sk ${pb}/${branch}/packages | awk '{print $1}') / 1024 | bc) "MB of packages"
    echo $(echo $(du -sk ${pb}/distfiles | awk '{print $1}') / 1024 | bc) "MB of distfiles"
  fi
  rm -rf ${pb}/${branch}/bad
  mkdir -p ${pb}/${branch}/bad
  echo "checking packages"
  for i in *.tgz; do
    if ! gzip -t $i; then
      echo "Warning: package $i is bad, moving to ${pb}/${branch}/bad"
      # the latest link will be left behind...
      mv $i ${pb}/${branch}/bad
      rm ../*/$i
    fi
  done
  echo "generating CHECKSUM.MD5"
  md5 *.tgz > CHECKSUM.MD5
  cd ${pb}/${branch}
  if grep -qE '(ptimeout|pnohang): killing' make.1; then
    echo "The following port(s) timed out:"
    grep -E '(ptimeout|pnohang): killing' make.1 | sed -e 's/^.*ptimeout:/ptimeout:/' -e 's/^.*pnohang:/pnohang:/'
  fi
  cd ${pb}/${branch}/old-errors
  new=""
  for i in *.log; do
    if [ ! -f ../errors/$i ]; then
      new="$new $(basename $i .log)"
    fi
  done
  if [ "x$new" != "x" ]; then
    echo "The following port(s) didn't build the first time around: $new"
  fi
  echo "================================================"
  echo "new failures"
  echo "================================================"
  cd ${pb}/${branch}/errors
  for i in *.log; do
    if [ ! -f ${pb}/${branch}/bak/errors/$i ]; then
      echo -n " $(basename $i .log)"
    fi
  done
  if cd ${pb}/${branch}/bak/packages/All; then
    echo
    echo "================================================"
    echo "old packages"
    echo "================================================"
    for i in *.tgz; do
      if [ ! -f ${pb}/${branch}/packages/All/$i ]; then
        echo -n " $(basename $i .tgz)"
      fi
    done
  fi
  if cd ${pb}/${branch}/bak/errors; then
    echo
    echo "================================================"
    echo "old failures"
    echo "================================================"
    for i in *.log; do
      if [ ! -f ${pb}/${branch}/errors/$i ]; then
        echo -n " $(basename $i .log)"
      fi
    done
  fi
  echo
  echo "================================================"
  echo "new packages"
  echo "================================================"
  cd ${pb}/${branch}/packages/All
  for i in *.tgz; do
    if [ ! -f ${pb}/${branch}/bak/packages/All/$i ]; then
      echo -n " $(basename $i .tgz)"
    fi
  done
  echo
  echo "================================================"
  echo "archiving /usr/ports"
  echo "================================================"
  echo "started at $(date)"
  cd ${pb}/usr
  tar --exclude CVS -czf ${pb}/${branch}/tarballs/ports.tar.gz ports
  echo "ended at $(date)"
  echo "================================================"
  echo "copying distfiles"
  echo "================================================"
  echo "started at $(date)"
  cd ${pb}
  rm -rf bak/distfiles
  mv -f distfiles bak
  su ${user} -c ${scripts}/cpdistfiles > ${pb}/cpdistfiles.log 2>&1 </dev/null &
  # if norestr flag is set, assume it's for ftp and copy the packages over
  if [ "$norestr" = 1 ]; then
    echo "ended at $(date)"
    echo "================================================"
    echo "copying packages"
    echo "================================================"
    su ${user} -c '${scripts}/docppackages ${branch}'
  fi
fi
echo "================================================"
echo "all done at $(date)"
echo "================================================"