| 1 | package Linux::Kernel::Build; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings FATAL => 'all'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 1 | ▶ | use Net::Ping; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Getopt::Std; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | require Exporter; | ||
| 11 | |||
| 12 | @ISA = (Exporter); | ||
| 13 | @EXPORT = qw(); | ||
| 14 | |||
| 15 | use vars qw($VERSION $SUBVERSION); | ||
| 16 | $VERSION = 2014.0623_00; | ||
| 17 | |||
| 18 | BEGIN { } | ||
| 19 | |||
| 20 | |||
| 21 | use constant DEBUGALITTLE => 1; # | ||
| 22 | use constant DEBUGALOT => 1; # | ||
| 23 | |||
| 24 | my $commandLineDisabled = undef; # | ||
| 25 | my $scriptName = 'kernelMaker.pl'; # | ||
| 26 | my $scriptVersion = '0.1-alpha'; # | ||
| 27 | my $kernelFileType = 'bz2'; | ||
| 28 | my $kernelFile = 'linux-2.6.11-rc2.tar.bz2'; | ||
| 29 | my $proxyEnableFlag = '0'; | ||
| 30 | my $proxy = ''; | ||
| 31 | my $proxyUser = ''; | ||
| 32 | my $proxyPassword = ''; | ||
| 33 | my $kernelSourceHostDirectoryURL = 'http://www.kernel.org/pub/linux/kernel/v2.6/testing/'; | ||
| 34 | my $maximumTries = '1'; | ||
| 35 | my $destinationDirectory = '/home/adutko/'; | ||
| 36 | my $timeout = '50'; | ||
| 37 | |||
| 38 | |||
| 39 | ###################################################################################### | ||
| 40 | ###################################################################################### | ||
| 41 | ## WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! ## | ||
| 42 | ###################################################################################### | ||
| 43 | ###################################################################################### | ||
| 44 | ## ## | ||
| 45 | ## Unless you know EXACTLY what you're doing it's best you ONLY modify the options ## | ||
| 46 | ## preceeding this warning or pass options to the script on the command line. ## | ||
| 47 | ## ## | ||
| 48 | ###################################################################################### | ||
| 49 | ###################################################################################### | ||
| 50 | ## WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! ## | ||
| 51 | ###################################################################################### | ||
| 52 | ###################################################################################### | ||
| 53 | |||
| 54 | |||
| 55 | ################################################################################## | ||
| 56 | ############################### SUBROUTINES ################################# | ||
| 57 | ################################################################################## | ||
| 58 | sub showMenu() { | ||
| 59 | |||
| 60 | print "usage: kernelMaker.pl [-help -type -file -proxy -user -passwd -url -tries -dir -timeout] | ||
| 61 | |||
| 62 | -help : Show this help menu. | ||
| 63 | -type : Specify the type of file compression. | ||
| 64 | -file : Specify the name of the compressed kernel file. | ||
| 65 | -enableproxy : Specify whether to enable proxy or not. | ||
| 66 | -proxy : Specify a proxy. | ||
| 67 | -user : Specify a proxy user. | ||
| 68 | -passwd : Specify a proxy password (WARNING :: PLAIN TEXT). | ||
| 69 | -url : Specify the URL for the directory where the -file can be found. | ||
| 70 | -tries : Specify the maximum number of times wget tries to retrieve -file from -url. | ||
| 71 | -dir : Specify where to save the generated package. | ||
| 72 | -timeout : Specify the timeout for wget. | ||
| 73 | \n"; | ||
| 74 | |||
| 75 | print "example: kernelMaker.pl -type=bz2 -file=kernel-2.6-1.tar.bz2 -proxy=0 -url=http://kernel.org/ARCHIVE/ -tries=2 -dir=/tmp -timeout=10\n"; | ||
| 76 | |||
| 77 | }; | ||
| 78 | |||
| 79 | sub optionVerifier($;$) { | ||
| 80 | |||
| 81 | my $optionsToVerify = shift || die "Didn't get options to verify in optionVerifier().\n"; | ||
| 82 | my $typeOfOptionsToVerify = shift || "Didn't get if you are using commandline options or manual options.\n"; | ||
| 83 | |||
| 84 | ################################################################################## | ||
| 85 | ############################### OPTION VERIFIER ############################## | ||
| 86 | ################################################################################## | ||
| 87 | |||
| 88 | ## Passed options in a more useable form. | ||
| 89 | my %optionsToBeVerified = %{$optionsToVerify}; | ||
| 90 | |||
| 91 | ## Command line variable values. | ||
| 92 | my @options = ("-type","-file","-enableproxy","-proxy","-user","-passwd","-url","-tries","-dir","-timeout"); | ||
| 93 | |||
| 94 | ## My verified options. | ||
| 95 | my $goodOptions = (); | ||
| 96 | |||
| 97 | ################################################################################## | ||
| 98 | ################################ KERNEL ME UP ################################ | ||
| 99 | ################################################################################## | ||
| 100 | my $kernelFileCompression = undef; | ||
| 101 | my $kernelFileDefinedType = undef; | ||
| 102 | my $kernelFileToUse = undef; | ||
| 103 | |||
| 104 | if ( $typeOfOptionsToVerify eq "TRUE" ) { | ||
| 105 | |||
| 106 | $kernelFileDefinedType = $kernelFileType; | ||
| 107 | $kernelFileToUse = $kernelFile; | ||
| 108 | |||
| 109 | } else { | ||
| 110 | |||
| 111 | $kernelFileDefinedType = $optionsToBeVerified{$options[0]}; | ||
| 112 | (my $file, my $kernelFileSplit) = split(/-file=/,$optionsToBeVerified{$options[1]},2); | ||
| 113 | $kernelFileToUse = $kernelFileSplit; | ||
| 114 | |||
| 115 | }; | ||
| 116 | |||
| 117 | if ( $kernelFileDefinedType =~ /gz/ ) { | ||
| 118 | |||
| 119 | print "KERNEL FILE TYPE SET :::::>>>>> gz \n" if DEBUGALOT; | ||
| 120 | |||
| 121 | push(@{$goodOptions},'gz'); | ||
| 122 | push(@{$goodOptions},$kernelFileToUse); | ||
| 123 | |||
| 124 | } elsif ( $kernelFileDefinedType =~ /bz2/ ) { | ||
| 125 | |||
| 126 | print "KERNEL FILE TYPE SET :::::>>>>> bz2 \n" if DEBUGALOT; | ||
| 127 | |||
| 128 | push(@{$goodOptions},'bz2'); | ||
| 129 | push(@{$goodOptions},$kernelFileToUse); | ||
| 130 | |||
| 131 | } elsif ( $kernelFileDefinedType =~ /tgz/ ) { | ||
| 132 | |||
| 133 | print "KERNEL FILE TYPE SET :::::>>>>> tgz \n" if DEBUGALOT; | ||
| 134 | |||
| 135 | push(@{$goodOptions},'tgz'); | ||
| 136 | push(@{$goodOptions},$kernelFileToUse); | ||
| 137 | |||
| 138 | } elsif ( $kernelFileDefinedType =~ /tar/ ) { | ||
| 139 | |||
| 140 | print "KERNEL FILE TYPE SET :::::>>>>> tar \n" if DEBUGALOT; | ||
| 141 | |||
| 142 | push(@{$goodOptions},'tar'); | ||
| 143 | push(@{$goodOptions},$kernelFileToUse); | ||
| 144 | |||
| 145 | } else { | ||
| 146 | |||
| 147 | die "You need to set \$kernelFileType to a recognized filetype before continuing...\n"; | ||
| 148 | |||
| 149 | }; | ||
| 150 | |||
| 151 | ################################################################################## | ||
| 152 | ############################# END KERNEL ME UP ############################## | ||
| 153 | ################################################################################## | ||
| 154 | |||
| 155 | ################################################################################## | ||
| 156 | ################################ WGET OPTIONS ################################ | ||
| 157 | ################################################################################## | ||
| 158 | |||
| 159 | my $noProxy = undef; | ||
| 160 | my $proxyFlag = undef; | ||
| 161 | my $proxyToUse = undef; | ||
| 162 | my $proxyUserToUse = undef; | ||
| 163 | my $proxyPasswordToUse = undef; | ||
| 164 | |||
| 165 | if ( $typeOfOptionsToVerify eq "TRUE" ) { | ||
| 166 | |||
| 167 | $proxyFlag = $proxyEnableFlag; | ||
| 168 | $proxyToUse = $proxy; | ||
| 169 | $proxyUserToUse = $proxyUser; | ||
| 170 | $proxyPasswordToUse = $proxyPassword; | ||
| 171 | |||
| 172 | } else { | ||
| 173 | |||
| 174 | (my $proxyCruft, my $proxyEnabledFlag) = split(/-enableproxy=/,$optionsToBeVerified{$options[2]},2); | ||
| 175 | $proxyFlag = $proxyEnabledFlag; | ||
| 176 | |||
| 177 | if ( $proxyFlag && $proxyFlag == '1' ) { | ||
| 178 | |||
| 179 | (my $proxyProxyCruft, my $proxyPassedProxy) = split(/-proxy=/,$optionsToBeVerified{$options[3]},2); | ||
| 180 | $proxyToUse = $proxyPassedProxy; | ||
| 181 | (my $proxyUserCruft, my $proxyPassedUser) = split(/-user=/,$optionsToBeVerified{$options[4]},2); | ||
| 182 | $proxyUserToUse = $proxyPassedUser; | ||
| 183 | (my $proxyPasswordCruft, my $proxyPassedPassword) = split(/-password=/,$optionsToBeVerified{$options[5]},2); | ||
| 184 | $proxyPasswordToUse = $proxyPassedPassword; | ||
| 185 | |||
| 186 | }; | ||
| 187 | |||
| 188 | }; | ||
| 189 | |||
| 190 | if ( $proxyFlag == '0' ) { | ||
| 191 | |||
| 192 | $noProxy = '--no-proxy'; | ||
| 193 | push(@{$goodOptions},$noProxy); | ||
| 194 | print "No proxy enabled so using --no-proxy for wget.\n" if DEBUGALOT; | ||
| 195 | |||
| 196 | } elsif ( $proxyFlag == '1' ) { | ||
| 197 | |||
| 198 | if ($proxyToUse && $proxyToUse ne '') { | ||
| 199 | |||
| 200 | push(@{$goodOptions},$proxyToUse); | ||
| 201 | print "Proxy verified and set...\n" if DEBUGALITTLE; | ||
| 202 | |||
| 203 | } else { | ||
| 204 | |||
| 205 | die "Please check the value of \$proxy.\n"; | ||
| 206 | |||
| 207 | }; | ||
| 208 | |||
| 209 | if ($proxyUserToUse && $proxyUserToUse ne '') { | ||
| 210 | |||
| 211 | push(@{$goodOptions},$proxyUserToUse); | ||
| 212 | print "Proxy user verified and set...\n" if DEBUGALITTLE; | ||
| 213 | |||
| 214 | } else { | ||
| 215 | |||
| 216 | die "Please check the value of \$proxyUser.\n"; | ||
| 217 | |||
| 218 | }; | ||
| 219 | |||
| 220 | if ($proxyPasswordToUse && $proxyPasswordToUse ne '') { | ||
| 221 | |||
| 222 | push(@{$goodOptions},$proxyPasswordToUse); | ||
| 223 | print "Proxy password verified and set...\n" if DEBUGALITTLE; | ||
| 224 | |||
| 225 | } else { | ||
| 226 | |||
| 227 | die "Please check the value of \$proxyPassword.\n"; | ||
| 228 | |||
| 229 | }; | ||
| 230 | |||
| 231 | } else { | ||
| 232 | |||
| 233 | die "Please set the \$proxyEnableFlag field to either 0 or 1.\n"; | ||
| 234 | |||
| 235 | }; | ||
| 236 | |||
| 237 | ################################################################################## | ||
| 238 | ############################## END WGET OPTIONS ############################## | ||
| 239 | ################################################################################## | ||
| 240 | |||
| 241 | ####################################### | ||
| 242 | #### KERNEL FILE HOST VERIFICATION #### | ||
| 243 | ####################################### | ||
| 244 | my $kernelFullURL = undef; | ||
| 245 | my $verifyHost = undef; | ||
| 246 | my $kernelURL = undef; | ||
| 247 | |||
| 248 | if ( $typeOfOptionsToVerify eq "TRUE" ) { | ||
| 249 | |||
| 250 | $kernelURL = $kernelSourceHostDirectoryURL; | ||
| 251 | |||
| 252 | } else { | ||
| 253 | |||
| 254 | (my $flag, my $kernelPassedURL) = split(/-url=/,$optionsToBeVerified{$options[6]},2); | ||
| 255 | $kernelURL = $kernelPassedURL; | ||
| 256 | |||
| 257 | }; | ||
| 258 | |||
| 259 | print "KERNEL FULL PATH =====>>>>> $kernelURL \n" if DEBUGALITTLE; | ||
| 260 | |||
| 261 | if( !defined($kernelURL) ) { | ||
| 262 | |||
| 263 | print "So tell me how you're supposed to run this script without kernel source?\n"; | ||
| 264 | print "You need to set \$kernelURL to a valid URL before proceeding.\n"; | ||
| 265 | exit; | ||
| 266 | |||
| 267 | }; | ||
| 268 | |||
| 269 | ## Get the actual host from $kernelURL | ||
| 270 | (my $http, my $kernelSourceHost) = split("http://",$kernelURL,2); | ||
| 271 | print "TRIMMED FULL PATH ======>>>>> $kernelSourceHost \n" if DEBUGALOT; | ||
| 272 | ($kernelSourceHost, my $leftover) = split("/",$kernelSourceHost,2); | ||
| 273 | print "PING =====>>>>> $kernelSourceHost :: LEFTOVER =====>>>>> $leftover\n" if DEBUGALOT; | ||
| 274 | |||
| 275 | $verifyHost = Net::Ping->new(); | ||
| 276 | if ( $verifyHost->ping($kernelSourceHost) ) { | ||
| 277 | |||
| 278 | $kernelFullURL = $kernelSourceHost . '/' . $kernelFile; | ||
| 279 | $verifyHost->close(); | ||
| 280 | |||
| 281 | push(@{$goodOptions},$kernelFullURL); | ||
| 282 | |||
| 283 | print "\$kernelSourceHost verified and set...\n" if DEBUGALITTLE; | ||
| 284 | print "$kernelSourceHost responded to ping!\n" if DEBUGALOT; | ||
| 285 | |||
| 286 | } else { | ||
| 287 | |||
| 288 | print "ERROR :::::>>>>> Please verify \$kernelSourceHostDirectoryURL.\n"; | ||
| 289 | print " It must be set to the directory where the kernel source file is located.\n"; | ||
| 290 | print " It cannot represent the full path of the kernel file.\n"; | ||
| 291 | |||
| 292 | exit(1); | ||
| 293 | |||
| 294 | }; | ||
| 295 | ####################################### | ||
| 296 | ## END KERNEL FILE HOST VERIFICATION ## | ||
| 297 | ####################################### | ||
| 298 | |||
| 299 | ####################################### | ||
| 300 | ###### MAXIMUM TRY VERIFICATION ###### | ||
| 301 | ####################################### | ||
| 302 | my $maxTries = undef; | ||
| 303 | |||
| 304 | if ( $typeOfOptionsToVerify eq "TRUE" ) { | ||
| 305 | |||
| 306 | $maxTries = $maximumTries; | ||
| 307 | |||
| 308 | } else { | ||
| 309 | |||
| 310 | (my $tries, my $triesPassed) = split(/-tries=/,$optionsToBeVerified{$options[7]},2); | ||
| 311 | $maxTries = $triesPassed; | ||
| 312 | |||
| 313 | }; | ||
| 314 | |||
| 315 | ## IS IT A NUMBER? | ||
| 316 | if ( !( $maxTries =~ /^-?\d/) ) { | ||
| 317 | |||
| 318 | die "Please set \$maxTries to a numeric value equal to or greater than 1.\n"; | ||
| 319 | |||
| 320 | } else { | ||
| 321 | |||
| 322 | print "\$maxTries verified and set...\n" if DEBUGALITTLE; | ||
| 323 | push(@{$goodOptions},$maxTries); | ||
| 324 | |||
| 325 | }; | ||
| 326 | |||
| 327 | ####################################### | ||
| 328 | ##### END MAXIMUM TRY VERIFICATION #### | ||
| 329 | ####################################### | ||
| 330 | |||
| 331 | ########################################## | ||
| 332 | # DESTINATION DIRECTORY VERIFICATION # | ||
| 333 | ########################################## | ||
| 334 | my $destDir = undef; | ||
| 335 | |||
| 336 | if ( $typeOfOptionsToVerify eq "TRUE" ) { | ||
| 337 | |||
| 338 | $destDir = $destinationDirectory; | ||
| 339 | |||
| 340 | } else { | ||
| 341 | |||
| 342 | (my $dir, my $dirPassed) = split(/-dir=/,$optionsToBeVerified{$options[8]},2); | ||
| 343 | $destDir = $dirPassed; | ||
| 344 | |||
| 345 | }; | ||
| 346 | |||
| 347 | if ( !( -d $destDir) ) { | ||
| 348 | |||
| 349 | die "Please set \$destDir to a valid system directory.\n"; | ||
| 350 | |||
| 351 | } else { | ||
| 352 | |||
| 353 | my $trailingSlash = substr($destDir,0,-1); | ||
| 354 | |||
| 355 | if ($trailingSlash ne "/") { | ||
| 356 | |||
| 357 | die "Please add a trailing slash to \$destDir.\n"; | ||
| 358 | |||
| 359 | } else { | ||
| 360 | |||
| 361 | print "\$destDir verified and set...\n" if DEBUGALITTLE; | ||
| 362 | push(@{$goodOptions},$destDir); | ||
| 363 | |||
| 364 | }; | ||
| 365 | |||
| 366 | }; | ||
| 367 | |||
| 368 | ########################################## | ||
| 369 | # END DESTINATION DIRECTORY VERIFICATION # | ||
| 370 | ########################################## | ||
| 371 | |||
| 372 | ####################################### | ||
| 373 | ###### TIMEOUT VERIFICATION ###### | ||
| 374 | ####################################### | ||
| 375 | my $setTimeout = undef; | ||
| 376 | |||
| 377 | if ( $typeOfOptionsToVerify eq "TRUE" ) { | ||
| 378 | |||
| 379 | $setTimeout = $timeout; | ||
| 380 | |||
| 381 | } else { | ||
| 382 | |||
| 383 | (my $timeout, my $timeoutPassed) = split(/-timeout=/,$optionsToBeVerified{$options[9]},2); | ||
| 384 | $setTimeout = $timeoutPassed; | ||
| 385 | |||
| 386 | }; | ||
| 387 | |||
| 388 | if ( !( $setTimeout =~ /^-?\d/) ) { | ||
| 389 | |||
| 390 | die "Please set \$setTimeout to a numeric value equal to or greater than 1.\n"; | ||
| 391 | |||
| 392 | } else { | ||
| 393 | |||
| 394 | print "\$setTimeout verified and set...\n" if DEBUGALITTLE; | ||
| 395 | push(@{$goodOptions},$setTimeout); | ||
| 396 | |||
| 397 | }; | ||
| 398 | |||
| 399 | ####################################### | ||
| 400 | #### END TIMEOUT VERIFICATION ##### | ||
| 401 | ####################################### | ||
| 402 | |||
| 403 | ################################################################################## | ||
| 404 | ############################# END OPTION VERIFIER ############################# | ||
| 405 | ################################################################################## | ||
| 406 | |||
| 407 | return $goodOptions; | ||
| 408 | |||
| 409 | }; | ||
| 410 | |||
| 411 | sub getSource($;$) { | ||
| 412 | |||
| 413 | my $getdir = shift || die "Didn't get a directory to download source for getSource().\n"; | ||
| 414 | my $getsrc = shift || die "Didn't get a source URL.\n"; | ||
| 415 | my $getOptions = shift || die "Didn't get any wget options.\n"; | ||
| 416 | |||
| 417 | my $retriever = 'wget '; | ||
| 418 | my $flatOptions = undef; | ||
| 419 | my $wgetSrc = undef; | ||
| 420 | |||
| 421 | for my $individualWGETOption (@{$getOptions}) { | ||
| 422 | |||
| 423 | $flatOptions = ' ' . $individualWGETOption . ' '; | ||
| 424 | |||
| 425 | }; | ||
| 426 | |||
| 427 | $wgetSrc = 'wget' . $flatOptions . '-P ' . $getdir . ' ' . $getsrc; | ||
| 428 | |||
| 429 | my $geterror = `$wgetSrc`; | ||
| 430 | |||
| 431 | if( $geterror eq "") { | ||
| 432 | |||
| 433 | return("GOT KERNEL SOURCE!","TRUE"); | ||
| 434 | |||
| 435 | } else { | ||
| 436 | |||
| 437 | return("FAILED TO GET KERNEL SOURCE!","FALSE"); | ||
| 438 | |||
| 439 | }; | ||
| 440 | |||
| 441 | }; | ||
| 442 | |||
| 443 | sub expandSource($;$) { | ||
| 444 | |||
| 445 | my $curdir = shift || die "Didn't get a directory to expand the kernel source into for expandSource().\n"; | ||
| 446 | my $srcfile = shift || die "Didn't get a kernel source file for expandSource().\n"; | ||
| 447 | |||
| 448 | my $expander = 'tar -xzvf '; | ||
| 449 | my $expandcmd = $expander . $srcfile . ' -C ' . $curdir; | ||
| 450 | |||
| 451 | my $mkdir = 'mkdir ' . $curdir; | ||
| 452 | |||
| 453 | my $mkdirerror = `$mkdir`; | ||
| 454 | |||
| 455 | if( $mkdirerror eq "" ) { | ||
| 456 | |||
| 457 | my $expanderror = `$expandcmd`; | ||
| 458 | |||
| 459 | if( $expanderror ne "" ) { | ||
| 460 | |||
| 461 | return("EXPANDED KERNEL SOURCE!","TRUE"); | ||
| 462 | |||
| 463 | } else { | ||
| 464 | |||
| 465 | return("FAILED TO EXPAND KERNEL SOURCE!","FALSE"); | ||
| 466 | |||
| 467 | }; | ||
| 468 | |||
| 469 | } else { | ||
| 470 | |||
| 471 | return("FAILED TO CREATE THE KERNEL DESTINATION DIRECTORY!","FALSE"); | ||
| 472 | |||
| 473 | }; | ||
| 474 | |||
| 475 | }; | ||
| 476 | |||
| 477 | sub makeSource($;$;$) { | ||
| 478 | |||
| 479 | my $configdir = shift || die "Didn't get a directory to 'make config' for makeSource().\n"; | ||
| 480 | my $exitdir = shift || die "Didn't get a directory leave for makeSource().\n"; | ||
| 481 | my $kernelSourceFileName = shift || die "Didn't get the name of the kernel directory for makeSource().\n"; | ||
| 482 | my $intodir = $configdir . $kernelSourceFileName . '/'; | ||
| 483 | my $kernelmakerconfig = 'Y | make -C ' . $intodir . ' config'; | ||
| 484 | my $kernelmakermake = 'make -C ' . $intodir; | ||
| 485 | my $kernelmakerclean = 'make -C ' . $intodir . ' clean'; | ||
| 486 | |||
| 487 | my $kernelmakerconfigerror = `$kernelmakerconfig`; | ||
| 488 | |||
| 489 | if( $kernelmakerconfigerror ne "" ) { | ||
| 490 | |||
| 491 | my $kernelmakermakeerror = `$kernelmakermake`; | ||
| 492 | |||
| 493 | if( $kernelmakermakeerror ne "" ) { | ||
| 494 | |||
| 495 | my $kernelmakercleanerror = `$kernelmakerclean`; | ||
| 496 | |||
| 497 | if( $kernelmakercleanerror ne "" ) { | ||
| 498 | |||
| 499 | return("MADE THE KERNEL!","TRUE"); | ||
| 500 | |||
| 501 | } else { | ||
| 502 | |||
| 503 | return("MAKE CLEAN KERNEL FAILED!","FALSE"); | ||
| 504 | |||
| 505 | }; | ||
| 506 | |||
| 507 | } else { | ||
| 508 | |||
| 509 | return("ERROR IN MAKING KERNEL","FALSE"); | ||
| 510 | |||
| 511 | }; | ||
| 512 | |||
| 513 | } else { | ||
| 514 | |||
| 515 | return("ERROR MAKING CONFIG FOR KERNEL","FALSE"); | ||
| 516 | |||
| 517 | }; | ||
| 518 | |||
| 519 | }; | ||
| 520 | |||
| 521 | sub installKernel() { | ||
| 522 | |||
| 523 | |||
| 524 | |||
| 525 | }; | ||
| 526 | |||
| 527 | sub cleanSource($;$) { | ||
| 528 | |||
| 529 | my $rmdir = shift || die "Didn't get a directory to cleanSource().\n"; | ||
| 530 | my $rmfiledir = shift || die "Didn't get a file to cleanSource().\n"; | ||
| 531 | |||
| 532 | my $removedircmd = 'rm -rf ' . $rmdir; | ||
| 533 | my $removefilecmd = 'rm -f ' . $rmfiledir . $kernelFile; | ||
| 534 | |||
| 535 | my $removeerror = `$removedircmd`; | ||
| 536 | my $removefileerror = `$removefilecmd`; | ||
| 537 | |||
| 538 | if( ($removeerror eq "") && ($! eq "") ) { | ||
| 539 | |||
| 540 | if( ($removefileerror eq "") && ($! eq "") ) { | ||
| 541 | |||
| 542 | return ("REMOVED DIRECTORY AND SOURCE FILE","TRUE"); | ||
| 543 | |||
| 544 | } else { | ||
| 545 | |||
| 546 | return("ERROR REMOVING SOURCE FILE","FALSE"); | ||
| 547 | |||
| 548 | }; | ||
| 549 | |||
| 550 | } else { | ||
| 551 | |||
| 552 | return ("ERROR REMOVING DIRECTORY","FALSE"); | ||
| 553 | |||
| 554 | }; | ||
| 555 | |||
| 556 | }; | ||
| 557 | |||
| 558 | sub getHostName() { | ||
| 559 | my $prog = '/bin/hostname'; | ||
| 560 | my $hostname = `$prog`; | ||
| 561 | my @HOST_PARTS = split /\./, $hostname; | ||
| 562 | |||
| 563 | return ($HOST_PARTS[0]); | ||
| 564 | }; | ||
| 565 | |||
| 566 | sub main() { | ||
| 567 | |||
| 568 | my $hostname = getHostName(); | ||
| 569 | |||
| 570 | ## Manual variable values. | ||
| 571 | my $manualKernelFileType = undef; | ||
| 572 | my $manualKernelFile = undef; | ||
| 573 | my $manualKernelSourceHostDirectoryURL = undef; | ||
| 574 | my $manualProxyEnableFlag = undef; | ||
| 575 | my $manualProxy = undef; | ||
| 576 | my $manualProxyUser = undef; | ||
| 577 | my $manualProxyPassword = undef; | ||
| 578 | my $manualMaximumTries = undef; | ||
| 579 | my $manualDestinationDirectory = undef; | ||
| 580 | my $manualTimeout = undef; | ||
| 581 | |||
| 582 | ## Valid command line options. | ||
| 583 | my %options = ( | ||
| 584 | -help => undef, # Show this help menu. | ||
| 585 | -type => undef, # Specify the type of file compression. | ||
| 586 | -file => undef, # Specify the name of the compressed kernel file. | ||
| 587 | -enableproxy => undef, # Specify whether to enable proxy or not. | ||
| 588 | -proxy => undef, # Specify a proxy. | ||
| 589 | -user => undef, # Specify a proxy user. | ||
| 590 | -passwd => undef, # Specify a proxy password (WARNING :: PLAIN TEXT). | ||
| 591 | -url => undef, # Specify the URL for the directory where the -file can be found. | ||
| 592 | -tries => undef, # Specify the maximum number of times wget tries to retrieve -file from -url. | ||
| 593 | -dir => undef, # Specify where to save the generated package. | ||
| 594 | -timeout => undef, # Specify the timeout for wget. | ||
| 595 | ); | ||
| 596 | |||
| 597 | ## Manual variable storage. | ||
| 598 | my $manualVariableStore = (); | ||
| 599 | |||
| 600 | if (!@ARGV) { | ||
| 601 | |||
| 602 | print "Initializing $scriptName v.$scriptVersion on $hostname...\n" if DEBUGALITTLE; | ||
| 603 | print "NO command line options specified.\n" if DEBUGALITTLE; | ||
| 604 | |||
| 605 | $commandLineDisabled = "TRUE"; | ||
| 606 | |||
| 607 | ############################################################################### | ||
| 608 | ############################ MANUAL CONFIG OPTIONS ########################## | ||
| 609 | ############################################################################### | ||
| 610 | $manualKernelFileType = $kernelFileType; # | ||
| 611 | $manualKernelFile = $kernelFile; # | ||
| 612 | $manualKernelSourceHostDirectoryURL = $kernelSourceHostDirectoryURL; # | ||
| 613 | $manualProxyEnableFlag = $proxyEnableFlag; # | ||
| 614 | $manualProxy = $proxy; # | ||
| 615 | $manualProxyUser = $proxyUser; # | ||
| 616 | $manualProxyPassword = $proxyPassword; # | ||
| 617 | $manualMaximumTries = $maximumTries; # | ||
| 618 | $manualDestinationDirectory = $destinationDirectory; # | ||
| 619 | $manualTimeout = $timeout; # | ||
| 620 | ############################################################################### | ||
| 621 | ############################# END CONFIG OPTIONS ############################ | ||
| 622 | ############################################################################### | ||
| 623 | |||
| 624 | } else { | ||
| 625 | |||
| 626 | print "Initializing $scriptName v.$scriptVersion on $hostname...\n" if DEBUGALITTLE; | ||
| 627 | print "Command line options specified.\n" if DEBUGALITTLE; | ||
| 628 | |||
| 629 | $commandLineDisabled = "FALSE"; | ||
| 630 | |||
| 631 | ################################################################################## | ||
| 632 | ############################## CML CONFIG OPTIONS ############################## | ||
| 633 | ################################################################################## | ||
| 634 | |||
| 635 | my $argument = undef; | ||
| 636 | |||
| 637 | print "ALL ARGUMENTS :::::>>>>> @ARGV \n" if DEBUGALOT; | ||
| 638 | |||
| 639 | foreach $argument (@ARGV) { | ||
| 640 | |||
| 641 | print "ARGUMENT :::::>>>>> $argument\n" if DEBUGALITTLE; | ||
| 642 | |||
| 643 | ## Does each argument have a - in front of it? | ||
| 644 | if ($argument !~ /^-/) { | ||
| 645 | |||
| 646 | die "Unknown option $argument. Please make sure you've prepended each argument with a single dash.\n"; | ||
| 647 | |||
| 648 | }; | ||
| 649 | |||
| 650 | (my $argumentField,my $argumentValue) = split(/=/,$argument,2); | ||
| 651 | |||
| 652 | if ( $argumentField eq "-help" ) { | ||
| 653 | |||
| 654 | print "CALLING HELP MENU :::::>>>>> \n" if DEBUGALOT; | ||
| 655 | |||
| 656 | showMenu(); | ||
| 657 | |||
| 658 | exit(1); | ||
| 659 | |||
| 660 | }; | ||
| 661 | |||
| 662 | }; | ||
| 663 | |||
| 664 | }; | ||
| 665 | |||
| 666 | ################################################################################## | ||
| 667 | ############################ END CML CONFIG OPTIONS ############################ | ||
| 668 | ################################################################################## | ||
| 669 | |||
| 670 | if ( $commandLineDisabled eq "TRUE" ) { | ||
| 671 | |||
| 672 | print "Initializing $scriptName v.$scriptVersion on $hostname...\n"; | ||
| 673 | |||
| 674 | print "Using the following manual parameters to generate your kernel package: | ||
| 675 | -type => $manualKernelFileType | ||
| 676 | -file => $manualKernelFile | ||
| 677 | -enableproxy => $manualProxyEnableFlag | ||
| 678 | -proxy => $manualProxy | ||
| 679 | -user => $manualProxyUser | ||
| 680 | -passwd => $manualProxyPassword | ||
| 681 | -url => $manualKernelSourceHostDirectoryURL | ||
| 682 | -tries => $manualMaximumTries | ||
| 683 | -dir => $manualDestinationDirectory | ||
| 684 | -timeout => $manualTimeout | ||
| 685 | \n"; | ||
| 686 | |||
| 687 | print "Verifying manual configuration options...\n" if DEBUGALITTLE; | ||
| 688 | |||
| 689 | ## Translate manual options to a hash. | ||
| 690 | my %manualOptions = ( | ||
| 691 | -type => $manualKernelFileType, | ||
| 692 | -file => $manualKernelFile, | ||
| 693 | -enableproxy => $manualProxyEnableFlag, | ||
| 694 | -proxy => $manualProxy, | ||
| 695 | -user => $manualProxyUser, | ||
| 696 | -passwd => $manualProxyPassword, | ||
| 697 | -url => $manualKernelSourceHostDirectoryURL, | ||
| 698 | -tries => $manualMaximumTries, | ||
| 699 | -dir => $manualDestinationDirectory, | ||
| 700 | -timeout => $manualTimeout, | ||
| 701 | ); | ||
| 702 | |||
| 703 | my $validManualOptions = optionVerifier(\%manualOptions,$commandLineDisabled); | ||
| 704 | |||
| 705 | print "All options verified... @{$validManualOptions} \n"; | ||
| 706 | |||
| 707 | #if( (-f $manualOptions{"-dir"} . $manualOptions{"-file"}) ) { | ||
| 708 | |||
| 709 | # print "Hrmm...I'm thinking cleanSource() failed b/c my source file still exists from the previous run...\n"; | ||
| 710 | # print "Removing...\n"; | ||
| 711 | |||
| 712 | # `rm -rf $directory`; | ||
| 713 | # `rm -f $directoryparent$kernelfile*`; | ||
| 714 | |||
| 715 | #}; | ||
| 716 | |||
| 717 | |||
| 718 | } elsif ( $commandLineDisabled eq "FALSE" ) { | ||
| 719 | |||
| 720 | print "Initializing $scriptName v.$scriptVersion on $hostname...\n"; | ||
| 721 | |||
| 722 | print "Using the following command line parameters to generate your kernel package: \n"; | ||
| 723 | |||
| 724 | my %commandLineOptions = (); | ||
| 725 | |||
| 726 | for my $lineOption (@ARGV) { | ||
| 727 | |||
| 728 | if ( $lineOption =~ /-enableproxy/ ) { | ||
| 729 | |||
| 730 | ## Translate command line options to a hash. | ||
| 731 | %commandLineOptions = ( | ||
| 732 | -type => $ARGV[0], | ||
| 733 | -file => $ARGV[1], | ||
| 734 | -enableproxy => $ARGV[2], | ||
| 735 | -proxy => $ARGV[3], | ||
| 736 | -user => $ARGV[4], | ||
| 737 | -passwd => $ARGV[5], | ||
| 738 | -url => $ARGV[6], | ||
| 739 | -tries => $ARGV[7], | ||
| 740 | -dir => $ARGV[8], | ||
| 741 | -timeout => $ARGV[9], | ||
| 742 | ); | ||
| 743 | |||
| 744 | } else { | ||
| 745 | |||
| 746 | ## Translate command line options to a hash. | ||
| 747 | %commandLineOptions = ( | ||
| 748 | -type => $ARGV[0], | ||
| 749 | -file => $ARGV[1], | ||
| 750 | -enableproxy => $ARGV[2], | ||
| 751 | -url => $ARGV[3], | ||
| 752 | -tries => $ARGV[4], | ||
| 753 | -dir => $ARGV[5], | ||
| 754 | -timeout => $ARGV[6], | ||
| 755 | ); | ||
| 756 | |||
| 757 | }; | ||
| 758 | |||
| 759 | }; | ||
| 760 | |||
| 761 | ## Let's verify all passed options are actual options. | ||
| 762 | while( (my $optionKey, my $optionValue) = (each %commandLineOptions) ) { | ||
| 763 | |||
| 764 | if( $optionValue ) { | ||
| 765 | |||
| 766 | print "KEY :: $optionKey -- VALUE :: $optionValue \n" if DEBUGALOT; | ||
| 767 | |||
| 768 | } else { | ||
| 769 | |||
| 770 | print "KEY :: $optionKey -- VALUE :: NULL \n" if DEBUGALOT; | ||
| 771 | |||
| 772 | }; | ||
| 773 | |||
| 774 | }; | ||
| 775 | |||
| 776 | print "Verifying command line configuration options...\n" if DEBUGALITTLE; | ||
| 777 | |||
| 778 | my $validCommandLineOptions = optionVerifier(\%commandLineOptions,$commandLineDisabled); | ||
| 779 | |||
| 780 | print "All options verified... @{$validCommandLineOptions} \n"; | ||
| 781 | |||
| 782 | } else { | ||
| 783 | |||
| 784 | print "There is something really wrong b/c \$commandLineDisabled isn't set properly.\n"; | ||
| 785 | |||
| 786 | }; | ||
| 787 | |||
| 788 | ########### | ||
| 789 | ## STOP ## | ||
| 790 | ########### | ||
| 791 | |||
| 792 | }; | ||
| 793 | |||
| 794 | |||
| 795 | ########### | ||
| 796 | ## START ## | ||
| 797 | ########### | ||
| 798 | &main; | ||
| 799 | |||
| 800 | |||
| 801 | =head1 NAME | ||
| 802 | |||
| 803 | Linux::Kernel::Build - Custom Linux Kernel Builds | ||
| 804 | |||
| 805 | =head1 VERSION | ||
| 806 | |||
| 807 | Version 2014.0621_00 | ||
| 808 | |||
| 809 | =cut | ||
| 810 | |||
| 811 | |||
| 812 | =head1 SYNOPSIS | ||
| 813 | |||
| 814 | Linux::Kernel::Build is the namespace for the subroutines | ||
| 815 | associated with downloading, building and optionally | ||
| 816 | installing new kernels. It is part of the Linux::Kernel | ||
| 817 | suite of tools associated with the Linux kernel. Another | ||
| 818 | tool available via the CPAN that does something similar is | ||
| 819 | 'kif'. The reasoning behind creating the Linux::Kernel | ||
| 820 | namespace was to generate a central namespace Kernel related | ||
| 821 | operationgs functions and data. As of June 2014, there are | ||
| 822 | other modules and distributions in the planning stages that | ||
| 823 | will take code from existing CPAN modules that either expose | ||
| 824 | kernel related data to users or enable users to work with | ||
| 825 | the Linux kernel, and put the code in other namespaces under | ||
| 826 | Linux::Kernel. | ||
| 827 | |||
| 828 | Linux::Kernel::Build focuses on the following: | ||
| 829 | |||
| 830 | 1) Download a compressed and archived kernel. | ||
| 831 | 2) Decompress and expand the kernel into a known directory. | ||
| 832 | 3) make config the kernel. | ||
| 833 | 4) make the kernel. | ||
| 834 | 5) install the kernel automatically. | ||
| 835 | 6) remove all used directories and files. | ||
| 836 | |||
| 837 | |||
| 838 | Perhaps a little code snippet. | ||
| 839 | |||
| 840 | use Linux::Kernel::Build; | ||
| 841 | |||
| 842 | my $kernel = Linux::Kernel::Build->new(); | ||
| 843 | $kernel->get(); | ||
| 844 | $kernel->unpack(); | ||
| 845 | $kernel->config(); | ||
| 846 | $kernel->build(); | ||
| 847 | $kernel->install(); | ||
| 848 | $kernel->clean(); | ||
| 849 | |||
| 850 | =head1 EXPORT | ||
| 851 | |||
| 852 | =head1 SUBROUTINES/METHODS | ||
| 853 | |||
| 854 | =head2 showMenu() | ||
| 855 | |||
| 856 | |||
| 857 | =cut | ||
| 858 | |||
| 859 | =head2 optionVerifier() | ||
| 860 | |||
| 861 | |||
| 862 | =cut | ||
| 863 | |||
| 864 | =head2 getSource() | ||
| 865 | |||
| 866 | =cut | ||
| 867 | |||
| 868 | =head2 expandSource() | ||
| 869 | |||
| 870 | =cut | ||
| 871 | |||
| 872 | =head2 makeSource() | ||
| 873 | |||
| 874 | =cut | ||
| 875 | |||
| 876 | =head2 installKernel() | ||
| 877 | |||
| 878 | =cut | ||
| 879 | |||
| 880 | =head2 cleanSource() | ||
| 881 | |||
| 882 | =cut | ||
| 883 | |||
| 884 | =head2 getHostName() | ||
| 885 | |||
| 886 | =cut | ||
| 887 | |||
| 888 | =head2 main() | ||
| 889 | |||
| 890 | =cut | ||
| 891 | |||
| 892 | |||
| 893 | =head1 AUTHOR | ||
| 894 | |||
| 895 | Adam M Dutko, C<< <addutko at cpan.org> >> | ||
| 896 | |||
| 897 | =head1 BUGS | ||
| 898 | |||
| 899 | Please report any bugs or feature requests to C<bug-linux-kernel at rt.cpan.org | ||
| 900 | >, or through | ||
| 901 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Linux-Ker | ||
| 902 | nel>. I will be notified, and then you'll | ||
| 903 | automatically be notified of progress on your bug as I make changes. | ||
| 904 | |||
| 905 | =head1 TODO | ||
| 906 | |||
| 907 | 1) Need to verify all installation options; break out into subroutines. | ||
| 908 | 2) Modify the get, clean, make and install routines. | ||
| 909 | 3) Configure to use the users old config. | ||
| 910 | |||
| 911 | =head1 SUPPORT | ||
| 912 | |||
| 913 | You can find documentation for this module with the perldoc command. | ||
| 914 | |||
| 915 | perldoc Linux::Kernel | ||
| 916 | |||
| 917 | |||
| 918 | You can also look for information at: | ||
| 919 | |||
| 920 | =over 4 | ||
| 921 | |||
| 922 | =item * RT: CPAN's request tracker (report bugs here) | ||
| 923 | |||
| 924 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Linux-Kernel> | ||
| 925 | |||
| 926 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 927 | |||
| 928 | L<http://annocpan.org/dist/Linux-Kernel> | ||
| 929 | |||
| 930 | =item * CPAN Ratings | ||
| 931 | |||
| 932 | L<http://cpanratings.perl.org/d/Linux-Kernel> | ||
| 933 | |||
| 934 | =item * Search CPAN | ||
| 935 | |||
| 936 | L<http://search.cpan.org/dist/Linux-Kernel/> | ||
| 937 | |||
| 938 | =back | ||
| 939 | |||
| 940 | =head1 ACKNOWLEDGEMENTS | ||
| 941 | |||
| 942 | =head1 LICENSE AND COPYRIGHT | ||
| 943 | |||
| 944 | Copyright (C) 2007-2014 Adam M. Dutko | ||
| 945 | |||
| 946 | This program is free software; you can redistribute it and/or modify | ||
| 947 | it under the terms of the GNU General Public License as published by | ||
| 948 | the Free Software Foundation; version 2 dated June, 1991 or at your option | ||
| 949 | any later version. | ||
| 950 | |||
| 951 | This program is distributed in the hope that it will be useful, | ||
| 952 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 953 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 954 | GNU General Public License for more details. | ||
| 955 | |||
| 956 | A copy of the GNU General Public License is available in the source tree; | ||
| 957 | if not, write to the Free Software Foundation, Inc., | ||
| 958 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 959 | |||
| 960 | |||
| 961 | =cut | ||
| 962 | |||
| 963 | 1; # End of Linux::Kernel | ||
| 964 | |||