Class: Yast::AutoinstScriptsClass
- Inherits:
-
Module
- Object
- Module
- Yast::AutoinstScriptsClass
- Defined in:
- ../../src/modules/AutoinstScripts.rb
Instance Method Summary (collapse)
-
- (void) AddEditScript(scriptName, source, interpreter, type, chrooted, debug, feedback, network, feedback_type, location, notification)
Add or edit a script.
-
- (Object) AutoinstScripts
Constructor.
-
- (void) deleteScript(scriptName)
delete a script from a list.
-
- (Hash) Export
Dump the settings to a map, for autoinstallation use.
-
- (Boolean) GetModified
Functions which returns if the settings were modified.
-
- (Object) Import(s)
Get all the configuration from a map.
- - (Object) interactiveScript(shell, debug, scriptPath, params, current_logdir, scriptName)
- - (Object) main
-
- (Object) mergeScripts
merge all types of scripts into one single list.
- - (Object) Resolve_location(d)
- - (Object) Resolve_relurl(script)
- - (Object) Resolve_ws(script)
-
- (Object) SetModified
Function sets internal variable, which indicates, that any settings were modified, to “true”.
-
- (Object) splitParams(s)
bidirectional feedback during script execution Experimental.
-
- (String) Summary
Return Summary.
-
- (String) typeString(type)
return type of script as formatted string.
-
- (Boolean) Write(type, special)
Execute pre scripts.
Instance Method Details
- (void) AddEditScript(scriptName, source, interpreter, type, chrooted, debug, feedback, network, feedback_type, location, notification)
This method returns an undefined value.
Add or edit a script
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 |
# File '../../src/modules/AutoinstScripts.rb', line 424 def AddEditScript(scriptName, source, interpreter, type, chrooted, debug, feedback, network, feedback_type, location, notification) mod = false @merged = Builtins.maplist(@merged) do |script| # Edit if Ops.get_string(script, "filename", "") == scriptName oldScript = {} oldScript = Builtins.add(oldScript, "filename", scriptName) oldScript = Builtins.add(oldScript, "source", source) oldScript = Builtins.add(oldScript, "interpreter", interpreter) oldScript = Builtins.add(oldScript, "type", type) oldScript = Builtins.add(oldScript, "chrooted", chrooted) oldScript = Builtins.add(oldScript, "debug", debug) oldScript = Builtins.add(oldScript, "feedback", feedback) oldScript = Builtins.add(oldScript, "network_needed", network) oldScript = Builtins.add(oldScript, "feedback_type", feedback_type) oldScript = Builtins.add(oldScript, "location", location) oldScript = Builtins.add(oldScript, "notification", notification) mod = true next deep_copy(oldScript) else next deep_copy(script) end end if !mod script = {} script = Builtins.add(script, "filename", scriptName) script = Builtins.add(script, "source", source) script = Builtins.add(script, "interpreter", interpreter) script = Builtins.add(script, "type", type) script = Builtins.add(script, "chrooted", chrooted) script = Builtins.add(script, "debug", debug) script = Builtins.add(script, "feedback", feedback) script = Builtins.add(script, "network_needed", network) script = Builtins.add(script, "feedback_type", feedback_type) script = Builtins.add(script, "location", location) script = Builtins.add(script, "notification", notification) @merged = Builtins.add(@merged, script) end Builtins.y2debug("Merged scripts: %1", @merged) nil end |
- (Object) AutoinstScripts
Constructor
111 112 113 114 115 |
# File '../../src/modules/AutoinstScripts.rb', line 111 def AutoinstScripts @merged = mergeScripts if !Mode.autoinst nil end |
- (void) deleteScript(scriptName)
This method returns an undefined value.
delete a script from a list
399 400 401 402 403 404 405 |
# File '../../src/modules/AutoinstScripts.rb', line 399 def deleteScript(scriptName) clean = Builtins.filter(@merged) do |s| Ops.get_string(s, "filename", "") != scriptName end @merged = deep_copy(clean) nil end |
- (Hash) Export
Dump the settings to a map, for autoinstallation use.
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 |
# File '../../src/modules/AutoinstScripts.rb', line 120 def Export @pre = [] @post = [] @chroot = [] @init = [] @postpart = [] Builtins.y2milestone("Merged %1", @merged) # split Builtins.foreach(@merged) do |s| if Ops.get_string(s, "type", "") == "pre-scripts" @pre = Builtins.add(@pre, s) elsif Ops.get_string(s, "type", "") == "post-scripts" @post = Builtins.add(@post, s) elsif Ops.get_string(s, "type", "") == "init-scripts" @init = Builtins.add(@init, s) elsif Ops.get_string(s, "type", "") == "chroot-scripts" @chroot = Builtins.add(@chroot, s) elsif Ops.get_string(s, "type", "") == "postpartitioning-scripts" @postpart = Builtins.add(@postpart, s) end end # clean expre = Builtins.maplist(@pre) do |p| { "filename" => Ops.get_string(p, "filename", ""), "interpreter" => Ops.get_string(p, "interpreter", ""), "source" => Ops.get_string(p, "source", ""), "notification" => Ops.get_string(p, "notification", ""), "location" => Ops.get_string(p, "location", ""), "feedback" => Ops.get_boolean(p, "feedback", false), "feedback_type" => Ops.get_string(p, "feedback_type", ""), "param-list" => p.fetch("param-list",[]), "debug" => Ops.get_boolean(p, "debug", true) } end expost = Builtins.maplist(@post) do |p| { "filename" => Ops.get_string(p, "filename", ""), "interpreter" => Ops.get_string(p, "interpreter", ""), "source" => Ops.get_string(p, "source", ""), "location" => Ops.get_string(p, "location", ""), "notification" => Ops.get_string(p, "notification", ""), "feedback" => Ops.get_boolean(p, "feedback", false), "feedback_type" => Ops.get_string(p, "feedback_type", ""), "debug" => Ops.get_boolean(p, "debug", true), "param-list" => p.fetch("param-list",[]), "network_needed" => Ops.get_boolean(p, "network_needed", false) } end exchroot = Builtins.maplist(@chroot) do |p| { "filename" => Ops.get_string(p, "filename", ""), "interpreter" => Ops.get_string(p, "interpreter", ""), "source" => Ops.get_string(p, "source", ""), "chrooted" => Ops.get_boolean(p, "chrooted", false), "notification" => Ops.get_string(p, "notification", ""), "location" => Ops.get_string(p, "location", ""), "feedback" => Ops.get_boolean(p, "feedback", false), "feedback_type" => Ops.get_string(p, "feedback_type", ""), "param-list" => p.fetch("param-list",[]), "debug" => Ops.get_boolean(p, "debug", true) } end exinit = Builtins.maplist(@init) do |p| { "filename" => Ops.get_string(p, "filename", ""), "source" => Ops.get_string(p, "source", ""), "location" => Ops.get_string(p, "location", ""), "debug" => Ops.get_boolean(p, "debug", true) } end expostpart = Builtins.maplist(@postpart) do |p| { "filename" => Ops.get_string(p, "filename", ""), "interpreter" => Ops.get_string(p, "interpreter", ""), "source" => Ops.get_string(p, "source", ""), "location" => Ops.get_string(p, "location", ""), "notification" => Ops.get_string(p, "notification", ""), "feedback" => Ops.get_boolean(p, "feedback", false), "feedback_type" => Ops.get_string(p, "feedback_type", ""), "param-list" => p.fetch("param-list",[]), "debug" => Ops.get_boolean(p, "debug", true) } end result = {} if Ops.greater_than(Builtins.size(expre), 0) Ops.set(result, "pre-scripts", expre) end if Ops.greater_than(Builtins.size(expost), 0) Ops.set(result, "post-scripts", expost) end if Ops.greater_than(Builtins.size(exchroot), 0) Ops.set(result, "chroot-scripts", exchroot) end if Ops.greater_than(Builtins.size(exinit), 0) Ops.set(result, "init-scripts", exinit) end if Ops.greater_than(Builtins.size(expostpart), 0) Ops.set(result, "postpartitioning-scripts", expostpart) end deep_copy(result) end |
- (Boolean) GetModified
Functions which returns if the settings were modified
61 62 63 |
# File '../../src/modules/AutoinstScripts.rb', line 61 def GetModified @modified end |
- (Object) Import(s)
Get all the configuration from a map. When called by autoinst_<module name> (preparing autoinstallation data) the map may be empty.
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File '../../src/modules/AutoinstScripts.rb', line 304 def Import(s) s = deep_copy(s) Builtins.y2debug("Calling AutoinstScripts::Import()") @pre = Ops.get_list(s, "pre-scripts", []) @init = Ops.get_list(s, "init-scripts", []) @post = Ops.get_list(s, "post-scripts", []) @chroot = Ops.get_list(s, "chroot-scripts", []) @postpart = Ops.get_list(s, "postpartitioning-scripts", []) @pre = Resolve_location(@pre) @init = Resolve_location(@init) @post = Resolve_location(@post) @chroot = Resolve_location(@chroot) @postpart = Resolve_location(@postpart) @merged = mergeScripts Builtins.y2debug("merged: %1", @merged) true end |
- (Object) interactiveScript(shell, debug, scriptPath, params, current_logdir, scriptName)
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 |
# File '../../src/modules/AutoinstScripts.rb', line 503 def interactiveScript(shell, debug, scriptPath, params, current_logdir, scriptName) data = {} = "" SCR.Execute(path(".target.remove"), "/tmp/ay_opipe") SCR.Execute(path(".target.remove"), "/tmp/ay_ipipe") SCR.Execute(path(".target.bash"), "mkfifo -m 660 /tmp/ay_opipe", {}) SCR.Execute(path(".target.bash"), "mkfifo -m 660 /tmp/ay_ipipe", {}) execute = Builtins.sformat( "%1 %2 %3 %4 2> %5/%6.log ", shell, debug, scriptPath, params, current_logdir, scriptName ) SCR.Execute( path(".target.bash_background"), Ops.add("OPIPE=/tmp/ay_opipe IPIPE=/tmp/ay_ipipe ", execute), {} ) run = true = false vbox = VBox() buffer = [] while SCR.Read(path(".target.lstat"), "/tmp/ay_opipe") != {} && run data = Convert.to_map( SCR.Execute(path(".target.bash_output"), "cat /tmp/ay_opipe", {}) ) buffer = Builtins.splitstring(Ops.get_string(data, "stdout", ""), "\n") while buffer != [] line = Ops.get(buffer, 0, "") buffer = Builtins.remove(buffer, 0) next if Builtins.size(line) == 0 Ops.set(data, "stdout", line) Builtins.y2milestone("working on line %1", line) if Builtins.substring(Ops.get_string(data, "stdout", ""), 0, 8) == "__EXIT__" if == "radiobutton" vbox = Builtins.add(vbox, PushButton(Id(:ok), Label.OKButton)) UI.OpenDialog(RadioButtonGroup(Id(:rb), vbox)) end if == true UI.ChangeWidget(Id(:ok), :Enabled, true) ret = UI.UserInput if == "radiobutton" val = UI.QueryWidget(Id(:rb), :CurrentButton) SCR.Execute( path(".target.bash"), Builtins.sformat( "echo \"%1\" > /tmp/ay_ipipe", AutoinstConfig.ShellEscape(Convert.to_string(val)) ), {} ) elsif == "entry" val = UI.QueryWidget(Id(:ay_entry), :Value) SCR.Execute( path(".target.bash"), Builtins.sformat( "echo \"%1\" > /tmp/ay_ipipe", AutoinstConfig.ShellEscape(Convert.to_string(val)) ), {} ) end = false end vbox = VBox() if == "" run = false else UI.CloseDialog end = "" elsif Builtins.substring(Ops.get_string(data, "stdout", ""), 0, 12) == "__PROGRESS__" params = splitParams(Ops.get_string(data, "stdout", "")) UI.OpenDialog( VBox( ProgressBar( Id(:pr), Ops.get(params, "label", ""), Builtins.tointeger(Ops.get(params, "max", "100")), 0 ) ) ) = "progressbar" elsif Builtins.substring(Ops.get_string(data, "stdout", ""), 0, 8) == "__TEXT__" params = splitParams(Ops.get_string(data, "stdout", "")) hspace = Builtins.tointeger(Ops.get(params, "width", "10")) vspace = Builtins.tointeger(Ops.get(params, "height", "20")) = Builtins.haskey(params, "okbutton") ? true : false vbox = VBox( HSpacing(hspace), HBox(VSpacing(vspace), RichText(Id(:mle), "")) ) if == true vbox = Builtins.add(vbox, PushButton(Id(:ok), Label.OKButton)) end UI.OpenDialog(vbox) UI.ChangeWidget(Id(:ok), :Enabled, false) if == true = "text" elsif Builtins.substring(Ops.get_string(data, "stdout", ""), 0, 9) == "__ENTRY__" params = splitParams(Ops.get_string(data, "stdout", "")) if Builtins.haskey(params, "description") vbox = Builtins.add(vbox, HSpacing(40)) vbox = Builtins.add( vbox, RichText(Ops.get(params, "description", "")) ) end vbox = Builtins.add( vbox, TextEntry( Id(:ay_entry), Ops.get(params, "label", ""), Ops.get(params, "default", "") ) ) vbox = Builtins.add(vbox, PushButton(Id(:ok), Label.OKButton)) UI.OpenDialog(vbox) = "entry" = true elsif Builtins.substring(Ops.get_string(data, "stdout", ""), 0, 15) == "__RADIOBUTTON__" params = splitParams(Ops.get_string(data, "stdout", "")) if Builtins.haskey(params, "description") vbox = Builtins.add(vbox, HSpacing(60)) vbox = Builtins.add( vbox, RichText(Ops.get(params, "description", "")) ) end = "radiobutton" = true else if == "progressbar" UI.ChangeWidget( Id(:pr), :Value, Builtins.tointeger(Ops.get_string(data, "stdout", "0")) ) elsif == "text" UI.ChangeWidget( Id(:mle), :Value, Ops.add( Convert.to_string(UI.QueryWidget(Id(:mle), :Value)), Ops.get_string(data, "stdout", "") ) ) elsif == "radiobutton" if Builtins.substring(Ops.get_string(data, "stdout", ""), 0, 10) == "__BUTTON__" params = splitParams(Ops.get_string(data, "stdout", "")) vbox = Builtins.add( vbox, Left( RadioButton( Id(Ops.get(params, "val", "")), Ops.get(params, "label", "") ) ) ) else Builtins.y2milestone( "*urgs* received '%1' instead of '__BUTTON__' during RADIOBUTTON creation", Ops.get_string(data, "stdout", "") ) end end end end end SCR.Execute(path(".target.remove"), "/tmp/ay_opipe") SCR.Execute(path(".target.remove"), "/tmp/ay_ipipe") nil end |
- (Object) main
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 |
# File '../../src/modules/AutoinstScripts.rb', line 13 def main Yast.import "UI" textdomain "autoinst" Yast.import "Mode" Yast.import "AutoinstConfig" Yast.import "Summary" Yast.import "URL" Yast.import "Popup" Yast.import "Label" Yast.import "Report" Yast.include self, "autoinstall/io.rb" # Pre scripts @pre = [] # Post scripts @post = [] # Chroot scripts @chroot = [] # Init scripts @init = [] # postpart scripts @postpart = [] # Merged scripts @merged = [] # default value of settings modified @modified = false AutoinstScripts() end |
- (Object) mergeScripts
merge all types of scripts into one single list
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 |
# File '../../src/modules/AutoinstScripts.rb', line 69 def mergeScripts result = Builtins.maplist(@pre) do |p| p = Builtins.add(p, "type", "pre-scripts") deep_copy(p) end result = Convert.convert( Builtins.union(result, Builtins.maplist(@post) do |p| p = Builtins.add(p, "type", "post-scripts") deep_copy(p) end), :from => "list", :to => "list <map>" ) result = Convert.convert( Builtins.union(result, Builtins.maplist(@chroot) do |p| p = Builtins.add(p, "type", "chroot-scripts") deep_copy(p) end), :from => "list", :to => "list <map>" ) result = Convert.convert( Builtins.union(result, Builtins.maplist(@init) do |p| p = Builtins.add(p, "type", "init-scripts") deep_copy(p) end), :from => "list", :to => "list <map>" ) result = Convert.convert( Builtins.union(result, Builtins.maplist(@postpart) do |p| p = Builtins.add(p, "type", "postpartitioning-scripts") deep_copy(p) end), :from => "list", :to => "list <map>" ) deep_copy(result) end |
- (Object) Resolve_location(d)
293 294 295 296 297 |
# File '../../src/modules/AutoinstScripts.rb', line 293 def Resolve_location(d) d = deep_copy(d) d = Builtins.maplist(d) { |script| Resolve_relurl(Resolve_ws(script)) } deep_copy(d) end |
- (Object) Resolve_relurl(script)
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 |
# File '../../src/modules/AutoinstScripts.rb', line 243 def Resolve_relurl(script) script = deep_copy(script) if Builtins.issubstring( Ops.get_string(script, "location", ""), "relurl://" ) l = Ops.get_string(script, "location", "") l = Builtins.substring(l, 9) newloc = "" if AutoinstConfig.scheme == "relurl" Builtins.y2milestone("autoyast profile was relurl too") newloc = Convert.to_string( SCR.Read(path(".etc.install_inf.ayrelurl")) ) tok = URL.Parse(newloc) Builtins.y2milestone("tok = %1", tok) newloc = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add(Ops.get_string(tok, "scheme", ""), "://"), Ops.get_string(tok, "host", "") ), "/" ), dirname(Ops.get_string(tok, "path", "")) ), l ) else newloc = Ops.add( Ops.add( Ops.add( Ops.add( Ops.add(AutoinstConfig.scheme, "://"), AutoinstConfig.host ), "/" ), AutoinstConfig.directory ), l ) end Ops.set(script, "location", newloc) Builtins.y2milestone("changed relurl to %1 for script", newloc) end deep_copy(script) end |
- (Object) Resolve_ws(script)
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File '../../src/modules/AutoinstScripts.rb', line 227 def Resolve_ws(script) script = deep_copy(script) if !Builtins.isempty(Ops.get_string(script, "location", "")) l = CutWhitespace(Ops.get_string(script, "location", "")) if l != Ops.get_string(script, "location", "") Builtins.y2milestone( "changed script location to \"%1\" from \"%2\"", l, Ops.get_string(script, "location", "") ) Ops.set(script, "location", l) end end deep_copy(script) end |
- (Object) SetModified
Function sets internal variable, which indicates, that any settings were modified, to “true”
53 54 55 56 57 |
# File '../../src/modules/AutoinstScripts.rb', line 53 def SetModified @modified = true nil end |
- (Object) splitParams(s)
bidirectional feedback during script execution Experimental
492 493 494 495 496 497 498 499 500 501 |
# File '../../src/modules/AutoinstScripts.rb', line 492 def splitParams(s) l = Builtins.splitstring(s, "|") ret = {} l = Builtins.remove(l, 0) Builtins.foreach(l) do |element| p = Builtins.splitstring(element, "=") Ops.set(ret, Ops.get(p, 0, ""), Ops.get(p, 1, "")) end deep_copy(ret) end |
- (String) Summary
Return Summary
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 |
# File '../../src/modules/AutoinstScripts.rb', line 326 def Summary summary = "" summary = Summary.AddHeader(summary, _("Preinstallation Scripts")) if Ops.greater_than(Builtins.size(@pre), 0) summary = Summary.OpenList(summary) Builtins.foreach(@pre) do |script| summary = Summary.AddListItem( summary, Ops.get_string(script, "filename", "") ) end summary = Summary.CloseList(summary) else summary = Summary.AddLine(summary, Summary.NotConfigured) end summary = Summary.AddHeader(summary, _("Postinstallation Scripts")) if Ops.greater_than(Builtins.size(@post), 0) summary = Summary.OpenList(summary) Builtins.foreach(@post) do |script| summary = Summary.AddListItem( summary, Ops.get_string(script, "filename", "") ) end summary = Summary.CloseList(summary) else summary = Summary.AddLine(summary, Summary.NotConfigured) end summary = Summary.AddHeader(summary, _("Chroot Scripts")) if Ops.greater_than(Builtins.size(@chroot), 0) summary = Summary.OpenList(summary) Builtins.foreach(@chroot) do |script| summary = Summary.AddListItem( summary, Ops.get_string(script, "filename", "") ) end summary = Summary.CloseList(summary) else summary = Summary.AddLine(summary, Summary.NotConfigured) end summary = Summary.AddHeader(summary, _("Init Scripts")) if Ops.greater_than(Builtins.size(@init), 0) summary = Summary.OpenList(summary) Builtins.foreach(@init) do |script| summary = Summary.AddListItem( summary, Ops.get_string(script, "filename", "") ) end summary = Summary.CloseList(summary) else summary = Summary.AddLine(summary, Summary.NotConfigured) end summary = Summary.AddHeader(summary, _("Postpartitioning Scripts")) if Ops.greater_than(Builtins.size(@postpart), 0) summary = Summary.OpenList(summary) Builtins.foreach(@postpart) do |script| summary = Summary.AddListItem( summary, Ops.get_string(script, "filename", "") ) end summary = Summary.CloseList(summary) else summary = Summary.AddLine(summary, Summary.NotConfigured) end summary end |
- (String) typeString(type)
return type of script as formatted string
473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
# File '../../src/modules/AutoinstScripts.rb', line 473 def typeString(type) if type == "pre-scripts" return _("Pre") elsif type == "post-scripts" return _("Post") elsif type == "init-scripts" return _("Init") elsif type == "chroot-scripts" return _("Chroot") elsif type == "postpartitioning-scripts" return _("Postpartitioning") end _("Unknown") end |
- (Boolean) Write(type, special)
Execute pre scripts
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
# File '../../src/modules/AutoinstScripts.rb', line 687 def Write(type, special) return true if !Mode.autoinst && !Mode.autoupgrade scripts = [] if type == "pre-scripts" scripts = deep_copy(@pre) elsif type == "init-scripts" scripts = deep_copy(@init) elsif type == "chroot-scripts" && !special scripts = Builtins.filter(@chroot) do |s| !Ops.get_boolean(s, "chrooted", false) end elsif type == "chroot-scripts" && special scripts = Builtins.filter(@chroot) do |s| Ops.get_boolean(s, "chrooted", false) end elsif type == "post-scripts" && !special scripts = Builtins.filter(@post) do |s| !Ops.get_boolean(s, "network_needed", false) end elsif type == "post-scripts" && special scripts = Builtins.filter(@post) do |s| Ops.get_boolean(s, "network_needed", false) end elsif type == "postpartitioning-scripts" scripts = deep_copy(@postpart) else Builtins.y2error("Unsupported script type") return false end tmpdirString = "" current_logdir = "" if type == "pre-scripts" || type == "postpartitioning-scripts" tmpdirString = Builtins.sformat("%1/%2", AutoinstConfig.tmpDir, type) SCR.Execute(path(".target.mkdir"), tmpdirString) current_logdir = Builtins.sformat("%1/logs", tmpdirString) SCR.Execute(path(".target.mkdir"), current_logdir) elsif type == "chroot-scripts" if !special tmpdirString = Builtins.sformat( "%1%2", AutoinstConfig.destdir, AutoinstConfig.scripts_dir ) SCR.Execute(path(".target.mkdir"), tmpdirString) current_logdir = Builtins.sformat( "%1%2", AutoinstConfig.destdir, AutoinstConfig.logs_dir ) SCR.Execute(path(".target.mkdir"), current_logdir) else tmpdirString = Builtins.sformat("%1", AutoinstConfig.scripts_dir) SCR.Execute(path(".target.mkdir"), tmpdirString) current_logdir = Builtins.sformat("%1", AutoinstConfig.logs_dir) SCR.Execute(path(".target.mkdir"), current_logdir) end else current_logdir = AutoinstConfig.logs_dir end Builtins.foreach(scripts) do |s| scriptInterpreter = Ops.get_string(s, "interpreter", "shell") params = s.fetch("param-list",[]).join(" ") scriptName = Ops.get_string(s, "filename", "") if scriptName == "" t = URL.Parse(Ops.get_string(s, "location", "")) scriptName = basename(Ops.get_string(t, "path", "")) scriptName = type if scriptName == "" end scriptPath = "" if type == "pre-scripts" || type == "postpartitioning-scripts" # y2milestone("doing /sbin/udevcontrol stop_exec_queue now to prevent trouble if one is doing partitioning in a pre-script"); # SCR::Execute( .target.bash, "/sbin/udevcontrol stop_exec_queue" ); scriptPath = Builtins.sformat( "%1/%2/%3", AutoinstConfig.tmpDir, type, scriptName ) Builtins.y2milestone("Writing %1 script into %2", type, scriptPath) if Ops.get_string(s, "location", "") != "" Builtins.y2debug( "getting script: %1", Ops.get_string(s, "location", "") ) if !GetURL(Ops.get_string(s, "location", ""), scriptPath) Builtins.y2error( "script %1 could not be retrieved", Ops.get_string(s, "location", "") ) end else SCR.Write( path(".target.string"), scriptPath, Ops.get_string(s, "source", "echo Empty script!") ) end elsif type == "init-scripts" scriptPath = Builtins.sformat( "%1/%2", AutoinstConfig.initscripts_dir, scriptName ) Builtins.y2milestone("Writing init script into %1", scriptPath) if Ops.get_string(s, "location", "") != "" Builtins.y2debug( "getting script: %1", Ops.get_string(s, "location", "") ) if !GetURL(Ops.get_string(s, "location", ""), scriptPath) Builtins.y2error( "script %1 could not be retrieved", Ops.get_string(s, "location", "") ) end else SCR.Write( path(".target.string"), scriptPath, Ops.get_string(s, "source", "echo Empty script!") ) end # moved to 1st stage because of systemd #Service::Enable("autoyast"); elsif type == "chroot-scripts" #scriptPath = sformat("%1%2/%3", (special) ? "" : AutoinstConfig::destdir, AutoinstConfig::scripts_dir, scriptName); toks = URL.Parse(Ops.get_string(s, "location", "")) # special == true ---> The script has to be installed into /mnt # because it will be called in a chroot environment. # (bnc#889931) # Add /mnt only if the script is getting via GetURL. # In the other case SCR will do it via target setting. # (bnc#897212) # # FIXME: Find out why "nfs" has a special behavior. # Take another name for "s" if (special && s["location"] && !s["location"].empty?) || toks["scheme"] == "nfs" scriptPath = Builtins.sformat( "%1%2/%3", AutoinstConfig.destdir, AutoinstConfig.scripts_dir, scriptName ) else scriptPath = Builtins.sformat( "%1/%2", AutoinstConfig.scripts_dir, scriptName ) end Builtins.y2milestone("Writing chroot script into %1", scriptPath) if Ops.get_string(s, "location", "") != "" if !GetURL(Ops.get_string(s, "location", ""), scriptPath) Builtins.y2error( "script %1 could not be retrieved", Ops.get_string(s, "location", "") ) end else SCR.Write( path(".target.string"), scriptPath, Ops.get_string(s, "source", "echo Empty script!") ) end # FIXME: That's duplicate code if (special && s["location"] && !s["location"].empty?) || toks["scheme"] == "nfs" scriptPath = scriptPath[AutoinstConfig.destdir.length..-1] # cut off the e.g. /mnt for later execution end else # disable all sources and finish target - no clue what this is good for. # triggers an error with post-script network_needed=true # Pkg::SourceFinishAll(); # Pkg::TargetFinish(); scriptPath = Builtins.sformat( "%1/%2", AutoinstConfig.scripts_dir, scriptName ) Builtins.y2milestone("Writing script into %1", scriptPath) if Ops.get_string(s, "location", "") != "" if !GetURL(Ops.get_string(s, "location", ""), scriptPath) Builtins.y2error( "script %1 could not be retrieved", Ops.get_string(s, "location", "") ) end else SCR.Write( path(".target.string"), scriptPath, Ops.get_string(s, "source", "echo Empty script!") ) end end if type != "init-scripts" # string message = sformat(_("Executing user supplied script: %1"), scriptName); executionString = "" showFeedback = Ops.get_boolean(s, "feedback", false) if Ops.get_string(s, "notification", "") != "" Popup.ShowFeedback("", Ops.get_string(s, "notification", "")) end if scriptInterpreter == "shell" debug = Ops.get_boolean(s, "debug", true) ? "-x" : "" if SCR.Read(path(".target.size"), Ops.add(scriptPath, "-run")) == -1 || Ops.get_boolean(s, "rerun", false) == true if Ops.get_boolean(s, "interactive", false) == true interactiveScript( "/bin/sh", debug, scriptPath, params, current_logdir, scriptName ) else executionString = Builtins.sformat( "/bin/sh %1 %2 %3 &> %4/%5.log ", debug, scriptPath, params, current_logdir, scriptName ) Builtins.y2milestone( "Script Execution command: %1", executionString ) SCR.Execute(path(".target.bash"), executionString) SCR.Execute( path(".target.bash"), "/bin/touch $FILE", { "FILE" => Ops.add(scriptPath, "-run") } ) end end elsif scriptInterpreter == "perl" debug = Ops.get_boolean(s, "debug", true) ? "-w" : "" if SCR.Read(path(".target.size"), Ops.add(scriptPath, "-run")) == -1 || Ops.get_boolean(s, "rerun", false) == true if Ops.get_boolean(s, "interactive", false) == true interactiveScript( "/usr/bin/perl", debug, scriptPath, params, current_logdir, scriptName ) else executionString = Builtins.sformat( "/usr/bin/perl %1 %2 %3 &> %4/%5.log ", debug, scriptPath, params, current_logdir, scriptName ) Builtins.y2milestone( "Script Execution command: %1", executionString ) SCR.Execute(path(".target.bash"), executionString) SCR.Execute( path(".target.bash"), "/bin/touch $FILE", { "FILE" => Ops.add(scriptPath, "-run") } ) end end elsif scriptInterpreter == "python" if SCR.Read(path(".target.size"), Ops.add(scriptPath, "-run")) == -1 || Ops.get_boolean(s, "rerun", false) == true if Ops.get_boolean(s, "interactive", false) == true interactiveScript( "/usr/bin/python", "", scriptPath, params, current_logdir, scriptName ) else executionString = Builtins.sformat( "/usr/bin/python %1 %2 &> %3/%4.log ", scriptPath, params, current_logdir, scriptName ) Builtins.y2milestone( "Script Execution command: %1", executionString ) SCR.Execute(path(".target.bash"), executionString) SCR.Execute( path(".target.bash"), "/bin/touch $FILE", { "FILE" => Ops.add(scriptPath, "-run") } ) end end else Builtins.y2error("Unknown interpreter: %1", scriptInterpreter) end feedback = "" Popup.ClearFeedback if Ops.get_string(s, "notification", "") != "" if executionString != "" if showFeedback feedback = Convert.to_string( SCR.Read( path(".target.string"), Ops.add( Ops.add(Ops.add(current_logdir, "/"), scriptName), ".log" ) ) ) end if Ops.greater_than(Builtins.size(feedback), 0) if Ops.get_string(s, "feedback_type", "") == "" Popup.LongText("", RichText(Opt(:plainText), feedback), 50, 20) elsif Ops.get_string(s, "feedback_type", "") == "message" Report.Message(feedback) elsif Ops.get_string(s, "feedback_type", "") == "warning" Report.Warning(feedback) elsif Ops.get_string(s, "feedback_type", "") == "error" Report.Error(feedback) end end end end end true end |