-
Notifications
You must be signed in to change notification settings - Fork 8
/
functions.sh
executable file
·1746 lines (1412 loc) · 48.8 KB
/
functions.sh
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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# Set the build tag
BUILDTAG="$BUILD"
export BUILDTAG
# Set the repo we pull for build / tests
GITREPO="https://github.com/iXsystems/ixbuild.git"
# Set the branch to use for above repo
if [ -z "$IXBUILDBRANCH" ] ; then
IXBUILDBRANCH="master"
fi
if [ -f "${PROGDIR}/config/${BUILDTAG}.conf" ] ; then
. ${PROGDIR}/config/${BUILDTAG}.conf
fi
cleanup_workdir()
{
if [ -z "$MASTERWRKDIR" ] ; then return 0; fi
if [ ! -d "$MASTERWRKDIR" ] ; then return 0 ; fi
if [ "$MASTERWRKDIR" = "/" ] ; then return 0 ; fi
# If running on host, lets cleanup
if [ -z "$JAILED_TESTS" ] ; then
# Cleanup any leftover mounts
for i in `mount | grep -q "on ${MASTERWRKDIR}/" | awk '{print $1}' | tail -r`
do
umount -f $i
done
fi
# Should be done with unmounts
mount | grep -q "on ${MASTERWRKDIR}/"
if [ $? -ne 0 ] ; then
rm -rf ${MASTERWRKDIR} 2>/dev/null
chflags -R noschg ${MASTERWRKDIR} 2>/dev/null
rm -rf ${MASTERWRKDIR}
fi
cd
}
exit_clean()
{
cleanup_workdir
exit 1
}
create_workdir()
{
if [ ! -d "/tmp/build" ] ; then
mkdir /tmp/build
fi
cd /tmp/build
MASTERWRKDIR=`mktemp -d /tmp/build/XXXX`
# Vanilla Checkout
cocmd="git clone --depth=1 -b ${IXBUILDBRANCH} ${GITREPO} ${MASTERWRKDIR}"
echo "Cloning with: $cocmd"
$cocmd
if [ $? -ne 0 ] ; then exit_clean; fi
cd ${MASTERWRKDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
# Copy over user builds
if [ -d "/ixbuild/builds" ] ; then
rm -rf ${MASTERWRKDIR}/builds
cp -r /ixbuild/builds ${MASTERWRKDIR}/builds
fi
echo "$BUILDTAG" | grep -q -e "freenas" -e "truenas"
if [ $? -eq 0 ] ; then
TBUILDDIR="${MASTERWRKDIR}/freenas"
else
echo "$BUILDTAG" | grep -q -e "trueos" -e "pico"
if [ $? -eq 0 ] ; then
TBUILDDIR="${MASTERWRKDIR}/trueos"
else
TBUILDDIR="${MASTERWRKDIR}/pcbsd"
fi
fi
cp ${BDIR}/${BUILD}/* ${TBUILDDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
cd ${TBUILDDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
}
push_pkgworkdir()
{
cd ${PPKGDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
if [ -z "$SFTPHOST" ] ; then return 0; fi
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${WORKPKG}" >/dev/null 2>/dev/null
echo "Pushing cached pkgs..."
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${WORKPKG}/ >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
if [ $? -ne 0 ] ; then tail -50 ${MASTERWRKDIR}/push.log ; exit_clean; fi
}
pull_pkgworkdir()
{
if [ -z "$SFTPHOST" ] ; then return 0; fi
# Check if we have any workdirs to re-sync
ssh ${SFTPUSER}@${SFTPHOST} "ls ${WORKPKG}" >/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
return 0
fi
if [ ! -d "${PPKGDIR}" ] ; then
mkdir -p ${PPKGDIR}
fi
cd ${PPKGDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
echo "Pulling cached pkgs..."
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" ${SFTPUSER}@${SFTPHOST}:${WORKPKG}/ . >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
if [ $? -ne 0 ] ; then tail -50 ${MASTERWRKDIR}/push.log ; exit_clean; fi
}
push_world()
{
cd ${TBUILDDIR}/fbsd-dist
if [ $? -ne 0 ] ; then exit_clean; fi
# Pushing to a local directory?
if [ -z "$SFTPHOST" ] ; then
if [ ! -d "${PCBSDBDIR}/fbsd-dist/${WORLDTREL}" ] ; then mkdir -p ${PCBSDBDIR}/fbsd-dist/${WORLDTREL}; fi
rm ${PCBSDBDIR}/fbsd-dist/${WORLDTREL}/* 2>/dev/null
echo "Saving FreeBSD dist files -> ${PCBSDBDIR}/fbsd-dist/${WORLDTREL}"
cp * ${PCBSDBDIR}/fbsd-dist/${WORLDTREL}/
return 0
fi
# Push world packages to work directory
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${WORKWORLD}" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${WORKWORLD}/ >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
if [ $? -ne 0 ] ; then tail -50 ${MASTERWRKDIR}/push.log ; exit_clean; fi
if [ -n "$PKGBASE" ] ; then
# Push packages to base directory
cd ${TBUILDDIR}/fbsd-pkg
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${PKGSTAGE}-base" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${PKGSTAGE}-base/ >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
fi
# Dist files to dist directory
cd ${TBUILDDIR}/fbsd-dist
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${ISOSTAGE}/dist" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${ISOSTAGE}/dist/ >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
}
pull_world()
{
if [ ! -d "${TBUILDDIR}/fbsd-dist" ] ; then
mkdir -p ${TBUILDDIR}/fbsd-dist
fi
# Pulling from a local dist set
if [ -z "$SFTPHOST" ] ; then
if [ ! -d "${PCBSDBDIR}/fbsd-dist/${WORLDTREL}" ] ; then return 1; fi
cp ${PCBSDBDIR}/fbsd-dist/${WORLDTREL}/* ${TBUILDDIR}/fbsd-dist/
if [ $? -ne 0 ] ; then
return 1
fi
return 0
fi
# Pulling from a remote dist set
# Check if the world exists
ssh ${SFTPUSER}@${SFTPHOST} "ls ${WORKWORLD}" >/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
return 1
fi
if [ -n "$PKGBASE" ] ; then
# Push packages to base directory
mkdir ${TBUILDDIR}/fbsd-pkg
cd ${TBUILDDIR}/fbsd-pkg
if [ $? -ne 0 ] ; then exit_clean; fi
echo "Pulling base packages..."
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" ${SFTPUSER}@${SFTPHOST}:${PKGSTAGE}-base/ . >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
fi
cd ${TBUILDDIR}/fbsd-dist
if [ $? -ne 0 ] ; then exit_clean; fi
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" ${SFTPUSER}@${SFTPHOST}:${WORKWORLD}/ . >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
if [ $? -ne 0 ] ; then tail -50 ${MASTERWRKDIR}/push.log ; exit_clean; fi
return 0
}
pull_iso()
{
if [ -z "$SFTPHOST" ] ; then return 0; fi
# Check if we have any workdirs to re-sync
ssh ${SFTPUSER}@${SFTPHOST} "ls ${ISOSTAGE}" >/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
return 0
fi
if [ ! -d "${TBUILDDIR}/iso" ] ; then
mkdir -p ${TBUILDDIR}/iso
fi
cd ${TBUILDDIR}/iso
if [ $? -ne 0 ] ; then exit_clean; fi
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" ${SFTPUSER}@${SFTPHOST}:${ISOSTAGE}/ . >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
if [ $? -ne 0 ] ; then tail -50 ${MASTERWRKDIR}/push.log ; exit_clean; fi
}
jenkins_world()
{
create_workdir
cd ${TBUILDDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
make world
if [ $? -ne 0 ] ; then exit_clean; fi
push_world
if [ -z "$1" ] ; then
cleanup_workdir
fi
}
jenkins_jail()
{
create_workdir
pull_world
if [ $? -ne 0 ] ; then
jenkins_world "1"
pull_world
if [ $? -ne 0 ] ; then
exit_clean "Failed getting world files"
fi
fi
cd ${TBUILDDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
make jail
if [ $? -ne 0 ] ; then exit_clean; fi
cleanup_workdir
exit 0
}
jenkins_pkg()
{
create_workdir
# Pull in the world directory
pull_world
if [ $? -ne 0 ] ; then
jenkins_world "1"
pull_world
if [ $? -ne 0 ] ; then
exit_clean "Failed getting world files"
fi
fi
cd ${TBUILDDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
# Check if we have a more current pkg set on the local box
if [ -n "$SFTPHOST" ] ; then
remotetime=`ssh ${SFTPUSER}@${SFTPHOST} "cat ${PKGSTAGE}/.started" 2>/dev/null`
localtime=`cat ${PPKGDIR}/.started 2>/dev/null`
if [ -n "$remotetime" -a -n "$localtime" ] ; then
if [ $remotetime -lt $localtime ] ; then
push_pkgworkdir
fi
fi
fi
cd ${TBUILDDIR}
make ports-update-all
if [ $? -ne 0 ] ; then exit_clean; fi
# Pull the workdir from the cache
pull_pkgworkdir
cd ${TBUILDDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
# Save the timestamp of when we started this poud run
if [ ! -d "${PPKGDIR}" ] ; then mkdir -p ${PPKGDIR} ; fi
date +"%s" >${PPKGDIR}/.started
# Make the release or ISO packages
if [ "$1" = "release" ] ; then
make ports
if [ $? -ne 0 ] ; then push_pkgworkdir; exit_clean; fi
else
make iso-ports
if [ $? -ne 0 ] ; then push_pkgworkdir; exit_clean; fi
fi
# Push over the workdir to the cache
push_pkgworkdir
# Yay, success! Lets rsync the package set to staging machine
cd $PPKGDIR
if [ $? -ne 0 ] ; then exit_clean; fi
if [ -n "$SFTPHOST" ] ; then
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${PKGSTAGE}" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${PKGSTAGE} >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
if [ $? -ne 0 ] ; then tail -50 ${MASTERWRKDIR}/push.log ; exit_clean; fi
fi
cleanup_workdir
exit 0
}
jenkins_iso()
{
create_workdir
pull_world
# Pull the workdir from the cache
pull_pkgworkdir
cd ${TBUILDDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
make image
if [ $? -ne 0 ] ; then exit_clean; fi
# Now lets sync the ISOs
cd ${TBUILDDIR}/iso
if [ $? -ne 0 ] ; then exit_clean; fi
if [ -n "$SFTPHOST" ] ; then
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${ISOSTAGE}" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${ISOSTAGE} >${MASTERWRKDIR}/push.log 2>${MASTERWRKDIR}/push.log
if [ $? -ne 0 ] ; then tail -50 ${MASTERWRKDIR}/push.log ; exit_clean; fi
fi
# Do ISO artifact creation for Jenkins
if [ -d "${WORKSPACE}" ] ; then
rm -rf "${WORKSPACE}/iso"
mkdir -p "${WORKSPACE}/iso"
cp -r ${TBUILDDIR}/iso/* "${WORKSPACE}/iso"
chown -R jenkins:jenkins "${WORKSPACE}"
fi
cleanup_workdir
exit 0
}
generatePackageManifestFile()
{
#inputs: 1: Directory of package files (*.txz), 2: text file for manifest
#Note: This will **replace** the manifest info in the file!!
_pkgdir=$1
_pkgfile=$2
#Remove the old file if it exists
if [ -e "${_pkgfile}" ] ; then
rm "${_pkgfile}"
fi
for _line in `find "${_pkgdir}" -depth 1 -name "*.txz" | sort`
do
#Cleanup the individual line (directory, suffix)
_line=$(echo ${_line} | rev | cut -d "/" -f 1| rev | sed "s|.txz||g")
#Make sure it is a valid package name - otherwise skip it
case "${_line}" in
fbsd-distrib) continue ;;
*-*) ;;
*) continue ;;
esac
#Grab the version tag (ignore the first word - name might start with a number)
_version=$(echo ${_line} | cut -d '-' -f 2-12 | rev | cut -d '-' -f 1-2 | rev)
#check that the version string starts with a number, otherwise only use the last "-" section
_tmp=$(echo ${_version} | egrep '^[0-9]+')
if [ -z "${_tmp}" ] ; then
_version=$(echo ${_line} | rev | cut -d '-' -f 1 | rev)
fi
_name=$(echo ${_line} | sed "s|-${_version}||g")
echo "${_name} : ${_version}" >> ${_pkgfile}
#echo "Name: ${_name} : Version: ${_version}"
#echo " -raw line: ${line}"
done
#cleanup the temporary variables
unset _pkgdir
unset _pkgfile
unset _line
unset _name
unset _version
unset _tmp
}
jenkins_publish_pkg()
{
if [ ! -d "${SFTPFINALDIR}/pkg/${TARGETREL}" ] ; then
echo "Missing packages to push!"
exit 1
fi
#Generate the pkg manifest files every time we push to the CDN
echo "Generating package manifest..."
_all_pkgs_dir="amd64/All" #Relative to the release dir
_base_pkgs_dir="amd64-base"
generatePackageManifestFile "${SFTPFINALDIR}/pkg/${TARGETREL}/${_all_pkgs_dir}" "${SFTPFINALDIR}/pkg/${TARGETREL}/pkg_manifest.pkglist"
generatePackageManifestFile "${SFTPFINALDIR}/pkg/${TARGETREL}/${_base_pkgs_dir}" "${SFTPFINALDIR}/pkg/${TARGETREL}/FreeBSD_manifest.pkglist"
unset _all_pkgs_dir
unset _base_pkgs_dir
# Set target locations
scale="pcbsd@pcbsd-master.scaleengine.net"
target="/usr/home/pcbsd/mirror/pkg"
case ${1} in
edge) RTARGET="${TARGETREL}/edge" ;;
unstable) RTARGET="${TARGETREL}/unstable" ;;
*) RTARGET="${TARGETREL}" ;;
esac
# Make sure remote target exists
echo "ssh ${scale} mkdir -p ${target}/${RTARGET}"
ssh ${scale} "mkdir -p ${target}/${RTARGET}" >/dev/null 2>/dev/null
# Copy packages
rsync -va --delete-delay --delay-updates -e "ssh -o StrictHostKeyChecking=no" ${SFTPFINALDIR}/pkg/${TARGETREL}/ ${scale}:${target}/${RTARGET}/
if [ $? -ne 0 ] ; then exit_clean; fi
}
jenkins_publish_pkg_ipfs()
{
# Location of our ipfs-cluster-ctl command
PATH="${PATH}:/root/bin"
export PATH
# Now lets sync the docs
if [ -z "$SFTPHOST" ] ; then exit 1; fi
tstamp=$(date +%s)
echo "mkdir -p /root/trueos/${TARGETREL}/${tstamp}"
mkdir -p /root/trueos/${TARGETREL}/${tstamp}
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" ${SFTPUSER}@${SFTPHOST}:${SFTPFINALDIR}/pkg/${TARGETREL}/ /root/trueos/${TARGETREL}/${tstamp}
if [ $? -ne 0 ] ; then exit_clean ; fi
if [ ! -e "/root/trueos/${TARGETREL}/${tstamp}/manifest.pkglist" ] ; then
#Note: There are two pkg publish jobs - so only generate the manifest if it has not already been created
echo "Generating package manifest..."
generatePackageManifestFile "/root/trueos/${TARGETREL}/${tstamp}" "/root/trueos/${TARGETREL}/${tstamp}/manifest.pkglist"
fi
# Which hash file we are updating
if [ "$TARGERREL" = "master" ] ; then
HFILE="trueos-ipfs-stable"
KEEPHASH="2"
else
HFILE="trueos-ipfs-unstable"
KEEPHASH="3"
fi
echo "Setting permissions on /root/trueos/${TARGETREL}/${tstamp}"
chown -R root:wheel /root/trueos/${TARGETREL}/${tstamp}
# Copy packages
echo "Adding packages to IPFS, this will take a while..."
ipfs-go config --json Experimental.FilestoreEnabled true
echo "ipfs-go add --nocopy -r -Q --pin /root/trueos/${TARGETREL}/${tstamp}"
PKGHASH=$(ipfs-go add --nocopy -r -Q --pin /root/trueos/${TARGETREL}/${tstamp})
if [ $? -ne 0 ] ; then exit_clean; fi
echo "Finished Adding: $PKGHASH"
echo "Pinning to IPFS cluster: $PKGHASH"
ipfs-cluster-ctl pin add ${PKGHASH}
# Save hash to list of pins
echo "$tstamp $PKGHASH" >>/var/db/${HFILE}
# Unpin hashes beyond the KEEPHASH
PRUNEHASH=$(expr $KEEPHASH + 1)
cat /var/db/${HFILE} | sort -r | tail -n +${PRUNEHASH} | while read line
do
otstamp=$(echo $line | awk '{print $1}')
ohash=$(echo $line | awk '{print $2}')
echo "Unpinning: $ohash"
ipfs-cluster-ctl pin rm $ohash
if [ -d "/root/trueos/${TARGETREL}/${otstamp}" ] ; then
echo "Removing pruned package files: /root/trueos/${TARGETRE}/${otstamp}"
rm -rf "/root/trueos/${TARGETREL}/${otstamp}"
fi
done
# Pruning of old pinned hashes
cat /var/db/${HFILE} | sort -r | head -n ${KEEPHASH} >/var/db/${HFILE}.new
mv /var/db/${HFILE}.new /var/db/${HFILE}
# Publish HASH to trueos-ipfs-unstable file
scp /var/db/${HFILE} kris@web.pcbsd.org:updates/${HFILE}
if [ $? -ne 0 ] ; then exit_clean; fi
echo "Doing garbage collection of IPFS..."
ipfs-go repo gc
}
jenkins_promote_pkg()
{
# Set target locations
scale="pcbsd@pcbsd-master.scaleengine.net"
mdate=$(date "+%y%m%d%H")
if [ -n "TARGETDATE" ] ; then
mdate="$TARGETDATE"
fi
otarget="/usr/home/pcbsd/mirror/pkg/master/edge"
ntarget="/usr/home/pcbsd/mirror/pkg/master-${mdate}"
# Make new master-<DATE> directory
ssh ${scale} "mkdir -p ${target}"
# Copy over the amd64-base packages from UNSTABLE -> STABLE
rcmd="rsync -va --delete-delay --delay-updates ${otarget}/amd64-base/ ${ntarget}/amd64-base/"
echo "Running on remote: $rcmd"
ssh ${scale} "$rcmd"
if [ $? -ne 0 ] ; then exit_clean; fi
# Copy over the amd64 packages from UNSTABLE -> STABLE
rcmd="rsync -va --delete-delay --delay-updates ${otarget}/amd64/ ${ntarget}/amd64/"
echo "Running on remote: $rcmd"
ssh ${scale} "$rcmd"
if [ $? -ne 0 ] ; then exit_clean; fi
echo "Packages promoted to: ${target}"
echo "Don't forget to sym-link master -> ${target}"
}
generateJsonObjectForImage()
{
i=$1
# Now add the information about this file to the JSON manifest
if [ -n "${_PUSH_JSON_FILE}" ] ; then
_PUSH_JSON_FILE="${_PUSH_JSON_FILE}, " #add the comma separation between elements
fi
_name=`echo ${i} | cut -d - -f 2` #Desktop or Server
_filetype=`echo ${i} | rev | cut -d . -f 1 | rev` #iso or img
_imgtype=`echo ${i} | cut -d - -f 6` #UNSTABLE or <junk>
_type=`echo ${i} | rev | cut -d . -f 2 | cut -d - -f 1 | rev` #DVD or USB
_date=`date "+%Y-%m-%d"`
if [ ! "UNSTABLE" == "${_imgtype}" ] ; then
_imgtype="STABLE"
_dateversion=`echo ${i} | cut -d - -f 3` #YY.MM
else
_dateversion=`echo ${i} | cut -d - -f 3-5` #YYYY-MM-DD
fi
_sha256=`cat ${i}.sha256`
_PUSH_JSON_FILE="${_PUSH_JSON_FILE} { \"name\":\"TrueOS ${_name} (${_type} image)\", \"date\":\"${_date}\", \"version\":\"${_dateversion}\", \"sha256\":\"${_sha256}\", \"type\":\"${_imgtype}\", \"platform\":\"${_name}\", \"filetype\":\"${_filetype}\", \"url\":\"${i}\""
for j in "md5" "sha256" "sig" "torrent"
do
if [ -e "${i}.${j}" ] ; then
_PUSH_JSON_FILE="${_PUSH_JSON_FILE}, \"${j}_url\":\"${i}.${j}\""
fi
done
_PUSH_JSON_FILE="${_PUSH_JSON_FILE} }" #close off the json object
#clean up the internal variables
unset _name
unset _filetype
unset _imgtype
unset _type
unset _dateversion
unset _date
unset _sha256
}
jenkins_publish_iso()
{
if [ ! -d "${SFTPFINALDIR}/iso/${TARGETREL}" ] ; then
echo "Missing iso to push!"
exit 1
fi
if [ -n "$1" -a "$1" = "edge" ] ; then
RTARGET="${TARGETREL}/edge"
else
RTARGET="${TARGETREL}"
fi
# Set the targets
scale="pcbsd@pcbsd-master.scaleengine.net"
target="/usr/home/pcbsd/mirror/iso"
ssh ${scale} "mkdir -p ${target}/${RTARGET}/${ARCH}" >/dev/null 2>/dev/null
# We sign the ISO's with gpg
cd ${SFTPFINALDIR}/iso/${TARGETREL}/${ARCH}/
if [ $? -ne 0 ] ; then exit_clean; fi
unset _PUSH_JSON_FILE #Make sure this internal variable is cleared first
for i in `ls *.iso *.img *.xz`
do
echo "Signing: $i"
rm ${i}.sig >/dev/null 2>/dev/null
gpg -u releng@trueos.org --output ${i}.sig --detach-sig ${i}
# Now add the information about this file to the JSON manifest
_latest=`echo ${i} | cut -d - -f 1`
if [ ! "${_latest}" == "latest" ] ; then #Skip the "latest-[desktop/server]" symlinks
echo "Adding Image to JSON Manifest: ${i}"
generateJsonObjectForImage ${i}
fi
done
# Generate the files.json file with all information about the files that are available
echo "[ ${_PUSH_JSON_FILE} ]" > files.json #make sure to encapulate the list of JSON objects within an array
unset _PUSH_JSON_FILE #clear it out (done with it)
# Copy the ISOs
rsync -va --delete-delay --delay-updates -e "ssh -o StrictHostKeyChecking=no" ${SFTPFINALDIR}/iso/${TARGETREL}/${ARCH}/ ${scale}:${target}/${RTARGET}/${ARCH}/
if [ $? -ne 0 ] ; then exit_clean; fi
}
jenkins_vm()
{
create_workdir
pull_world
pull_iso
cd ${TBUILDDIR}
if [ $? -ne 0 ] ; then exit_clean; fi
make vm
if [ $? -ne 0 ] ; then exit_clean; fi
# Now lets sync the ISOs
cd ${TBUILDDIR}/iso
if [ $? -ne 0 ] ; then exit_clean; fi
if [ -n "$SFTPHOST" ] ; then
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${ISOSTAGE}" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${ISOSTAGE}
if [ $? -ne 0 ] ; then exit_clean; fi
fi
cleanup_workdir
exit 0
}
jenkins_truenas_push_docs()
{
# Now lets upload the docs
if [ -n "$SFTPHOST" ] ; then
rm -rf /tmp/handbookpush 2>/dev/null
mkdir -p /tmp/handbookpush
# Get the docs from the staging server
rsync -va --delete-delay --delay-updates -e "ssh -o StrictHostKeyChecking=no" ${SFTPUSER}@${SFTPHOST}:${DOCSTAGE}/tn-handbook/ /tmp/handbookpush
if [ $? -ne 0 ] ; then exit_clean; fi
cd /tmp/handbookpush
if [ $? -ne 0 ] ; then exit_clean ; fi
# Make them live!
rsync -a -O -v -z --delete -e 'ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa.jenkins' . jenkins@support.ixsystems.com:/usr/local/www/vhosts/truenas-guide
if [ $? -ne 0 ] ; then exit_clean; fi
rm -rf /tmp/handbookpush 2>/dev/null
fi
return 0
}
jenkins_freenas_push_be()
{
# Figure out the flavor for this test
echo $BUILDTAG | grep -q "truenas"
if [ $? -eq 0 ] ; then
FLAVOR="truenas"
else
FLAVOR="freenas"
fi
if [ -z "${RSYNCHOST}" ] ; then
exit 1
echo "Missing $RSYNCHOST"
fi
if [ -z "${PUSHPATH}" ] ; then
exit 1
echo "Missing $PUSHPATH"
fi
ssh $RSYNCHOST mkdir -p $PUSHPATH/$FLAVOR/$JENKINSVERSION 2>/dev/null
rsync -avh /$BUILDTAG/freenas/_BE/repo-manifest $RSYNCHOST:$PUSHPATH/$FLAVOR/$JENKINSVERSION/build_env/
rsync -avh /$BUILDTAG/freenas/_BE/objs/debug/ $RSYNCHOST:$PUSHPATH/$FLAVOR/$JENKINSVERSION/build_env/debug/
rsync -avh /$BUILDTAG/freenas/_BE/objs/world/ $RSYNCHOST:$PUSHPATH/$FLAVOR/$JENKINSVERSION/build_env/world/
rsync -avh /$BUILDTAG/freenas/_BE/release/ $RSYNCHOST:$PUSHPATH/$FLAVOR/$JENKINSVERSION/release/
}
jenkins_freenas_push_docs()
{
if [ -z "$DOCBRANCH" ] ; then
DOCBRANCH="master"
fi
echo "Using DOCBRANCH: $DOCBRANCH"
# Set the default DOC target if not provided
if [ -z "$DOCTARGET" ] ; then
DOCTARGET="html11"
fi
# Set the default remote directory if not provided
if [ -z "REMOTE_DIR" ] ; then
if [ "$1" = "truenas" ] ; then
REMOTE_DIR="/usr/local/www/vhosts/truenas-guide"
else
REMOTE_DIR="/tank/doc/userguide/${DOCTARGET}"
fi
fi
# Set all the SSH options / overrides
if [ -z "$SSHPORT" ] ; then
SSHPORT="22"
fi
if [ -z "$SSHUSER" ] ; then
SSHUSER="jenkins"
fi
if [ -z "$SSHHOST" ] ; then
if [ "$1" = "truenas" ] ; then
SSHHOST="support.ixsystems.com"
else
SSHHOST="api.freenas.org"
fi
fi
# Now lets upload the docs
if [ -z "$SFTPHOST" ] ; then
echo "ERROR: Unset SFTPHOST!"
exit 1
fi
echo "Uploading Docs to: ${SSHUSER}@${SSHHOST}:${SSHPORT} -> ${REMOTE_DIR}"
rm -rf /tmp/handbookpush 2>/dev/null
mkdir -p /tmp/handbookpush
# Get the docs from the staging server
rsync -va --delete-delay --delay-updates -e "ssh -o StrictHostKeyChecking=no" ${SFTPUSER}@${SFTPHOST}:${DOCSTAGE}/handbook-${DOCBRANCH}/ /tmp/handbookpush
if [ $? -ne 0 ] ; then exit_clean; fi
cd /tmp/handbookpush
if [ $? -ne 0 ] ; then exit_clean ; fi
# Make them live!
echo "Pushing to ${REMOTE_DIR}"
ssh -p ${SSHPORT} ${SSHUSER}@${SSHHOST} mkdir -p ${REMOTE_DIR} || true
rsync -a -v -z --delete --exclude "truenas*" -e "ssh -p ${SSHPORT} -o StrictHostKeyChecking=no" . ${SSHUSER}@${SSHHOST}:${REMOTE_DIR}
if [ $? -ne 0 ] ; then exit_clean; fi
rm -rf /tmp/handbookpush 2>/dev/null
return 0
}
jenkins_freenas_push_api()
{
# Now lets upload the docs
if [ -n "$SFTPHOST" ] ; then
rm -rf /tmp/apipush 2>/dev/null
mkdir -p /tmp/apipush
# Get the docs from the staging server
rsync -va --delete-delay --delay-updates -e "ssh -o StrictHostKeyChecking=no" ${SFTPUSER}@${SFTPHOST}:${DOCSTAGE}/api/ /tmp/apipush
if [ $? -ne 0 ] ; then exit_clean; fi
cd /tmp/apipush
if [ $? -ne 0 ] ; then exit_clean ; fi
# Make them live!
rsync -a -v -z --delete --exclude "truenas*" -e 'ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa.jenkins' . jenkins@api.freenas.org:/tank/api/html
if [ $? -ne 0 ] ; then exit_clean; fi
rm -rf /tmp/apipush 2>/dev/null
fi
return 0
}
jenkins_freenas_push()
{
# Sanity check that the build was done on this node
if [ ! -d "${FNASBDIR}" ] ; then
echo "ERROR: No such build dir: ${FNASBDIR}"
exit 1
fi
cd ${FNASBDIR}
if [ $? -ne 0 ] ; then exit_clean ; fi
git reset --hard
git pull
PROFILEARGS="$BUILDOPTS"
if [ -z "$JENKINSVERSION" ] ; then
echo "ERROR: Missing JENKINSVERSION="
fi
PROFILEARGS="${PROFILEARGS} VERSION=$JENKINSVERSION"
if [ -n "$JENKINSINTUPDATE" -a "$JENKINSINTUPDATE" = "true" ] ; then
PROFILEARGS="${PROFILEARGS} INTERNAL_UPDATE=yes"
else
if [ -z "$RELENG_PASSWORD" ] ; then
echo "ERROR: Pushing public with no password set!"
exit 1
fi
fi
if [ -n "$RELENG_PASSWORD" ] ; then
# Set the correct variable release-push expects
echo "Setting IX_KEY_PASSWORD from RELENG_PASSWORD"
IX_KEY_PASSWORD="${RELENG_PASSWORD}"
export IX_KEY_PASSWORD
fi
# Skip deltas for now
DELTAS="0"
export DELTAS
# Push the release to download.freenas.org
echo "make release-push ${PROFILEARGS}"
make release-push ${PROFILEARGS}
if [ $? -ne 0 ] ; then exit_clean ; fi
return 0
}
jenkins_freenas_push_nightly()
{
# Sanity check that the build was done on this node
if [ ! -d "${FNASBDIR}" ] ; then
echo "ERROR: No such build dir: ${FNASBDIR}"
exit 1
fi
cd ${FNASBDIR}
if [ $? -ne 0 ] ; then exit_clean ; fi
# Set CHANGELOG
if [ -e "${FNASBDIR}/ChangeLog" ] ; then
echo "Setting CHANGELOG: ${FNASBDIR}/ChangeLog"
CHANGELOG="${FNASBDIR}/ChangeLog"
export CHANGELOG
fi
# Skip deltas
DELTAS="0"
export DELTAS
if [ -z "$JENKINSINTUPDATE" -o "$JENKINSINTUPDATE" = "false" ] ; then
PROFILEARGS="${PROFILEARGS}"
else
PROFILEARGS="${PROFILEARGS} INTERNAL_UPDATE=yes"
fi
# Push the release
echo "make release-push ${BUILDOPTS} ${PROFILEARGS}"
make release-push ${BUILDOPTS} ${PROFILEARGS}
if [ $? -ne 0 ] ; then exit_clean ; fi
return 0
}
jenkins_truenas_docs()
{
if [ ! -d "/tmp/build" ] ; then
mkdir /tmp/build
fi
DDIR=`mktemp -d /tmp/build/XXXX`
git clone --depth=1 https://github.com/freenas/freenas-docs ${DDIR}
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
cd ${DDIR}/userguide
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
make TAG=truenas html
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
mv ${DDIR}/userguide/processed/_build/html ${DDIR}/html
make TAG=truenas pdf
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
# Put the PDF in the same dir as html
mv ${DDIR}/html ${DDIR}/userguide/processed/_build/html
cp ${DDIR}/userguide/processed/_build/latex/*.pdf ${DDIR}/userguide/processed/_build/html/
# Now lets sync the docs
if [ -n "$SFTPHOST" ] ; then
cd ${DDIR}/userguide/processed/_build/html/
if [ $? -ne 0 ] ; then exit_clean ; fi
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${DOCSTAGE}/tn-handbook" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${DOCSTAGE}/tn-handbook
if [ $? -ne 0 ] ; then exit_clean; fi
fi
rm -rf ${DDIR}
return 0
}
jenkins_freenas_docs()
{
if [ ! -d "/tmp/build" ] ; then
mkdir /tmp/build
fi
DDIR=`mktemp -d /tmp/build/XXXX`
if [ -z "$DOCBRANCH" ] ; then
DOCBRANCH="master"
fi
echo "Using DOCBRANCH: $DOCBRANCH"
if [ -z "DOCTAG" ] ; then
DOCTAG="freenas"
fi
git clone -b $DOCBRANCH --depth=1 https://github.com/freenas/freenas-docs ${DDIR}
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
cd ${DDIR}/userguide
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
make TAG=${DOCTAG} html
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
mv ${DDIR}/userguide/processed/_build/html ${DDIR}/html
make TAG=${DOCTAG} pdf
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
# Put the PDF in the same dir as html
mv ${DDIR}/html ${DDIR}/userguide/processed/_build/html
cp ${DDIR}/userguide/processed/_build/latex/*.pdf ${DDIR}/userguide/processed/_build/html/
# Now lets sync the docs
if [ -n "$SFTPHOST" ] ; then
cd ${DDIR}/userguide/processed/_build/html/
if [ $? -ne 0 ] ; then exit_clean ; fi
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${DOCSTAGE}/handbook-${DOCBRANCH}" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${DOCSTAGE}/handbook-${DOCBRANCH}
fi
rm -rf ${DDIR}
return 0
}
jenkins_freenas_api()
{
if [ ! -d "/tmp/build" ] ; then
mkdir /tmp/build
fi
DDIR=`mktemp -d /tmp/build/XXXX`
git clone --depth=1 https://github.com/freenas/freenas ${DDIR}
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
cd ${DDIR}/docs/api
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
make html
if [ $? -ne 0 ] ; then rm -rf ${DDIR} ; exit 1 ; fi
# Now lets sync the api docs
if [ -n "$SFTPHOST" ] ; then
cd ${DDIR}/docs/api/_build/html/
if [ $? -ne 0 ] ; then exit_clean ; fi
ssh ${SFTPUSER}@${SFTPHOST} "mkdir -p ${DOCSTAGE}/api" >/dev/null 2>/dev/null
rsync -va --delete -e "ssh -o StrictHostKeyChecking=no" . ${SFTPUSER}@${SFTPHOST}:${DOCSTAGE}/api
if [ $? -ne 0 ] ; then exit_clean; fi
fi