forked from OSInside/kiwi-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kiwi.pl
executable file
·2286 lines (2245 loc) · 80.2 KB
/
kiwi.pl
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
#!/usr/bin/perl
#================
# FILE : kiwi.pl
#----------------
# PROJECT : openSUSE Build-Service
# COPYRIGHT : (c) 2012 SUSE LINUX Products GmbH, Germany
# :
# AUTHOR : Marcus Schaefer <[email protected]>
# :
# BELONGS TO : Operating System images
# :
# DESCRIPTION : This is the main script to provide support
# : for creating operating system images
# :
# :
# STATUS : $LastChangedBy: ms $
# : $LastChangedRevision: 1 $
#----------------
use lib './modules','/usr/share/kiwi/modules';
use strict;
#============================================
# perl debugger setup
#--------------------------------------------
# $DB::inhibit_exit = 0;
#============================================
# Modules
#--------------------------------------------
use warnings;
use Carp qw (cluck);
use Getopt::Long;
use File::Basename;
use File::Spec;
use File::Find;
use File::Glob ':glob';
use JSON;
#==========================================
# KIWIModules
#------------------------------------------
use KIWIAnalyseSystem;
use KIWIAnalyseReport;
use KIWIAnalyseTemplate;
use KIWIAnalyseSoftware;
use KIWIBoot;
use KIWICache;
use KIWICommandLine;
use KIWIFilesystemOptions;
use KIWIGlobals;
use KIWIImage;
use KIWIImageCreator;
use KIWIImageFormat;
use KIWILocator;
use KIWILog;
use KIWIQX;
use KIWIRoot;
use KIWIResult;
use KIWIRuntimeChecker;
use KIWIXML;
use KIWIXMLInfo;
use KIWIXMLRepositoryData;
use KIWIXMLValidator;
#============================================
# UTF-8 for output to stdout
#--------------------------------------------
binmode(STDOUT, ":encoding(UTF-8)");
#============================================
# Globals
#--------------------------------------------
my $kiwi = KIWILog -> instance();
my $global = KIWIGlobals -> instance();
my $locator = KIWILocator -> instance();
#============================================
# Variables (operation mode)
#--------------------------------------------
my $kic; # Image preparation / creation
my $icache; # Image Cache creation
my $cmdL; # Command line data container
#==========================================
# IPC; signal setup
#------------------------------------------
local $SIG{"HUP"} = \&quit;
local $SIG{"TERM"} = \&quit;
local $SIG{"INT"} = \&quit;
#==========================================
# main
#------------------------------------------
sub main {
# ...
# This is the KIWI project to prepare and build operating
# system images from a given installation source. The system
# will create a chroot environment representing the needs
# of a XML control file. Once prepared KIWI can create several
# OS image types.
# ---
#========================================
# store caller information
#----------------------------------------
$kiwi -> loginfo ("kiwi @ARGV\n");
$kiwi -> loginfo ("kiwi revision: ".revision()."\n");
#==========================================
# Initialize and check options
#------------------------------------------
init();
#==========================================
# Check for nocolor option
#------------------------------------------
if ($cmdL -> getNoColor()) {
$kiwi -> info ("Switching off colored output\n");
if (! $kiwi -> setColorOff ()) {
kiwiExit (1);
}
}
#==========================================
# remove pre-defined smart channels
#------------------------------------------
if (glob ("/etc/smart/channels/*")) {
KIWIQX::qxx ( "rm -f /etc/smart/channels/*" );
}
#========================================
# Bundle user relevant build results
#----------------------------------------
if ($cmdL->getOperationMode("bundle")) {
my $bundle = KIWIResult -> new (
$cmdL -> getOperationMode("bundle"),
$cmdL -> getImageTargetDir(),
$cmdL -> getBuildNumber()
);
if (! $bundle) {
kiwiExit (1);
}
if (! $bundle -> buildRelease()) {
kiwiExit (1);
}
if (! $bundle -> populateRelease()) {
kiwiExit (1);
}
kiwiExit (0);
}
#========================================
# Prepare and Create in one step
#----------------------------------------
if ($cmdL->getOperationMode("build")) {
#==========================================
# Create destdir if needed
#------------------------------------------
$cmdL -> setDefaultAnswer ("yes");
my $dirCreated = $global -> createDirInteractive(
$cmdL->getImageTargetDir()."/build", $cmdL->getDefaultAnswer()
);
if (! defined $dirCreated) {
kiwiExit (1);
}
#==========================================
# Setup prepare
#------------------------------------------
my $imageTarget = $cmdL -> getImageTargetDir();
my $rootTarget = $imageTarget.'/build/image-root';
$cmdL -> setForceNewRoot (1);
$cmdL -> setRootTargetDir ($rootTarget);
$cmdL -> setOperationMode ("prepare", $cmdL->getConfigDir());
mkdir $imageTarget;
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
my $selectedType = $kic -> getSelectedBuildType();
if ($selectedType && $selectedType eq 'cpio') {
if (! $kic -> prepareBootImage(
$kic-> getSystemXML(),$rootTarget,$rootTarget
)) {
kiwiExit (1);
}
} else {
if (! $kic -> prepareImage()) {
kiwiExit (1);
}
}
#==========================================
# Setup create
#------------------------------------------
$cmdL -> setConfigDir ($rootTarget);
$cmdL -> setOperationMode ("create",$rootTarget);
$cmdL -> setForceNewRoot (0);
$cmdL -> unsetRecycleRootDir();
$kic -> initialize();
if ($selectedType && $selectedType eq 'cpio') {
if (! $kic -> createBootImage(
$kic-> getSystemXML(),$rootTarget,$imageTarget
)) {
kiwiExit (1);
}
} else {
if (! $kic -> createImage()) {
kiwiExit (1);
}
}
kiwiExit (0);
}
#========================================
# Create image cache(s)
#----------------------------------------
if ($cmdL->getOperationMode("initCache")) {
#==========================================
# Process system image description
#------------------------------------------
$kiwi -> info ("Reading image description [Cache]...\n");
my $xml = KIWIXML -> new (
$cmdL->getOperationMode("initCache"),
undef,$cmdL->getBuildProfiles(),$cmdL,undef
);
if (! defined $xml) {
kiwiExit (1);
}
my $pkgMgr = $cmdL -> getPackageManager();
if ($pkgMgr) {
$xml -> setPackageManager($pkgMgr);
}
#==========================================
# Create cache(s)...
#------------------------------------------
my $gdata = $global -> getKiwiConfig();
my $cdir = $cmdL->getCacheDir();
if (! $cdir) {
$cdir = $locator -> getDefaultCacheDir();
}
$icache = KIWICache -> new (
$xml,$cdir,$gdata->{BasePath},
$cmdL->getBuildProfiles(),
$cmdL->getOperationMode("initCache"),
$cmdL
);
if (! $icache) {
kiwiExit (1);
}
my $cacheInit = $icache -> initializeCache (
$cmdL,"create-cache"
);
if (! $cacheInit) {
kiwiExit (1);
}
if (! $icache -> createCache ($cacheInit)) {
kiwiExit (1);
}
kiwiExit (0);
}
#========================================
# Prepare image and build chroot system
#----------------------------------------
if ($cmdL->getOperationMode("prepare")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
my $selectedType = $kic -> getSelectedBuildType();
if ($selectedType && $selectedType eq 'cpio') {
if (! $kic -> prepareBootImage(
$kic -> getSystemXML(),
$cmdL-> getRootTargetDir(),$cmdL-> getRootTargetDir()
)) {
kiwiExit (1);
}
} else {
if (! $kic -> prepareImage()) {
kiwiExit (1);
}
}
kiwiExit (0);
}
#==========================================
# Create image from chroot system
#------------------------------------------
if ($cmdL->getOperationMode("create")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
my $selectedType = $kic -> getSelectedBuildType();
if ($selectedType && $selectedType eq 'cpio') {
if (! $kic -> createBootImage(
$kic -> getSystemXML(),
$cmdL-> getConfigDir(),$cmdL-> getImageTargetDir()
)) {
kiwiExit (1);
}
} else {
if (! $kic -> createImage()) {
kiwiExit (1);
}
}
kiwiExit (0);
}
#==========================================
# Upgrade image in chroot system
#------------------------------------------
if ($cmdL->getOperationMode("upgrade")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> upgradeImage()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Analyse system and create description
#------------------------------------------
if ($cmdL->getOperationMode("analyse")) {
$kiwi -> info ("Starting system analysis\n");
my $destination = $cmdL->getOperationMode("analyse");
$destination = "/var/cache/kiwi/describe/".$destination;
my $system = KIWIAnalyseSystem -> new (
$destination,$cmdL
);
if (! $system) {
kiwiExit (1);
}
if (! $system -> createCustomDataSyncReference()) {
kiwiExit (1);
}
if (! $system -> syncCustomData()) {
kiwiExit (1);
}
$kiwi -> info ("Creating base description files\n");
my $software = KIWIAnalyseSoftware -> new (
$system,$cmdL
);
if (! $software) {
kiwiExit (1);
}
my $template = KIWIAnalyseTemplate -> new (
$destination,$cmdL,$system,$software
);
if (! $template) {
kiwiExit (1);
}
$template -> writeKIWIXMLConfiguration();
$template -> writeKIWIScripts();
$kiwi -> info ("Creating system report\n");
my $report = KIWIAnalyseReport -> new (
$destination,$cmdL,$system,$software
);
if (! $report) {
kiwiExit (1);
}
$report -> createReport();
if (! $system -> commitTransaction()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# setup a splash initrd
#------------------------------------------
if ($cmdL->getOperationMode("setupSplash")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> createSplash()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Create a boot Stick (USB)
#------------------------------------------
if ($cmdL->getOperationMode("bootUSB")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> createImageBootUSB()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Create a boot CD (ISO)
#------------------------------------------
if ($cmdL->getOperationMode("bootCD")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> createImageBootCD()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Create an install CD (ISO)
#------------------------------------------
if ($cmdL->getOperationMode("installCD")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> createImageInstallCD()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Create an install USB stick
#------------------------------------------
if ($cmdL->getOperationMode("installStick")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> createImageInstallStick()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Create an install PXE data set
#------------------------------------------
if ($cmdL->getOperationMode("installPXE")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> createImageInstallPXE()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Create a virtual disk image
#------------------------------------------
if ($cmdL->getOperationMode("bootVMDisk")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> createImageDisk()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Convert image into format/configuration
#------------------------------------------
if ($cmdL->getOperationMode("convert")) {
$kic = KIWIImageCreator -> new ($cmdL);
if (! $kic) {
kiwiExit (1);
}
if (! $kic -> createImageFormat()) {
kiwiExit (1);
}
kiwiExit (0);
}
#==========================================
# Test suite
#------------------------------------------
if ($cmdL->getOperationMode("testImage")) {
$kiwi -> info ("Starting image test run...");
my $suite = "/usr/lib/os-autoinst";
my $distri = "kiwi-$$";
my $type = $cmdL -> getBuildType();
my $image = $cmdL -> getOperationMode("testImage");
my $tcase = $cmdL -> getTestCase();
#==========================================
# Check pre-conditions
#------------------------------------------
if (! -d $suite) {
$kiwi -> failed ();
$kiwi -> error ("Required os-autoinst test-suite not installed");
$kiwi -> failed ();
kiwiExit (1);
}
if (! -f $image) {
$kiwi -> failed ();
$kiwi -> error ("Test image $image doesn't exist");
$kiwi -> failed ();
kiwiExit (1);
}
if (! defined $type) {
$kiwi -> failed ();
$kiwi -> error ("No test image type specified");
$kiwi -> failed ();
kiwiExit (1);
}
if (! defined $tcase) {
$kiwi -> failed ();
$kiwi -> error ("No test test case specified");
$kiwi -> failed ();
kiwiExit (1);
}
if (! -d $tcase."/".$type) {
$kiwi -> failed ();
$kiwi -> error ("Test case for type $type does not exist");
$kiwi -> failed ();
kiwiExit (1);
}
if (! -f $tcase."/env.sh") {
$kiwi -> failed ();
$kiwi -> error ("Can't find environment for this test");
$kiwi -> failed ();
kiwiExit (1);
}
#==========================================
# Turn parameters into absolute pathes
#------------------------------------------
$image = File::Spec->rel2abs ($image);
$tcase = File::Spec->rel2abs ($tcase);
#==========================================
# Create distri link for os-autoinst
#------------------------------------------
my $test = $tcase."/".$type;
my $data = KIWIQX::qxx ("ln -s $test $suite/distri/$distri 2>&1");
my $code = $? >> 8;
if ($code != 0) {
$kiwi -> failed ();
$kiwi -> error ("Can't create distri link: $data");
$kiwi -> failed ();
kiwiExit (1);
}
#==========================================
# Create result mktemp directory
#------------------------------------------
my $out = KIWIQX::qxx ("mktemp -q -d /tmp/kiwi-testrun-XXXXXX 2>&1");
$code = $? >> 8; chomp $out;
if ($code != 0) {
$kiwi -> error ("Couldn't create result directory: $out: $!");
$kiwi -> failed ();
KIWIQX::qxx ("rm -f $suite/distri/$distri");
kiwiExit (1);
}
KIWIQX::qxx ("chmod 755 $out 2>&1");
#==========================================
# Copy environment to result directory
#------------------------------------------
$data = KIWIQX::qxx ("cp $tcase/env.sh $out");
$code = $? >> 8;
if ($code != 0) {
$kiwi -> failed ();
$kiwi -> error ("Failed to copy test environment: $data");
$kiwi -> failed ();
KIWIQX::qxx ("rm -f $suite/distri/$distri");
KIWIQX::qxx ("rm -rf $out");
kiwiExit (1);
}
#==========================================
# Create call file
#------------------------------------------
if (open my $FD,'>',"$out/run.sh") {
print $FD "cd $out\n";
print $FD "export DISTRI=$distri"."\n";
print $FD "export ISO=$image"."\n";
print $FD 'isotovideo $ISO'."\n";
close $FD;
} else {
$kiwi -> failed ();
$kiwi -> error ("Failed to create run test script: $!");
$kiwi -> failed ();
KIWIQX::qxx ("rm -f $suite/distri/$distri");
KIWIQX::qxx ("rm -rf $out");
kiwiExit (1);
}
#==========================================
# Create screen ctrl file
#------------------------------------------
if (open my $FD,'>',"$out/run.ctrl") {
print $FD "logfile /dev/null\n";
close $FD;
} else {
$kiwi -> failed ();
$kiwi -> error ("Failed to create screen ctrl file: $!");
$kiwi -> failed ();
KIWIQX::qxx ("rm -f $suite/distri/$distri");
KIWIQX::qxx ("rm -rf $out");
kiwiExit (1);
}
#==========================================
# Call the test
#------------------------------------------
$kiwi -> done ();
$kiwi -> info ("Calling isotovideo, this can take some time...\n");
$kiwi -> info ("watch the screen session by: 'screen -r'");
KIWIQX::qxx ("chmod u+x $out/run.sh");
KIWIQX::qxx ("screen -L -D -m -c $out/run.ctrl $out/run.sh");
$code = $? >> 8;
KIWIQX::qxx ("rm -f $suite/distri/$distri");
if ($code == 0) {
$kiwi -> done ();
} else {
$kiwi -> failed ();
}
$kiwi -> info ("Find test results in $out");
$kiwi -> done ();
#==========================================
# Read result
#------------------------------------------
my $json;
foreach my $result (glob ("$out/testresults/*/results.json")) {
my $json_fd = FileHandle -> new();
if ($json_fd -> open ($result)) {
local $/;
my $json_text = <$json_fd>;
$json = from_json(
$json_text, { utf8 => 1 }
);
$json_fd -> close();
}
last;
}
#==========================================
# Exit according to test result
#------------------------------------------
if ($json) {
my $status = $json->{overall};
if ($status eq 'fail') {
$kiwi -> info ("Test Failed");
$kiwi -> done();
kiwiExit (1);
} else {
$kiwi -> info ("Test Succeeded");
$kiwi -> failed();
kiwiExit (0);
}
}
}
return 1;
}
#==========================================
# init
#------------------------------------------
sub init {
# ...
# initialize, check privilege and options. KIWI
# requires you to perform at least one action.
# An action is either to prepare or create an image
# ---
#==========================================
# Option variables
#------------------------------------------
my $Help;
my $ArchiveImage; # archive image results into a tarball
my $FSBlockSize; # filesystem block size
my $FSInodeSize; # filesystem inode size
my $FSJournalSize; # filesystem journal size
my $FSMaxMountCount; # filesystem (ext) max mount count between checks
my $FSCheckInterval; # filesystem (ext) max interval between fs checks
my $FSInodeRatio; # filesystem bytes/inode ratio
my $SetImageType; # set image type to use, default is primary type
my $Build; # run prepare and create in one step
my $Prepare; # control XML file for building chroot extend
my $Create; # image description for building image extend
my $InitCache; # create image cache(s) from given description
my $Upgrade; # upgrade physical extend
my $BootVMDisk; # deploy initrd booting from a VM
my $InstallCD; # Installation initrd booting from CD
my $BootCD; # Boot initrd booting from CD
my $BootUSB; # Boot initrd booting from Stick
my $TestImage; # call end-to-end testsuite if installed
my $InstallStick; # Installation initrd booting from USB stick
my $SetupSplash; # setup kernel splash screen
my $Analyse; # inspect running system and create a description
my $Convert; # convert image into given format/configuration
my $MBRID; # custom mbrid value
my @RemovePackage; # remove pack by adding them to the remove list
my $IgnoreRepos; # ignore repositories specified so far
my $SetRepository; # set first repo for building physical extend
my $SetRepositoryType; # set firt repository type
my $SetRepositoryAlias; # alias name for the repository
my $SetRepositoryPriority; # priority for the repository
my @AddRepository; # add repository for building physical extend
my @AddRepositoryType; # add repository type
my @AddRepositoryAlias; # alias name for the repository
my @AddRepositoryPriority; # priority for the repository
my @AddPackage; # add packages to the image package list
my @AddPattern; # add patterns to the image package list
my $Partitioner; # default partitioner
my $ListXMLInfo; # list XML information
my $CheckConfig; # Configuration file to check
my $CreateInstSource; # create installation source from meta packages
my $CreateHash; # create .checksum.md5 for given description
my $CreatePassword; # create crypted password
my $Clone; # clone existing image description
my $InstallCDSystem; # disk system image to be installed on disk
my $TestCase; # path to image description including test/ case
my $InstallStickSystem; # disk system image to be installed on disk
my $InstallPXE; # Installation initrd booting via network
my $InstallPXESystem; # disk system image to be installed on disk
my @Profiles; # list of profiles to include in image
my $ForceBootstrap; # force bootstrap, checked for recycle-root mode
my $ForceNewRoot; # force creation of new root directory
my $NoColor; # don't use colored output (done/failed messages)
my $GzipCmd; # command to run to gzip things
my $TargetStudio; # command to run to create on demand storage
my $Verbosity; # control the verbosity level
my $TargetArch; # target architecture -> writes zypp.conf
my $Debug; # activates the internal stack trace output
my $Format; # format to convert to, vmdk, ovf, etc...
my $defaultAnswer; # default answer to any questions
my $targetDevice; # alternative device instead of a loop device
my $ImageCache; # build an image cache for later re-use
my $RecycleRoot; # use existing root directory incl. contents
my $Destination; # destination directory for logical extends
my $LogFile; # optional file name for logging
my @ListXMLInfoSelection; # info selection for listXMLInfo
my $RootTree; # optional root tree destination
my $BootVMSystem; # system image to be copied on a VM disk
my $BootVMSize; # size of virtual disk
my $BundleBuild; # bundle user relevant build results
my $BundleID; # bundle/build id used in bundle-build
my $StripImage; # strip shared objects and binaries
my $PrebuiltBootImage; # dir. where a prepared boot image may be found
my $ISOCheck; # create checkmedia boot entry
my $CheckKernel; # check if kernel matches in boot and system img
my $LVM; # use LVM partition setup for virtual disk
my $GrubChainload; # install grub loader in first partition not MBR
my $FatStorage; # size of fat partition if syslinux is used
my $DiskStartSector; # location of start sector (default is 2048)
my $EditBootConfig; # allow to run script before bootloader install
my $EditBootInstall; # allow to run script after bootloader install
my $PackageManager; # package manager to use
my $DiskAlignment; # partition alignment, default is 4096 KB
my $DiskBIOSSectorSize; # sector size default is 512 bytes
my $Version; # version information
#==========================================
# create logger and cmdline object
#------------------------------------------
$cmdL = KIWICommandLine -> new ();
if (! $cmdL) {
kiwiExit (1);
}
my $gdata = $global -> getKiwiConfig();
#==========================================
# get options and call non-root tasks
#------------------------------------------
my $result = GetOptions(
"archive-image" => \$ArchiveImage,
"add-package=s" => \@AddPackage,
"add-pattern=s" => \@AddPattern,
"add-profile=s" => \@Profiles,
"add-repo=s" => \@AddRepository,
"add-repoalias=s" => \@AddRepositoryAlias,
"add-repopriority=i" => \@AddRepositoryPriority,
"add-repotype=s" => \@AddRepositoryType,
"bundle-build=s" => \$BundleBuild,
"bundle-id=s" => \$BundleID,
"bootcd=s" => \$BootCD,
"bootusb=s" => \$BootUSB,
"bootvm=s" => \$BootVMDisk,
"bootvm-disksize=s" => \$BootVMSize,
"bootvm-system=s" => \$BootVMSystem,
"build|b=s" => \$Build,
"cache=s" => \$ImageCache,
"check-config=s" => \$CheckConfig,
"check-kernel" => \$CheckKernel,
"clone|o=s" => \$Clone,
"convert=s" => \$Convert,
"create|c=s" => \$Create,
"create-instsource=s" => \$CreateInstSource,
"createhash=s" => \$CreateHash,
"createpassword" => \$CreatePassword,
"debug" => \$Debug,
"del-package=s" => \@RemovePackage,
"destdir|d=s" => \$Destination,
"fat-storage=i" => \$FatStorage,
"force-bootstrap" => \$ForceBootstrap,
"force-new-root" => \$ForceNewRoot,
"format|f=s" => \$Format,
"fs-blocksize=i" => \$FSBlockSize,
"fs-check-interval=i" => \$FSCheckInterval,
"fs-inoderatio=i" => \$FSInodeRatio,
"fs-inodesize=i" => \$FSInodeSize,
"fs-journalsize=i" => \$FSJournalSize,
"fs-max-mount-count=i" => \$FSMaxMountCount,
"edit-bootconfig=s" => \$EditBootConfig,
"edit-bootinstall=s" => \$EditBootInstall,
"grub-chainload" => \$GrubChainload,
"gzip-cmd=s" => \$GzipCmd,
"help|h" => \$Help,
"ignore-repos" => \$IgnoreRepos,
"info|i=s" => \$ListXMLInfo,
"init-cache=s" => \$InitCache,
"installcd=s" => \$InstallCD,
"installcd-system=s" => \$InstallCDSystem,
"installstick=s" => \$InstallStick,
"installstick-system=s" => \$InstallStickSystem,
"installpxe=s" => \$InstallPXE,
"installpxe-system=s" => \$InstallPXESystem,
"isocheck" => \$ISOCheck,
"list|l" => \&listImage,
"logfile=s" => \$LogFile,
"lvm" => \$LVM,
"mbrid=o" => \$MBRID,
"describe=s" => \$Analyse,
"nocolor" => \$NoColor,
"package-manager=s" => \$PackageManager,
"partitioner=s" => \$Partitioner,
"prebuiltbootimage=s" => \$PrebuiltBootImage,
"prepare|p=s" => \$Prepare,
"recycle-root" => \$RecycleRoot,
"root|r=s" => \$RootTree,
"select=s" => \@ListXMLInfoSelection,
"set-repo=s" => \$SetRepository,
"set-repoalias=s" => \$SetRepositoryAlias,
"set-repopriority=i" => \$SetRepositoryPriority,
"set-repotype=s" => \$SetRepositoryType,
"setup-splash=s" => \$SetupSplash,
"strip|s" => \$StripImage,
"target-arch=s" => \$TargetArch,
"targetdevice=s" => \$targetDevice,
"targetstudio=s" => \$TargetStudio,
"type|t=s" => \$SetImageType,
"upgrade|u=s" => \$Upgrade,
"test-image=s" => \$TestImage,
"test-case=s" => \$TestCase,
"disk-start-sector=i" => \$DiskStartSector,
"disk-alignment=i" => \$DiskAlignment,
"disk-sector-size=i" => \$DiskBIOSSectorSize,
"verbose|v=i" => \$Verbosity,
"version" => \$Version,
"yes|y" => \$defaultAnswer,
);
#==========================================
# Check result of options parsing
#------------------------------------------
if ( $result != 1 ) {
usage(1);
}
#========================================
# set logfile if defined at the cmdline
#----------------------------------------
if ($LogFile) {
if ($InitCache) {
# when cache init runs logging should happen on the console
$LogFile = "terminal";
}
$cmdL -> setLogFile($LogFile);
$kiwi -> info ("Setting log file to: $LogFile\n");
if (! $kiwi -> setLogFile ( $LogFile )) {
kiwiExit (1);
}
}
#========================================
# set sector size for alignment
#----------------------------------------
$cmdL -> setDiskBIOSSectorSize (
$DiskBIOSSectorSize
);
#========================================
# set partition alignment
#----------------------------------------
$cmdL -> setDiskAlignment (
$DiskAlignment
);
#========================================
# set start sector for disk images
#----------------------------------------
if (! $DiskStartSector) {
$DiskStartSector = int (
$cmdL -> getDiskAlignment * 1024 / $cmdL -> getDiskBIOSSectorSize()
);
my $defaultStartSector = $gdata -> {DiskStartSector};
if ($DiskStartSector < $defaultStartSector) {
$DiskStartSector = $defaultStartSector;
}
}
$cmdL -> setDiskStartSector (
$DiskStartSector
);
#========================================
# set list of filesystem options
#----------------------------------------
my %init = (
blocksize => $FSBlockSize,
checkinterval => $FSCheckInterval,
inodesize => $FSInodeSize,
inoderatio => $FSInodeRatio,
journalsize => $FSJournalSize,
maxmountcnt => $FSMaxMountCount
);
my $fsOpts = KIWIFilesystemOptions -> new(\%init);
if (! $fsOpts) {
kiwiExit (1);
}
my $status = $cmdL -> setFilesystemOptions ($fsOpts);
if (! $status) {
kiwiExit (1);
}
#========================================
# check if bundle-build option is set
#----------------------------------------
if (defined $BundleID) {
$cmdL -> setBuildNumber ($BundleID);
}
#========================================
# check if archive-image option is set
#----------------------------------------
if (defined $ArchiveImage) {
$cmdL -> setArchiveImage ($ArchiveImage);
}
#========================================
# check if edit-bootconfig option is set
#----------------------------------------
if (defined $EditBootConfig) {
$cmdL -> setEditBootConfig ($EditBootConfig);
}
#========================================
# check if edit-bootinstall option is set
#----------------------------------------
if (defined $EditBootInstall) {
$cmdL -> setEditBootInstall ($EditBootInstall);
}
#========================================
# check if fat-storage option is set
#----------------------------------------
if (defined $FatStorage) {
$cmdL -> setFatStorage ($FatStorage);
}
#========================================
# check if grub-chainload option is set
#----------------------------------------
if (defined $GrubChainload) {
$cmdL -> setGrubChainload ($GrubChainload);
}
#========================================
# check if lvm option is set
#----------------------------------------
if (defined $LVM) {
$cmdL -> setLVM ($LVM);
}
#========================================
# check if check-kernel option is set
#----------------------------------------
if (defined $CheckKernel) {
$cmdL -> setCheckKernel ($CheckKernel);
}
#========================================
# check if isocheck option is set
#----------------------------------------
if (defined $ISOCheck) {
$cmdL -> setISOCheck ($ISOCheck);
}
#========================================
# check if prebuilt boot path is set
#----------------------------------------
if (defined $PrebuiltBootImage) {
$cmdL -> setPrebuiltBootImagePath ($PrebuiltBootImage);
}
#========================================
# check if strip image option is set
#----------------------------------------
if (defined $StripImage) {
$cmdL -> setStripImage ($StripImage);
}
#========================================
# check if XML Info Selection is set
#----------------------------------------
if (@ListXMLInfoSelection) {
$cmdL -> setXMLInfoSelection (\@ListXMLInfoSelection);
}
#========================================
# check if TestCase is specified
#----------------------------------------
if (defined $TestCase) {
$cmdL -> setTestCase ($TestCase);
}
#========================================
# check if Debug is specified
#----------------------------------------
if (defined $Debug) {
$cmdL -> setDebug ($Debug);
}
#========================================
# check if NoColor is specified
#----------------------------------------
if (defined $NoColor) {
$cmdL -> setNoColor ($NoColor);