/* inst_myclient.ycp * Purpose: * General purpose module to perform custom commands * at the end of an AutoYaST installation. * Variables/other to change before using : * number_of_steps (mandatory) * The individual steps (mandatory) * log_filename (optional) * helptext (optional) * sleep_after_completion (optional) * Dialog title in Wizard::SetContents (optional) * * Authors: Andreas Taschner ataschner@novell.com * Version: 0.18 * Date : 26 Aug 2009 */ { import "CommandLine"; import "Directory"; import "Installation"; import "Label"; import "SCR"; import "Wizard"; textdomain "installation"; /********************************************************* * * * Begin parameters to change - block 1 * * * *********************************************************/ // Help text // Note that in the ncurses interface it will be be displayed in // the left pane of the dialog while the module is running. // In the qt interface the Help button must be pressed to show it. string helptext = ("

MyCompany Customization module is now downloading files to the machine and performing additional configuration. Depending on how the wind is blowing, temperature, CPU and the amount of memory, this process can take some time.

"); // Define the number of steps/commands to be performed below // Needed for correct behavior of the progress bar integer number_of_steps = 3 ; // Name of the log - located in /var/log/YaST2/ string logfilename = "/y2log.mycustomization" ; // The time to sleep after all steps are done, to allow // for user to be able to read what happened. // Defined in miliseconds integer sleep_after_completion = 5000 ; /********************************************************* * * * End parameters to change - block 1 * * * *********************************************************/ integer current_step = 0; string log_destination = ">> " + Directory::logdir + logfilename ; string log_destination_verbose = "|tee -a " + Directory::logdir + "/y2log.mycustomization"; ////////////////////////////////////////////////////////////////// // Functions // ////////////////////////////////////////////////////////////////// // Display a step in the LogView widget and increment the progress bar. // Uses global variable 'current_step'. // @param step_descr description of the step. define void logStep( string step_descr ) ``{ current_step = current_step + 1; UI::ChangeWidget( `id(`progress), `Value, current_step ); UI::ChangeWidget( `id(`log), `LastLine, step_descr + "\n" ); }; // Run a step on the target and log its output to the globally specified // 'log_destination'. // @param step command to execute in this step define void runStep( string step ) ``{ string command = sformat( "HOME=%1 %2 %3 2>&1", Directory::tmpdir, step, log_destination ); y2milestone( "Executing '%1'", command ); SCR::Execute( .target.bash, command ); }; define void runStepVerbose( string step ) ``{ // Write command being executed to log and screen string command2 = sformat( "HOME=%1 %2 %3 %4", Directory::tmpdir, "echo -e \"\\n**** Executing : \"", step, log_destination_verbose ); SCR::Execute( .target.bash, command2 ); UI::ChangeWidget( `id(`log), `LastLine, step + "\n" ); string command = sformat( "HOME=%1 %2 2>&1", Directory::tmpdir, step ); y2milestone( "Executing '%1'", command ); // Execute the actual command SCR::Execute(.background.run_output, command ); list script_out = []; symbol ret = nil; // Loop through the output from the command and // display it on screen + log while((boolean)SCR::Read(.background.output_open) || ((integer)SCR::Read(.background.newlines) > 0)) { script_out = (list)SCR::Read(.background.newout); foreach(string line, script_out, { UI::ChangeWidget( `id(`log), `LastLine, line + "\n" ); string command3 = sformat( "HOME=%1 %2 %3 %4", Directory::tmpdir, "echo ", line, log_destination ); SCR::Execute( .target.bash, command3 ); } ); while ((integer)SCR::Read(.background.newlines) == 0 && (boolean)SCR::Read(.background.output_open)) { sleep(200); // small wait } } }; ////////////////////////////////////////////////////////////////// // Main Dialog // ////////////////////////////////////////////////////////////////// // Create the dialog box term contents = `VBox( `LogView(`id(`log), "", 10, 0 ), // Progress bar that displays overall progress in this dialog `ProgressBar(`id(`progress), ("Progress"), number_of_steps, 0 ) ); Wizard::SetContents( // Dialog title for our dialog ("Performing MyCompany specific customization"), contents, helptext, false, false); Wizard::DisableAbortButton(); /****************************************************************** * Enter the individual steps with comments and commands to * * display and execute. Create as many steps as desired, * * but remember to set number_of_steps accordingly above. * * logStep writes in the dialog what is going on and advances * * the progress bar. * * Invoke either runStep or runStepVerbose to execute the command * * Use runStep for normal verbosity level to the screen or * * runStepVerbose to display the actual command and its output. * * * ******************************************************************/ // Step logStep( "Downloading customization files archive..." ); runStepVerbose( "wget -O /tmp/custom-files.tgz http://smt10.nts.com/repo/tools/custom-files.tgz" ); // logStep( "Unpacking archive..." ); // runStep( "tar -C / -zxvf /tmp/custom-files.tgz" ); // Step // logStep( "Downloading customization script." ); // runStepVerbose( "wget -O /tmp/switch-screen-script.sh http://smt10.nts.com/repo/tools/switch-screen-script.sh" ); // Step logStep( "Unpacking archive..." ); runStepVerbose( "tar -C / -zxvf /tmp/custom-files.tgz" ); // Step // logStep( "Will now switch to another terminal to show command output." ); // runStep( "sleep 15" ); // Step // logStep( "Executing script..." ); // runStep( "bash /tmp/switch-screen-script.sh" ); // Step logStep( "Cleaning up." ); runStepVerbose( "rm -v /tmp/custom*" ); /****************************************************************** * * * No need to change anything below this line * * * ******************************************************************/ // The final LogView line to be displayed after our steps are completed. UI::ChangeWidget( `id(`log), `LastLine, "\n" + "Done." + "\n" ); // Sleep 5 secs to allow time for the user to see what has happened sleep( sleep_after_completion ); return `next; }