1 #*********************************************************************
2 #
3 # GOto::Utils package -- Log parsing aid.
4 #
5 # (c) 2008 by Cajus Pollmeier <pollmeier@gonicus.de>
6 #
7 #*********************************************************************
8 package GOto::Utils;
10 use Exporter;
11 @ISA = qw(Exporter);
12 @EXPORT = qw(process_input);
14 use strict;
15 use warnings;
16 use POSIX;
17 use Locale::gettext;
18 use MIME::Base64;
20 BEGIN {}
22 END {}
24 ### Start ######################################################################
26 # I18N setup
27 setlocale(LC_MESSAGES, "");
28 textdomain("fai-progress");
30 # "Global" variables
31 my $percent= 0;
32 my $pkg_step= 0.0;
33 my $scr_step= 0.0;
34 my $action= gettext("Initializing FAI");
36 #=== FUNCTION ================================================================
37 # NAME: process_input
38 # PARAMETERS: received line of input
39 # RETURNS: true if stream wants us to finish
40 # DESCRIPTION: parses information from the lines and sets the progress
41 # respectively
42 #===============================================================================
43 sub process_input($)
44 {
45 my %result;
46 my $line= shift;
47 chomp($line);
49 # Assume no errors
50 $result{'status'}= 0;
52 # Do regex
53 if ( $line =~ m/^fai-progress: hangup$/ ) {
54 $result{'status'}= -1;
55 } elsif ( $line =~ /^Calling task_confdir$/ ) {
56 %result = ( 'status' => 0, 'percent' => 0, 'task' => "task_confdir",
57 'action' => gettext("Retrieving initial client configuration"));
58 } elsif ( $line =~ /^Calling task_setup$/ ) {
59 %result = ( 'status' => 0, 'percent' => 1, 'task' => "task_setup",
60 'action' => gettext("Gathering client information"));
61 } elsif ( $line =~ /^Calling task_defclass$/ ) {
62 %result = ( 'status' => 0, 'percent' => 1, 'task' => "task_defclass",
63 'action' => gettext("Defining installation classes"));
64 } elsif ( $line =~ /^Calling task_defvar$/ ) {
65 %result = ( 'status' => 0, 'percent' => 1, 'task' => "task_defvar",
66 'action' => gettext("Defining installation variables"));
67 } elsif ( $line =~ /^Calling task_install$/ ) {
68 %result = ( 'status' => 0, 'percent' => 2, 'task' => "task_defvar",
69 'action' => gettext("Starting installation"));
70 } elsif ( $line =~ /^Calling task_partition$/ ) {
71 %result = ( 'status' => 0, 'percent' => 2, 'task' => "task_partition",
72 'action' => gettext("Inspecting harddisks"));
73 } elsif ( $line =~ /^Creating partition table$/ ) {
74 %result = ( 'status' => 0, 'percent' => 2, 'task' => "task_partition",
75 'action' => gettext("Partitioning harddisk"));
76 } elsif ( $line =~ /^Creating file systems$/ ) {
77 %result = ( 'status' => 0, 'percent' => 3, 'task' => "task_partition",
78 'action' => gettext("Creating filesystems"));
79 } elsif ( $line =~ /^Calling task_mountdisks$/ ) {
80 %result = ( 'status' => 0, 'percent' => 3, 'task' => "task_mountdisks",
81 'action' => gettext("Mounting filesystems"));
83 # Original FAI counting, no possibility to do anything here...
84 } elsif ( $line =~ /^Calling task_extrbase$/ ) {
85 %result = ( 'status' => 0, 'percent' => 3, 'task' => "task_extrbase",
86 'action' => gettext("Bootstrapping base system"));
88 # Using debootstrap for boostrapping is a bit more wise in at this point. Start at 3% and grow to approx 15%.
89 } elsif ( $line =~ /^HOOK extrbase/ ) {
90 %result = ( 'status' => 0, 'percent' => 3, 'task' => "task_extrbase",
91 'action' => gettext("Bootstrapping base system"));
92 $percent= 3;
93 } elsif ( $line =~ /^I: Retrieving (.+)$/ ) {
94 $percent= ($percent > 15) ? 15 : $percent + 0.025;
95 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_extrbase",
96 'action' => gettext("Bootstrapping base system").": ".sprintf(gettext("Retrieving %s..."), $1));
97 } elsif ( $line =~ /^I: Extracting (.+)$/ ) {
98 $percent= ($percent > 15) ? 15 : $percent + 0.025;
99 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_extrbase",
100 'action' => gettext("Bootstrapping base system").": ".sprintf(gettext("Extracting %s..."), $1));
101 } elsif ( $line =~ /^I: Validating (.+)$/ ) {
102 $percent= ($percent > 15) ? 15 : $percent + 0.025;
103 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_extrbase",
104 'action' => gettext("Bootstrapping base system").": ".sprintf(gettext("Validating %s..."), $1));
105 } elsif ( $line =~ /^I: Unpacking (.+)$/ ) {
106 $percent= ($percent > 15) ? 15 : $percent + 0.025;
107 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_extrbase",
108 'action' => gettext("Bootstrapping base system").": ".sprintf(gettext("Unpacking %s..."), $1));
109 } elsif ( $line =~ /^I: Configuring (.+)$/ ) {
110 $percent= ($percent > 15) ? 15 : $percent + 0.025;
111 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_extrbase",
112 'action' => gettext("Bootstrapping base system").": ".sprintf(gettext("Configuring %s..."), $1));
113 } elsif ( $line =~ /^Calling task_debconf$/ ) {
114 %result = ( 'status' => 0, 'percent' => 15, 'task' => "task_debconf",
115 'action' => gettext("Configuring base system"));
116 } elsif ( $line =~ /^Calling task_prepareapt$/ ) {
117 %result = ( 'status' => 0, 'percent' => 15, 'task' => "task_prepareapt",
118 'action' => gettext("Preparing network install"));
119 } elsif ( $line =~ /^Calling task_updatebase$/ ) {
120 %result = ( 'status' => 0, 'percent' => 15, 'task' => "task_updatebase",
121 'action' => gettext("Updating base system"));
122 } elsif ( $line =~ /^Calling task_instsoft$/ ) {
123 %result = ( 'status' => 0, 'percent' => 16, 'task' => "task_instsoft",
124 'action' => gettext("Gathering information for package lists"));
125 } elsif ( $line =~ /([0-9]+) packages upgraded, ([0-9]+) newly installed/ ) {
126 $pkg_step= 69.0 / ($1 + $2) / 3.0;
127 $percent= 16.0;
128 } elsif ( $line =~ /Get:[0-9]+ [^ ]+ [^ ]+ ([^ ]+)/ ) {
129 $percent+= $pkg_step;
130 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_instsoft",
131 'action' => gettext("Software installation").": ".sprintf(gettext("Retrieving %s..."), $1));
132 } elsif ( $line =~ /Unpacking ([^ ]+) .*from/ ) {
133 $percent+= $pkg_step;
134 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_instsoft",
135 'action' => gettext("Software installation").": ".sprintf(gettext("Extracting %s..."), $1));
136 } elsif ( $line =~ /Setting up ([^ ]+)/ ) {
137 $percent+= $pkg_step;
138 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_instsoft",
139 'action' => gettext("Software installation").": ".sprintf(gettext("Configuring %s..."), $1));
140 } elsif ( $line =~ /^Calling task_configure$/ ) {
141 %result = ( 'status' => 0, 'percent' => 80, 'task' => "task_configure",
142 'action' => gettext("Software installation").": ".gettext("Adapting system and package configuration"));
143 } elsif ( $line =~ /^Script count: ([0-9]+)$/ ) {
144 $percent= 85.0;
145 $scr_step= 15.0 / $1;
146 } elsif ( $line =~ /^Executing +([^ ]+): ([^\n ]+)$/ ) {
147 $percent+= $scr_step;
148 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_configure",
149 'action' => sprintf(gettext("Running script %s (%s)..."), $1, $2));
150 } elsif ( $line =~ /^Calling task_savelog$/ ) {
151 $percent= 100;
152 %result = ( 'status' => 0, 'percent' => floor($percent), 'task' => "task_savelog",
153 'action' => gettext("Installation finished"));
155 # Status evaluation
156 } elsif ( $line =~ /^TASKEND ([^ ]+) ([0-9]+)$/ ) {
157 if ($2 != 0){
158 %result = ( 'status' => $2, 'task' => "$1");
159 }
161 # Common errors
162 } elsif ( $line =~ /^goto-error-([^:]+)$/ ) {
163 %result = ( 'status' => 5, 'task' => "error-$1");
164 } elsif ( $line =~ /^goto-error-([^:]+):(.*)$/ ) {
165 %result = ( 'status' => 6, 'task' => "error-$1", 'action' => "$2");
166 } elsif ( $line =~ /^ldap2fai-error:(.*)$/ ) {
167 my $message= decode_base64("$1");
168 $message =~ tr/\n/\n .\n /;
169 %result = ( 'status' => 7, 'task' => "ldap2fai-error", 'action' => $message);
171 # GOto built ins
172 } elsif ( $line =~ /^goto-hardware-detection start$/ ) {
173 %result = ( 'status' => 0, 'task' => "goto-hardware-detection-start", 'action' => gettext("Detecting hardware"));
174 } elsif ( $line =~ /^goto-hardware-detection stop$/ ) {
175 %result = ( 'status' => 0, 'task' => "goto-hardware-detection-stop", 'action' => gettext("Inventarizing hardware information"));
176 } elsif ( $line =~ m/^goto-activation start$/ ) {
177 %result = ( 'status' => 0, 'task' => "goto-activation-start", 'action' => gettext("Waiting for the system to be activated"));
178 } elsif ( $line =~ m/^goto-activation stop$/ ) {
179 %result = ( 'status' => 0, 'task' => "goto-activation-stop", 'action' => gettext("System activated - retrieving configuration"));
180 }
182 return \%result;
183 }
185 1;