root/morphix/trunk/morph-scripts/morphix-iso.pl

Revision 2, 5.6 kB (checked in by nextime, 2 years ago)

Initial import, branching from morphix svn

Line 
1 #!/usr/bin/perl -w
2 # Small script for Generating a Custom ISO for Morphix
3 # © Laurens Buhler 2003 under the terms of the GPL
4
5 use strict;
6
7 print ("\t\tWelcome to the Morphix CD ISO creator\n\n");
8
9 # Creating a while loop to make the program stop when requested
10 our $exit;
11 our $continue;
12 our @mainmod;
13 our @minimod;
14 our @chosenmain;
15 our @chosenmini;
16
17 while (!$exit){
18
19 # Checking for the necessary programs (mkisofs, wget, tar)
20 my $wget = qx|which wget 2>&1|;
21 my $mkisofs = qx|which mkisofs 2>&1|;
22 my $tar = qx|which tar 2>&1|;
23        
24 if ($wget =~/no wget in/){
25         print ("wget was not found, exiting...\n");
26         $exit++; last if $exit;
27 } elsif ($mkisofs =~/no mkisofs in/){
28         print ("mkisofs was not found, exiting...\n");
29         $exit++; last if $exit;
30 } elsif ($tar =~/no tar in/){
31         print ("tar was not found, exiting...\n");
32         $exit++; last if $exit;
33 } else {
34         print ("\tNecessary programs where found, fetching the modules list...\n");
35 }
36
37 my $startdir = qx|pwd|;
38 my $workdir = "./.tmp.6978";
39
40 # Creating temp dir for generating the ISO
41 system ("mkdir $workdir");
42 system ("wget ftp://dl.xs4all.nl/pub/mirror/drupal/Morphix/modules.list");
43
44 # Sorting the available modules
45 my @modules = grep {!/^\s*$/} qx|cat modules.list|;
46 foreach my $line(@modules){
47         if ($line =~/mainmod/){
48                 push(@mainmod,$line);
49         } elsif ($line =~/minimod/){
50                 push(@minimod,$line);
51         }
52 }
53 print ("\tWhich Main Module\(s\) would you like added?\n\n");
54
55 # Printing the available modules
56 my $number = "1";
57 foreach my $line(@mainmod){
58         my @x = split/\//,$line;
59         my @name = split/\t/,$x[-1];
60         print ("[$number]\t $name[0]\n");
61         $number++;
62 }
63
64 # User choses the modules here
65 print ("\nPlease make your choice: ");
66 chomp (my $mainchoice = <stdin>);
67 my $maxnum = @mainmod;
68 while ($mainchoice =~/\D/ || $mainchoice eq "" || $mainchoice > $maxnum || $mainchoice < 1 || $mainchoice =~/\./){
69                 print ("Invalid number, please choose again: ");
70                 chomp ($mainchoice = <stdin>);
71 }
72 push (@chosenmain,$mainchoice);
73
74 my $stop_add;
75 $maxnum = @minimod;
76 while (!$stop_add){
77         print ("Would you like to add another module? [y/N]: ");
78         chomp ($continue = <stdin>);
79         $continue = lc($continue);
80         if ($continue =~/n/ || $continue eq ""){
81                 $stop_add = "1";
82         } elsif ($continue =~/y/){
83                 print ("Please make your choice: ");
84                 chomp (my $mainchoice = <stdin>);
85                 while ($mainchoice =~/\D/ || $mainchoice eq "" || $mainchoice > $maxnum || $mainchoice < 1 || $mainchoice =~/\./){
86                         print ("Invalid number, please choose again: ");
87                         chomp ($mainchoice = <stdin>);
88                 }
89                 push (@chosenmain,$mainchoice);
90         }
91 }
92
93 undef $stop_add;
94 while (!$stop_add){
95         print ("Would you like to add a minimodule? [y/N]: ");
96         chomp ($continue = <stdin>);
97         $continue = lc($continue);
98         if ($continue =~/n/ || $continue eq ""){
99                 $stop_add = "1";
100         } elsif ($continue =~/y/){
101                 my $number = "1";
102                 print ("\n");
103                 foreach my $line(@minimod){
104                         my @x = split/\//,$line;
105                         my @name = split/\t/,$x[-1];
106                         print ("[$number]\t $name[0]\n");
107                         $number++;
108                 }
109                 print ("Please make your choice: ");
110                 chomp (my $minichoice = <stdin>);
111                 while ($minichoice =~/\D/ || $minichoice eq "" || $minichoice > $maxnum || $minichoice < 1 || $minichoice =~/\./){
112                         print ("Invalid number, please choose again: ");
113                         chomp ($minichoice = <stdin>);
114                 }
115                 push (@chosenmini,$minichoice);
116         }
117 }
118
119 # Printing the list of chosen modules
120 print ("\nThe following module\(s\) will be added:\n");
121 foreach my $line(@chosenmain){
122         $line--;
123         my @x = split/\//,$mainmod[$line];
124         my @name = split/\t/,$x[-1];
125         print ("\t$name[0]\n");
126 }
127 if (@chosenmini){
128         foreach my $line(@chosenmini){
129                 $line--;
130                 my @x = split/\//,$minimod[$line];
131                 my @name = split/\t/,$x[-1];
132                 print ("\t$name[0]\n");
133         }
134 }
135
136 # Here we calculate the total size to be used for the ISO
137 my @basesize = split/\t/,$modules[-1];
138 chomp (my $basesize = $basesize[-1]);
139 my $isototal = $basesize;
140 foreach my $line(@chosenmain){
141         $line--;
142         my @x = split/\//,$mainmod[$line];
143         my @name = split/\t/,$x[-1];
144         chomp $name[1];
145         $isototal = sprintf ("%.f",($isototal + $name[1]));
146 }
147 if (@chosenmini){
148         foreach my $line(@chosenmini){
149                 my @x = split/\//,$minimod[$line];
150                 my @name = split/\t/,$x[-1];
151                 chomp $name[1];
152                 $isototal = sprintf ("%.f",($isototal + $name[1]));
153         }
154 }
155 $isototal = sprintf ("%.f",($isototal / 1024));
156 print ("The ISO will be: $isototal mb\n");
157
158 # Downloading the files for the ISO
159 print ("The ISO will now be downloaded and build, do you wish to proceed?\n");
160 print ("Press any key to proceed or q to quit: ");
161 chomp ($continue = <stdin>);
162 $continue = lc($continue);
163 if ($continue =~/q/){
164         $exit++; last if $exit;
165 }
166
167 my @baseurl = split/\t/,$modules[-1];
168 #print ("$baseurl[0]\n");
169 system ("wget $baseurl[0]");
170 foreach my $line(@chosenmain){
171         $line--;
172         my @x = split/\t/,$mainmod[$line];
173         system ("wget $x[0]");
174         #print ("$x[0]\n");
175 }
176 if (@chosenmini){
177         foreach my $line(@chosenmini){
178                 my @x = split/\t/,$minimod[$line];
179                 system ("wget $x[0]");
180                 #print ("$x[0]\n");
181         }
182 }
183
184 my @morphbase = split/\//,$baseurl[0];
185 chomp $morphbase[-1];
186 system ("cd $workdir && tar xvzf ../$morphbase[-1]");
187 system ("cp *Main*.mod $workdir/mainmod");
188 system ("cp *Mini*.mod $workdir/minimod");
189
190 # Time to create the ISO
191 system ("cd $workdir && mkisofs -r -b base/boot.img -c boot.catalog -o ../morphix-custom.iso -J -v -l -L -T -V \"Morphix-Custom\" .");
192 print ("ISO written to: morphix-custom.iso\n");
193
194 # Finishing up
195 print ("Do you want to delete the downloaded files?\n");
196 print ("Press any key to proceed or q to quit: ");
197 chomp ($continue = <stdin>);
198 $continue = lc($continue);
199 if ($continue =~/q/){
200 } else {
201         system ("rm -rf $morphbase[-1]");
202         system ("rm -rf *Main*.mod");
203         system ("rm -rf *Mini*.mod");
204         system ("rm -rf modules.list");
205 }
206
207 # Cleaning up
208 system ("rm -rf $workdir");
209 $exit++; last if $exit;
210 }      
Note: See TracBrowser for help on using the browser.