Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 64.06 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. #
  3. # MyLiveCD iso build script
  4. #
  5. # Copyright (C) 2010 Bill Reynolds <texstar@gmail.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # Adapted from the Mklivecd
  22. #
  23.  
  24. use strict;
  25. use lib qw(/usr/lib/libDrakX);
  26. require services;
  27.  
  28.  
  29. ### dependancies
  30. use Getopt::Long;
  31. use MDK::Common;
  32. use run_program;
  33. use Storable qw(store);
  34. use threads::shared;
  35.  
  36. ### useful functions
  37. sub get_exec { my $r = qx($_[0]); chomp($r); $r; };
  38.  
  39. ### global "constants"
  40. my $PROG_VERSION = '0.9.5';
  41. my $PROG_NAME = 'mylivecd';
  42. my $ESC = "\x1B[";
  43. my $URL = "http://pclinuxos.com/";
  44. my $COPYRIGHT = "Copyright (C) 2010, Texstar <texstar at gmail.com>";
  45.  
  46. ### global variables
  47. my $starttime = time;
  48. my $workdir = undef;
  49. my $kernel26 = undef;
  50. my $kernelver = "2.6.32";
  51. my $dietarch = undef;
  52. my $depmod = "/sbin/depmod";
  53. my $modfile = "/etc/modules.conf";
  54. my $modext = undef;
  55. my $modules = undef;
  56. my $modules_opt = "";
  57. my $modules_26 = "";
  58. my $modules_opt_26 = "";
  59. my $nodirs = '^/[.].* ^/dev$ ^/initrd$ ^/lost+found$ ^/mnt$ ^/media$ ^/proc$ ^/sys$ ^/tmp$ ^/var/tmp$ ^/root/tmp$ ^/home/guest/tmp$ ^/proc/asound ^/root/.local/share/akonadi ^/home/guest/.local/share/akonadi ^/root/.kde4/share/apps/kmix ^/home/guest/.kde4/share/apps/kmix ^/root/.synaptic/log';
  60. my $nofiles = '^/[.].* ^/fastboot$ /core[.][0-9][0-9]*$ .*~$ .*[.]rpmnew$ .*[.]rpmsave$ [.]bash_history$ [.]fonts[.]cache-[0-9]$ [.]xauth.* [.]wh[.]* [.]xsession-errors$ icon-theme.cache$ ^/var/run/ ^/var/lock/subsys/ ^/var/lib/dhcp/ ^/root/.kde4/share/config/kmix* ^/root/.kde4/share/config/phonondevicesrc ^/home/guest/.kde4/share/config/kmix* ^/home/guest/.kde4/share/config/phonondevicesrc ^/etc/modprobe.conf ^/etc/sysconfig/network-scripts/ifcfg-eth* ^/etc/udev/rules.d/70-persistent* ^/var/lib/alsa/asound.state ^/etc/asound.state ^/etc/lilo.conf ^/boot/grub/menu.lst ^/etc/modprobe.preload.d/cpufreq ^/etc/sysconfig/harddrake2/previous_hw ^/var/lib/rpm/__db.* ^/etc/sysconfig/finish-install ^/var/lib/speedboot/* ^/etc/modprobe.d/sound ^/var/log/mysqld/mysqlmanager.log';
  61. my $loopmod = undef;
  62. my $loopcmp = undef;
  63. my $o_stage2 = undef;
  64. my $finaliso = "livecd.iso";
  65. my $loader = "isolinux/isolinux.bin";
  66. my $md5sum = undef;
  67. my $genisoimage_opts = ""; # Fix for concat of undef in iso looptype
  68. my @services = ();
  69.  
  70. ### command-line options
  71. my $o_verbose;
  72. my $o_workdir;
  73. my $o_root = "/";
  74. my $o_tmp = "/tmp";
  75. my $o_looptype = "sqfs";
  76. my $o_keyboard = 'us';
  77. my $o_resolution = '800x600';
  78. my $o_theme = 'PCLinuxOS';
  79. my $o_vgamode = '788';
  80. my $o_splash = "silent";
  81. my $o_bootloader = "iso";
  82. my $o_ufs = 'unionfs';
  83. my $o_kernel = get_exec("uname -r");
  84. my $o_mbkopt = "";
  85. my $o_mbkopt_label = "";
  86. my $o_lzma;
  87. my $o_gzip;
  88. my $o_xz;
  89.  
  90. my $o_timeout = 90;
  91. my %opts = ( # these are all the options with defaults
  92. 'root' => \$o_root,
  93. 'tmp' => \$o_tmp,
  94. 'keyboard' => \$o_keyboard,
  95. 'resolution' => \$o_resolution,
  96. 'splash' => \$o_splash,
  97. 'kernel' => \$o_kernel,
  98. 'timeout' => \$o_timeout,
  99. 'bootloader' => \$o_bootloader,
  100. 'mbkopt' => \$o_mbkopt,
  101. 'mbkopt_label' => \$o_mbkopt_label,
  102. 'ufs' => \$o_ufs
  103. );
  104.  
  105.  
  106. ### startup banner
  107. sub print_banner {
  108. print STDERR "$PROG_NAME, version $PROG_VERSION, $URL
  109. $COPYRIGHT
  110.  
  111. This program is free software; you can redistribute it and/or
  112. modify it under the terms of the GNU General Public License
  113. as published by the Free Software Foundation; either version 2
  114. of the License, or (at your option) any later version.
  115. ";
  116. }
  117.  
  118.  
  119. ### usage
  120. sub print_usage {
  121. print STDERR "Usage:
  122. $0 [options] <livecd-image>
  123.  
  124. General Options:
  125. --help Display this message
  126. --version Display version information
  127. --verbose Be verbose in output
  128. --noclean Don't remove temporary files on exit. #'
  129. --workdir Specify a working directory which will not
  130. be cleaned.
  131. --debug Display some extra debugging information
  132. while building the CD. (Usefull for bug
  133. reports to the developers.)
  134.  
  135. Image generation:
  136. --root <rootdir> Root directory of the live filesystem to use
  137. as the for the image of the LiveCD.
  138. (default: $o_root)
  139. --tmp <tmpdir> Name of the directory to be used for
  140. temporary file storage.
  141. (default: $o_tmp)
  142. --img <image> Name of the saved compressed image. When an
  143. image by this name is found, it will not be
  144. re-created or overwritten, rather the
  145. existing image will be re-used, i.e. the
  146. compressed image is not re-built.
  147. --nofile <ex1>[,][...] Excludes files from the final image. (Also
  148. see the --nodir option for a full
  149. description)
  150. --nodir <ex1>[,][...] Excludes directories from the final image.
  151. Patterns passed to this option (as with the
  152. --nofile option) should be valid in a grep(1)
  153. search, e.g. --nodir=^/home/jaco,^/root/.mcop
  154. will exclude both the /home/jaco and
  155. /root/.mcop directories from the final
  156. LiveCD.
  157. --sort <file> Sort the files on the compressed iso image
  158. according to the genisoimage-style sort specifier
  159. as detailed in file.
  160. --kernel <kernel> Kernel to use as default for the LiveCD
  161. image. (Output of uname -r)
  162. (default: $o_kernel)
  163. --lzma Use with kernels older than 2.6.37
  164. --gzip Use gzip compression for the image
  165. --xz Use xz compression for the image
  166.  
  167. Boot options:
  168. --bootopt <option> Specify an additional boot option to pass to
  169. the kernel command-line.
  170. --bootmsg <msg> Use 'msg' as the isolinux boot message.
  171. --bootkey <key=msg> Display 'msg' on key 'key' from isolinux.
  172. --bootimg <img> Use 'img' (LSS format) as the isolinux.
  173. background display image.
  174. --bootloader <iso|grub|usb> The bootloader to use on the livecd i.e. isolinux,
  175. GRUB or syslinux for usb stick
  176. --bootmenu <file> What boot menu definition file should be used
  177. in case that bootloader option is set to iso or grub.
  178. For iso this file must be named 'isolinux.cfg',
  179. for grub the name must be 'menu.lst'.
  180. Boot menu will be generated if not specified.
  181. --boottheme <name> Which gfxboot theme should be used.
  182. Defaults to 'pclinuxos'
  183. --bootlang <lang code> Which language shound be used as default
  184. in the boot menu.
  185. Defaults to 'en'.
  186. --mbkopt <kernel> Create the ISO with multi boot kernel option.
  187. --mbkopt-label <Menu Label> Customize the menu entry for the 2nd kernel
  188.  
  189. --ufs <unionfs|aufs> Specify the union file system.
  190. --timeout <sec> Specify the default ISO Linux prompt timeout
  191. in seconds.
  192. (default: $o_timeout)
  193. --noprompt Disable ISO Linux prompt (i.e. prompt 0).
  194. --keyboard <mapping> Specify a different keyboard layout as
  195. default for the LiveCD.
  196. (default: $o_keyboard)
  197. --resolution <res> Specify the resolution for the framebuffer
  198. output device. (Either resolution or normal)
  199. (default: $o_resolution)
  200. --splash <silent|verbose|no> Create the LiveCD with bootsplash support if
  201. available on the root filesystem.
  202. (default: $o_splash)
  203. --fstab <options> Override the default options for the fstab on
  204. the LiveCD. Options are one or more of 'auto'
  205. and 'rw', for example '--fstab=rw,auto' will
  206. automatically mount all detected partitions
  207. rw.
  208.  
  209. ISO Image options:
  210. --isoextrafiles <path> Add the files in 'path' to the root of the
  211. LiveCD ISO image.
  212. --application <id> Use the specified iso application ID, as '-A'
  213. option to genisoimage.
  214. --volumeid <id> Use the specified iso volume ID, as a '-V'
  215. option to genisoimage.
  216. --preparer <prep> Use the specified preparer ID, as a '-p'
  217. option to genisoimage.
  218. --publisher <pub> Use the specified publisher ID, as a '-P'
  219. option to genisoimage.
  220. --md5sum Compute and implant the md5sum to verify media.
  221.  
  222. Behaviour:
  223. --usbhome Use USB memory stick devices as a persistent
  224. home when available/connected on bootup.
  225.  
  226. Examples:
  227. $0 --nodir ^/usr/src/RPM,^/root/tmp livecd.iso
  228. $0 --splash=silent livecd.iso
  229.  
  230. ";
  231. exit(1);
  232. }
  233.  
  234.  
  235. ### format an elapsed time
  236. sub fmt_elapsed {
  237. my ($t) = @_;
  238. my $h = int($t/3600);
  239. my $m = int(($t - $h*3600)/60);
  240. my $s = int($t - $h*3600 - $m*60);
  241. sprintf("%02d:%02d:%02d", $h, $m, $s);
  242. }
  243.  
  244.  
  245. ### format a number
  246. sub fmt_number {
  247. my ($n) = @_;
  248. $n = $n/1000;
  249. my $t = int($n/1000);
  250. my $h = $n - $t*1000;
  251. my $r = sprintf("%0.3f", $h);
  252. $r =~ s/[.]/,/;
  253. if ($t > 0) {
  254. $r = "0$r" while (length($r) < 7);
  255. $r = "$t,$r";
  256. }
  257. $r;
  258. }
  259.  
  260. ### progress bar globals
  261. my $PROGRESS_MAX = 76;
  262. my $progress_max : shared = 0;
  263. my $progress_inc : shared = 0;
  264. my $progress_curr : shared = 0;
  265. my $progress_start : shared = 0;
  266. my $progress_tot : shared = 0;
  267. my $progress_text : shared = undef;
  268. my $progress_ttext : shared = undef;
  269. my $progress_timer : shared = -1; # 0 to active, -1 to deactivate
  270. my $progress_last : shared = 0;
  271.  
  272. ### to be called before we use the progress bar
  273. sub start_progress {
  274. my ($title, $max) = @_;
  275. my $i = 0;
  276. $| = 1;
  277. print $title.":\n";
  278. print "[";
  279. print " " while ($i++ < $PROGRESS_MAX);
  280. print "]";
  281. $progress_max = $max;
  282. $progress_inc = $progress_max/$PROGRESS_MAX;
  283. $progress_start = time;
  284. $progress_curr = 0;
  285. $progress_tot = 0;
  286. $progress_text = undef;
  287. $progress_ttext = undef;
  288. $progress_last = 0;
  289. print $ESC."1A".$ESC."52G";
  290. print "[ 0.00% ".fmt_elapsed(0)."/".fmt_elapsed(0)."]";
  291. start_thread();
  292. }
  293.  
  294.  
  295. ### while we are progressing
  296. sub set_progress {
  297. my ($curr, $text, $thr) = @_;
  298. $progress_last = $curr;
  299. $progress_last = $progress_max if ($progress_last > $progress_max);
  300. my $num = int($progress_last/$progress_inc) - $progress_curr;
  301. if (defined($opts{verbose}) && defined($text)) {
  302. $text =~ s/\[//g;
  303. $text =~ s/\]//g;
  304. $text =~ s/\+//g;
  305. # if (!defined($progress_text) || !($text =~ m/^$progress_text$/)) {
  306. if (!defined($progress_text) || ($text ne $progress_text)) {
  307. if (defined($thr) || ($progress_timer == -1)) {
  308. $progress_text = $text;
  309. $progress_ttext = $text;
  310. print "\n";
  311. $progress_curr += $num;
  312. print $ESC."1G";
  313. chomp($text);
  314. $text =~ s#\r?\n# #gs; # remove newlines in text
  315. if (length($text) > 72) {
  316. print " ".pack("A72", $text)." ...";
  317. }
  318. else {
  319. print " ".pack("A76",$text);
  320. }
  321. print $ESC."1A";
  322. }
  323. else {
  324. $progress_ttext = $text;
  325. }
  326. }
  327. }
  328. elsif ($num) {
  329. if (defined($thr) || ($progress_timer == -1)) {
  330. print "\n";
  331. my $col = 2+$progress_curr;
  332. $progress_curr += $num;
  333. print $ESC.$col."G";
  334. print "=" while ($num--);
  335. print $ESC."1A";
  336. }
  337. }
  338.  
  339. if (defined($thr) || ($progress_timer == -1)) {
  340. my $elapsed = time - $progress_start;
  341. my $remain = 0;
  342. if ($progress_curr < $PROGRESS_MAX) {
  343. $remain = $progress_curr ? ($elapsed/$progress_curr)*($PROGRESS_MAX - $progress_curr) : 0;
  344. }
  345. print $ESC."52G";
  346. print sprintf("[%6.2f%% ", $curr*100/$progress_max);
  347. print fmt_elapsed($elapsed)."/".fmt_elapsed($remain+$elapsed)."]";
  348. }
  349. }
  350.  
  351.  
  352. ### to close off the progress bar
  353. sub end_progress {
  354. end_thread();
  355. set_progress($progress_max, $progress_text);
  356. print "\n";
  357. my $i = -2;
  358. print " " while ($i++ < $PROGRESS_MAX);
  359. print $ESC."1G";
  360. }
  361.  
  362.  
  363. ### this is our timer thingy
  364. sub timer_progress {
  365. while (($progress_timer > 0) && ($progress_timer < 2)) {
  366. set_progress($progress_last, $progress_ttext, 1);
  367. sleep(1);
  368. }
  369. $progress_timer = 0;
  370. }
  371.  
  372.  
  373. ### start the progress thread
  374. sub start_thread {
  375. if ($progress_timer > -1) {
  376. $progress_timer = 1;
  377. threads->new(\&timer_progress);
  378. }
  379. }
  380.  
  381.  
  382. ### end the progress thread
  383. sub end_thread {
  384. if ($progress_timer > -1) {
  385. $progress_timer = 2;
  386. sleep(2) if ($progress_timer > 0);
  387. }
  388. }
  389.  
  390. ### parse the command-line options
  391. sub parse_options {
  392. GetOptions(\%opts,
  393. 'help',
  394. 'verbose+',
  395. 'noclean',
  396. 'workdir=s',
  397. 'debug',
  398. 'root=s',
  399. 'tmp=s',
  400. 'img=s',
  401. 'nofile=s@',
  402. 'nodir=s@',
  403. 'sort=s',
  404. 'kernel=s',
  405. 'lowmem',
  406. 'bootopt=s@',
  407. 'bootmsg=s',
  408. 'bootkey=s%',
  409. 'bootimg=s',
  410. 'timeout=i',
  411. 'noprompt',
  412. 'keyboard=s',
  413. 'resolution=s',
  414. 'splash=s',
  415. 'fstab=s',
  416. 'isoextrafiles=s',
  417. 'application=s',
  418. 'volumeid=s',
  419. 'preparer=s',
  420. 'publisher=s',
  421. 'bootloader=s',
  422. 'mbkopt=s',
  423. 'mbkopt_label=s',
  424. 'bootmenu=s',
  425. 'boottheme=s',
  426. 'bootlang=s',
  427. 'ufs=s',
  428. 'md5sum',
  429. 'lzma',
  430. 'gzip',
  431. 'xz',
  432. 'usbhome'
  433. );
  434.  
  435. # help and stuff
  436. print_usage if (defined($opts{help}));
  437.  
  438. # mandatory stuff
  439. $o_root =~ s|/$||;
  440. $o_root .= "/";
  441. die_("\nFATAL: Root directory (--root) '$o_root' does not exist\n") unless (-d $o_root);
  442. $o_tmp =~ s|/$||;
  443. $o_tmp .= "/";
  444. $o_stage2 = get_exec("find $o_root/lib -name stage2_eltorito");
  445. die_("\nFATAL: Temporary directory (--tmp) '$o_tmp' does not exist\n") unless (-d $o_tmp);
  446.  
  447. # optional stuff
  448. die_("\nFATAL: Specified sort file (--sort) '".$opts{sort}."' does not exist\n") if (defined($opts{sort}) && !(-f $opts{sort}));
  449. die_("\nFATAL: Kernel (--kernel) '".$o_kernel."' not installed on the root image. (Directory '".$o_root."/lib/modules/".$o_kernel."' does not exist.)\n") if (!(-d $o_root."/lib/modules/".$o_kernel));
  450. die_("\nFATAL: Extra ISO directory (--isoextrafiles) '".$opts{isoextrafiles}."' does not exist\n") if (defined($opts{isoextrafiles}) && !(-d $opts{isoextrafiles}));
  451. die_("\nFATAL: Unknown splash (--splash) option '$o_splash'\n") unless ($o_splash =~ /silent|verbose|no/);
  452. die_("\nFATAL: Work directory (--workdir) '".$opts{workdir}."' does not exist\n") if (defined($opts{workdir}) && !(-d $opts{workdir}));
  453.  
  454. # final iso name
  455. if (scalar(@ARGV) > 0) {
  456. die_("\nFATAL: Too many command-line arguments\n") if (scalar(@ARGV) > 1);
  457. $finaliso = $ARGV[0];
  458. }
  459. else {
  460. #die_("\nFATAL: No final iso name specified\nUse --help for usage\n");
  461. $finaliso = "livecd.iso";
  462. }
  463.  
  464. # set some options
  465. my $rhr = "$o_root/etc/redhat-release";
  466. my $distro = (-f $rhr) ? get_exec("gawk -F' ' '{ print \$1 \" \" \$2 }' $rhr") : "$PROG_NAME";
  467. my $version = (-f $rhr) ? get_exec("gawk -F' ' '{ print \$4 \" \" \$5 }' $rhr") : "$PROG_VERSION";
  468. my $date = get_exec("date +\%Y\%m\%d\%R");
  469. $opts{volumeid} = "livecd $date" unless (defined($opts{volumeid}));
  470. $opts{application} = "$distro $version LiveCD" unless (defined($opts{application}));
  471. $opts{preparer} = "$PROG_NAME $PROG_VERSION" unless (defined($opts{preparer}));
  472. $opts{publisher} = "$URL" unless (defined($opts{publisher}));
  473. $opts{boottheme} = "PCLinuxOS" unless (defined($opts{boottheme}));
  474. $opts{bootlang} = "en" unless (defined($opts{bootlang}));
  475.  
  476. # create our working dir if none given
  477. if ($opts{workdir}) {
  478. $workdir = $opts{workdir};
  479. $opts{noclean} = 1;
  480. } else {
  481. $workdir = $o_tmp."mylivecd.$$";
  482. }
  483. mkdir_p($workdir);
  484. die_("\nFATAL: Unable to create working directory, '$workdir'\n") unless (-e $workdir);
  485. print STDERR "\nWARNING: The temporary directory '$workdir' will not be removed at exit, please do so manually" if (defined($opts{noclean}));
  486.  
  487. # massage where we might have options csv
  488. @{$opts{nofile}} = split(/,/, join(',', @{$opts{nofile}})) if (defined($opts{nofile}));
  489. push @{$opts{nofile}}, split(/ /, $nofiles);
  490. @{$opts{nodir}} = split(/,/, join(',', @{$opts{nodir}})) if (defined($opts{nodir}));
  491. push @{$opts{nodir}}, split(/ /, $nodirs);
  492.  
  493. # setup executables
  494.  
  495. $loopcmp = "/usr/bin/mksquashfs";
  496. $loopmod = "squashfs";
  497.  
  498. # do other things before starting
  499. check_kernel();
  500. check_dietlibc();
  501. check_resolution();
  502. check_root();
  503. check_apps();
  504. check_services();
  505. # pretty up
  506. print "\n\n";
  507. }
  508.  
  509.  
  510. ### check for the kernel version
  511. sub check_kernel {
  512. # this should really be perl regex's
  513.  
  514. $kernel26 = 1;
  515. $modfile = "/etc/modprobe.conf";
  516. $depmod = "/sbin/depmod";
  517.  
  518. # check for identical kernels
  519. if ($o_kernel eq $o_mbkopt) {
  520. print "\n";
  521. print "\nThe LiveCD kernel and multi boot kernel are identical.\n";
  522. print "Please choose another kernel or use the --kernel option.\n";
  523. print "\n";
  524. cleanup ();
  525. exit (1);
  526. }
  527. }
  528.  
  529.  
  530. ### checks if this is a MDK dietlibc architecture
  531. sub check_dietlibc {
  532. my $arch = get_exec("uname -m");
  533. $dietarch = 1 if ($arch =~ m/i.86|x86_64/);
  534. }
  535.  
  536.  
  537. ### checks the resolution given
  538. sub check_resolution {
  539. if ($o_resolution =~ m/^normal/) {
  540. $o_vgamode = "normal";
  541. $o_splash = "no";
  542. }
  543. elsif ($o_resolution =~ m/^640x480/) {
  544. $o_vgamode = 785;
  545. }
  546. elsif ($o_resolution =~ m/^800x600/) {
  547. $o_vgamode = 788;
  548. }
  549. elsif ($o_resolution =~ m/^1024x768/) {
  550. $o_vgamode = 791;
  551. }
  552. elsif ($o_resolution =~ m/^1280x1024/) {
  553. $o_vgamode = 794;
  554. }
  555. elsif ($o_resolution =~ m/^1600x1200/) {
  556. $o_vgamode = 797;
  557. }
  558. else {
  559. die_("\nFATAL: Invalid resolution '$o_resolution' specified with '--resolution' option
  560. Valid resolutions are:
  561. normal
  562. 640x480
  563. 800x600
  564. 1024x768
  565. 1280x1024
  566. 1600x1200\n");
  567. }
  568. }
  569.  
  570.  
  571. ### see if we are indeed root
  572. sub check_root {
  573. die_("\nFATAL: You have to be root to execute this program\n") if ($> > 0);
  574. }
  575.  
  576.  
  577. ### see if we are indeed root
  578. sub check_apps {
  579. die_("\nFATAL: The 'genisoimage' program is not available, please install the cdrkit-genisoimage package\n") unless (-f '/usr/bin/genisoimage');
  580. die_("\nFATAL: The 'md5sum' program is not available, please install the coreutils package\n") unless (-f '/usr/bin/md5sum');
  581. die_("\nFATAL: The 'draklive-install' program is not available, please install the draklive-install package\n") unless (-f '/usr/sbin/draklive-install');
  582. if (($o_bootloader =~m/^grub/) && ($o_stage2 eq '')) {
  583. die("\nFATAL: The Grub program is not available, please install the correct package\n")
  584. }
  585. die_("\nFATAL: The '$loopcmp' program is not available, please install the correct package\n") unless (!defined($loopcmp) || -f $loopcmp);
  586. }
  587.  
  588. sub check_services {
  589. my $eachserv='';
  590. # disable some services
  591. print STDERR "\nDisabling Services not needed on the LiveCD\n\n";
  592. foreach $eachserv ('atd','crond','syslog','kheader','xinetd'){
  593. (push(@services,$eachserv) and services::do_not_start_service_on_boot($eachserv)) if (services::starts_on_boot($eachserv));
  594. }
  595. }
  596.  
  597.  
  598. ### execute a command
  599. sub do_cmd {
  600. my ($cmd, $prog) = @_;
  601. set_progress($prog-1, $cmd) if (defined($prog));
  602. system($cmd) and die_("\nFATAL: Execution of '$cmd' failed\n");
  603. set_progress($prog, $cmd) if (defined($prog));
  604. }
  605.  
  606.  
  607. ### copy a file
  608. sub do_copy {
  609. my ($src, $mode, $dest, $prog) = @_;
  610. my $cmd = ($mode > 0) ? "install -m $mode $src $dest" : "cp -aL $src $dest";
  611. set_progress($prog-1, $cmd) if (defined($prog));
  612. system($cmd);
  613. set_progress($prog, $cmd) if (defined($prog));
  614. }
  615.  
  616.  
  617. ### create an initrd image
  618. sub create_initrd {
  619. # get our modules
  620. $modules = $modules_26;
  621. $modules_opt = $modules_opt_26;
  622. my @allmods = split(/ /, $modules);
  623. push @allmods, $loopmod if (defined($loopmod));
  624. push @allmods, $o_ufs;
  625. my @allmods_opt = split(/ /, $modules_opt);
  626.  
  627. # start progress bar
  628. my $pos = 0;
  629. if ($o_mbkopt ne "") {
  630. start_progress("Creating $o_kernel initrd", 121+scalar(@allmods));
  631. } else {
  632. start_progress("Creating initrd", 121+scalar(@allmods));
  633. }
  634.  
  635. # create directories
  636. my $dir = $workdir."/initrd.dir";
  637. mkdir_p("$dir/$_") foreach "lib/modules/$o_kernel/kernel/drivers", "lib/modules/$o_kernel/kernel/fs", "lib/modules/$o_kernel/kernel/lib", qw(bin sbin usr/bin usr/sbin dev etc/sysconfig etc/rc.d/ etc/profile.d proc sys ramfs usr/lib usr/share/ldetect-lst lib/module-init-tools cdrom loopfs tmp ramfs usr/share/icons/large usr/share/plymouth/themes usr/share/plymouth/themes/details usr/share/plymouth/themes/text usr/share/plymouth/themes/PCLinuxOS usr/lib/plymouth usr/lib/plymouth/renderers /etc/plymouth);
  638. set_progress(++$pos, "mkdir -p $dir/...");
  639.  
  640. # copy files
  641. do_copy($o_root."usr/bin/busybox", 755, "$dir/bin/busybox", ++$pos);
  642. do_copy($o_root."sbin/nash", 755, "$dir/bin/nash", ++$pos);
  643. do_copy($o_root."usr/lib/drakx-installer-binaries/probe-modules", 755, "$dir/bin/probe-modules", ++$pos);
  644. do_copy($o_root."usr/share/mylivecd/linuxrc", 755, "$dir/linuxrc", ++$pos);
  645. do_copy($o_root."usr/share/mylivecd/rc.sysinit", 755, "$dir/etc/rc.d/rc.sysinit", ++$pos);
  646.  
  647. if ($o_ufs =~ m/^unionfs/) {
  648. do_cmd("perl -pi -e 's/aufs/unionfs/' $dir/linuxrc");
  649. do_cmd("perl -pi -e 's/AUFS/UNIONFS/' $dir/etc/rc.d/rc.sysinit");
  650. do_cmd("perl -pi -e 's/aufs/unionfs/' $dir/etc/rc.d/rc.sysinit");
  651. do_cmd("perl -pi -e 's/ro none/ro unionfs/' $dir/etc/rc.d/rc.sysinit");
  652. }
  653.  
  654. # copy core library files
  655. do_copy($o_root."usr/share/mylivecd/halt.local", 755, "$dir/sbin/halt.local", ++$pos);
  656. do_copy($o_root."etc/inittab", 644, "$dir/etc/inittab", ++$pos);
  657. do_copy($o_root."etc/pclinuxos-release", 644, "$dir/etc/pclinuxos-release", ++$pos);
  658. do_copy($o_root."sbin/init", 755, "$dir/sbin/init.dynamic", ++$pos);
  659. do_copy($o_root."lib/libc.so.6", 0, "$dir/lib", ++$pos);
  660. do_copy($o_root."lib/ld-linux.so.2", 0, "$dir/lib", ++$pos);
  661. do_copy($o_root."lib/libpopt.so.0", 0, "$dir/lib", ++$pos);
  662. do_copy($o_root."lib/libdl.so.2", 0, "$dir/lib", ++$pos);
  663. do_copy($o_root."lib/libm.so.6", 0, "$dir/lib", ++$pos);
  664. do_copy($o_root."lib/libdevmapper.so.1.02", 0, "$dir/lib", ++$pos);
  665. do_copy($o_root."lib/libncurses.so.5", 0, "$dir/lib", ++$pos);
  666. do_copy($o_root."lib/libgcc_s.so.1", 0, "$dir/lib", ++$pos);
  667. do_copy($o_root."lib/libblkid.so.1", 0, "$dir/lib", ++$pos);
  668. do_copy($o_root."lib/libresolv.so.2", 0, "$dir/lib", ++$pos);
  669. do_copy($o_root."lib/i686/libpthread.so.0", 755, "$dir/lib", ++$pos);
  670. do_copy($o_root."lib/i686/libpthread-2.13.so", 755, "$dir/lib", ++$pos);
  671. do_copy($o_root."lib/libreadline.so.5", 0, "$dir/lib", ++$pos);
  672. do_copy($o_root."lib/i686/librt-2.13.so", 755, "$dir/lib", ++$pos);
  673. do_copy($o_root."lib/i686/librt.so.1", 755, "$dir/lib", ++$pos);
  674. do_copy($o_root."usr/lib/libnash.so.6.0.93", 0, "$dir/lib", ++$pos);
  675. do_copy($o_root."usr/lib/libparted.so.0", 0, "$dir/lib", ++$pos);
  676. do_copy($o_root."usr/lib/libbdevid.so.6.0.93", 0, "$dir/lib", ++$pos);
  677. do_copy($o_root."usr/lib/libelf.so.1", 0, "$dir/lib", ++$pos);
  678. do_copy($o_root."lib/libz.so.1", 0, "$dir/lib", ++$pos);
  679. do_copy($o_root."lib/libz.so.1.2.5", 0, "$dir/lib", ++$pos);
  680. do_copy($o_root."usr/lib/libpng12.so.0", 0, "$dir/usr/lib", ++$pos);
  681. do_copy($o_root."usr/lib/libpng12.so.0.47.0", 0, "$dir/usr/lib", ++$pos);
  682. do_copy($o_root."usr/lib/libpng.so.3", 0, "$dir/usr/lib", ++$pos);
  683. do_copy($o_root."usr/lib/libpng.so.3.47.0", 0, "$dir/usr/lib", ++$pos);
  684.  
  685. # udev library files
  686. do_copy($o_root."lib/libudev.so.0", 0, "$dir/lib", ++$pos);
  687. if ( -e "$o_root/lib/libudev.so.0.8.2" ) {
  688. do_copy($o_root."lib/libudev.so.0.8.2", 0, "$dir/lib", ++$pos);
  689. }
  690. if ( -e "$o_root/lib/libudev.so.0.10.0" ) {
  691. do_copy($o_root."lib/libudev.so.0.10.0", 0, "$dir/lib", ++$pos);
  692. }
  693. if ( -e "$o_root/lib/libudev.so.0.9.3" ) {
  694. do_copy($o_root."lib/libudev.so.0.9.3", 0, "$dir/lib", ++$pos);
  695. }
  696.  
  697. # Bootsplash Libs
  698. do_copy($o_root."lib/libply-splash-core.so.2", 0, "$dir/lib", ++$pos);
  699. do_copy($o_root."lib/libply-splash-core.so.2.0.0", 0, "$dir/lib", ++$pos);
  700. do_copy($o_root."lib/libply.so.2", 0, "$dir/lib", ++$pos);
  701. do_copy($o_root."lib/libply.so.2.0.0", 0, "$dir/lib", ++$pos);
  702.  
  703.  
  704. # Bootsplash files
  705. do_copy($o_root."sbin/plymouthd", 755, "$dir/bin/plymouthd", ++$pos);
  706. do_copy($o_root."usr/bin/plymouth", 755, "$dir/bin/plymouth", ++$pos);
  707. do_copy($o_root."usr/lib/plymouth/details.so", 0, "$dir/usr/lib/plymouth", ++$pos);
  708. do_copy($o_root."usr/lib/plymouth/script.so", 0, "$dir/usr/lib/plymouth", ++$pos);
  709. do_copy($o_root."usr/lib/plymouth/text.so", 0, "$dir/usr/lib/plymouth", ++$pos);
  710. do_copy($o_root."usr/share/plymouth/*", 0, "$dir/usr/share/plymouth", ++$pos);
  711. do_copy($o_root."usr/share/icons/large/pclinuxos.png", 0, "$dir/usr/share/icons/large", ++$pos);
  712.  
  713. do_copy($o_root."etc/plymouth/plymouthd.conf", 0, "$dir/etc/plymouth", ++$pos);
  714.  
  715. # Plymouth dependency library files
  716. do_copy($o_root."usr/lib/libply-boot-client.so.2", 0, "$dir/usr/lib", ++$pos);
  717. do_copy($o_root."usr/lib/libply-boot-client.so.2.0.0", 0, "$dir/usr/lib", ++$pos);
  718. do_copy($o_root."usr/lib/libply-splash-graphics.so.2", 0, "$dir/usr/lib", ++$pos);
  719. do_copy($o_root."usr/lib/libply-splash-graphics.so.2.0.0", 0, "$dir/usr/lib", ++$pos);
  720.  
  721. do_copy($o_root."usr/lib/plymouth/renderers/drm.so", 0, "$dir/usr/lib/plymouth/renderers", ++$pos);
  722. do_copy($o_root."usr/lib/plymouth/renderers/frame-buffer.so", 0, "$dir/usr/lib/plymouth/renderers", ++$pos);
  723. do_copy($o_root."usr/lib/plymouth/renderers/x11.so", 0, "$dir/usr/lib/plymouth/renderers", ++$pos);
  724.  
  725.  
  726. # Kernel stuff
  727. do_copy($o_root."lib/module-init-tools/ldetect-lst-modules.alias", 0, "$dir/lib/module-init-tools", ++$pos);
  728.  
  729. # Hardware detection stuff
  730. do_copy($o_root."usr/share/pci.ids", 0, "$dir/usr/share", ++$pos);
  731. do_copy($o_root."usr/share/usb.ids", 0, "$dir/usr/share", ++$pos);
  732. do_copy($o_root."usr/share/ldetect-lst/fallback-modules.alias", 0, "$dir/usr/share/ldetect-lst", ++$pos);
  733. do_copy($o_root."usr/share/ldetect-lst/pcitable.gz", 644, "$dir/usr/share/ldetect-lst", ++$pos);
  734. do_copy($o_root."usr/share/ldetect-lst/usbtable.gz", 644, "$dir/usr/share/ldetect-lst", ++$pos);
  735.  
  736. # Copy but hide the udev binaries
  737. do_cmd("mkdir -p $dir/sbin/tmp", ++$pos);
  738. do_copy($o_root."/sbin/udev*", 755, "$dir/sbin/tmp", ++$pos);
  739. do_copy($o_root."/sbin/start_udev", 755, "$dir/sbin/tmp", ++$pos);
  740. do_cmd("cp -a $o_root/etc/udev $dir/etc", ++$pos);
  741. if (-e "$o_root/etc/dev.d") {
  742. do_cmd("cp -a $o_root/etc/dev.d $dir/etc", ++$pos);
  743. }
  744. do_cmd("cp -a $o_root/etc/hotplug $dir/etc", ++$pos);
  745. do_cmd("cp -a $o_root/etc/sysconfig $dir/etc", ++$pos);
  746.  
  747. do_cmd("mknod $dir/dev/initrd b 1 250", ++$pos);
  748. do_cmd("mknod $dir/dev/console c 5 1", ++$pos);
  749. do_cmd("mknod $dir/dev/fb c 29 0", ++$pos);
  750. do_cmd("mknod $dir/dev/null c 1 3", ++$pos);
  751. do_cmd("mknod $dir/dev/systty c 4 0", ++$pos);
  752. do_cmd("mknod $dir/dev/ram b 1 1", ++$pos);
  753. do_cmd("mknod $dir/dev/tty$_ c 4 $_", ++$pos) foreach((0,1,2,3,4,5,6,7,8,9,10,11,12));
  754. do_cmd("mknod $dir/dev/ttyS0 c 4 64", ++$pos);
  755. do_cmd("mknod $dir/dev/ttyS1 c 4 65", ++$pos);
  756. do_cmd("mknod $dir/dev/ttyS2 c 4 66", ++$pos);
  757. do_cmd("mknod $dir/dev/ttyS3 c 4 67", ++$pos);
  758. do_cmd("mknod $dir/dev/lvm b 109 0", ++$pos);
  759.  
  760. # Copy specific kernel drivers for linuxrc
  761. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/ata $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  762. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/block $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  763. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/ide $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  764. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/message $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  765. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/parport $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  766. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/pcmcia $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  767. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/scsi $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  768. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/usb $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  769. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/uwb $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  770. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/cdrom $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  771. if (-e "$o_root/lib/modules/$o_kernel/kernel/drivers/ieee1394") {
  772. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/drivers/ieee1394 $dir/lib/modules/$o_kernel/kernel/drivers", ++$pos);
  773. }
  774. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/fs/ext4 $dir/lib/modules/$o_kernel/kernel/fs", ++$pos);
  775. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/fs/jbd2 $dir/lib/modules/$o_kernel/kernel/fs", ++$pos);
  776. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/fs/fat $dir/lib/modules/$o_kernel/kernel/fs", ++$pos);
  777. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/fs/isofs $dir/lib/modules/$o_kernel/kernel/fs", ++$pos);
  778. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/fs/nls $dir/lib/modules/$o_kernel/kernel/fs", ++$pos);
  779. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/fs/squashfs $dir/lib/modules/$o_kernel/kernel/fs", ++$pos);
  780. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/fs/unionfs $dir/lib/modules/$o_kernel/kernel/fs", ++$pos);
  781. if ( -e "$o_root/lib/modules/$o_kernel/kernel/fs/aufs" ) {
  782. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/fs/aufs $dir/lib/modules/$o_kernel/kernel/fs", ++$pos);
  783. }
  784. do_cmd("cp -r $o_root/lib/modules/$o_kernel/kernel/lib $dir/lib/modules/$o_kernel/kernel", ++$pos);
  785.  
  786. # Generate modules file
  787. do_cmd(":>$dir$modfile", ++$pos);
  788. my $cfg = defined($kernel26) ? "" : "--config $dir$modfile";
  789. do_cmd("(depmod -a --basedir $dir ".$cfg." $o_kernel) 2>/dev/null", ++$pos);
  790.  
  791. # get sizes$o_kernel
  792. my $size = get_exec("du -ks $dir | awk '{print \$1}'");
  793. $size = $size + 250;
  794. set_progress(++$pos, "du -ks $dir");
  795.  
  796. # number of inodes
  797. my $inodes = 1250;
  798. my $num = get_exec("find $dir | wc -l");
  799. $inodes = $inodes + $num;
  800. $size = int($size + ($inodes / 10)) + 1; # 10 inodes needs 1K
  801. set_progress(++$pos, "find $dir | wc -l");
  802.  
  803. # do magic
  804. my $initrd = "$workdir/livecd/isolinux/initrd";
  805. my $mnt = "$workdir/initrd.mnt";
  806. do_cmd("mkdir -p $workdir/livecd/isolinux", ++$pos);
  807. do_cmd("mkdir -p $workdir/livecd/boot/grub", ++$pos);
  808. do_cmd("dd if=/dev/zero of=$initrd bs=1k count=$size 2> /dev/null", ++$pos);
  809. do_cmd("mke2fs -q -m 0 -F -N $inodes -s 1 $initrd", ++$pos);
  810. do_cmd("mkdir -p $mnt ; mount -o loop -t ext2 $initrd $mnt", ++$pos);
  811. do_cmd("rm -rf $mnt/lost+found", ++$pos);
  812. do_cmd("(cd $dir ; tar cf - .) | (cd $mnt ; tar xf -)", ++$pos);
  813. do_cmd("umount $mnt", ++$pos);
  814. do_cmd("(cd $workdir/livecd/isolinux ; gzip -9 initrd)", ++$pos);
  815.  
  816. # make splash
  817. if (($o_splash !~ m/no/) && ($o_root =~ m/union/)) {
  818. if (-e "/tmp/bootsplash/scripts/make-boot-splash") {
  819. do_cmd("rm -rf /tmp/bootsplash");
  820. }
  821. do_cmd("mkdir -p /tmp/bootsplash");
  822. do_cmd("cp -r /usr/share/bootsplash/scripts /tmp/bootsplash");
  823. do_cmd("perl -pi -e 's#usr/share/bootsplash#tmp/bootsplash#' /tmp/bootsplash/scripts/make-boot-splash");
  824. do_cmd("perl -pi -e 's#usr/share/bootsplash#tmp/bootsplash#' /tmp/bootsplash/scripts/make-boot-splash-raw");
  825. do_cmd("perl -pi -e 's/^warn/#warn/' /tmp/bootsplash/scripts/remove-boot-splash");
  826.  
  827. do_cmd("mv -f $initrd.gz /tmp ; \
  828. /tmp/bootsplash/scripts/make-boot-splash-raw /tmp/initrd.gz $o_theme; \
  829. mv -f /tmp/initrd.gz $workdir/livecd/isolinux", ++$pos);
  830.  
  831. }
  832.  
  833. # we are done
  834. end_progress();
  835.  
  836.  
  837. }
  838.  
  839.  
  840. ## check for legacy kernel and create initrd2
  841. sub create_initrd2 {
  842. if ($o_mbkopt ne "" && -d "/lib/modules/$o_mbkopt") {
  843. # get our modules
  844. $modules = $modules_26;
  845. $modules_opt = $modules_opt_26;
  846. my @allmods = split(/ /, $modules);
  847. push @allmods, $loopmod if (defined($loopmod));
  848. push @allmods, $o_ufs;
  849. my @allmods_opt = split(/ /, $modules_opt);
  850.  
  851. # start progress bar
  852. my $pos = 0;
  853. start_progress("Creating $o_mbkopt initrd", 121+scalar(@allmods));
  854.  
  855. # create directories
  856. my $dir = $workdir."/initrd2.dir";
  857. mkdir_p("$dir/$_") foreach "lib/modules/$o_mbkopt/kernel/drivers", "lib/modules/$o_mbkopt/kernel/fs", "lib/modules/$o_mbkopt/kernel/lib", qw(bin sbin usr/bin usr/sbin dev etc/sysconfig etc/rc.d/ etc/profile.d proc sys ramfs usr/lib usr/share/ldetect-lst lib/module-init-tools cdrom loopfs tmp ramfs usr/share/icons/large usr/share/plymouth/themes usr/share/plymouth/themes/details usr/share/plymouth/themes/text usr/share/plymouth/themes/PCLinuxOS usr/lib/plymouth usr/lib/plymouth/renderers /etc/plymouth);
  858. set_progress(++$pos, "mkdir -p $dir/...");
  859.  
  860. # copy files
  861. do_copy($o_root."usr/bin/busybox", 755, "$dir/bin/busybox", ++$pos);
  862. do_copy($o_root."sbin/nash", 755, "$dir/bin/nash", ++$pos);
  863. do_copy($o_root."usr/lib/drakx-installer-binaries/probe-modules", 755, "$dir/bin/probe-modules", ++$pos);
  864. do_copy($o_root."usr/share/mylivecd/linuxrc", 755, "$dir/linuxrc", ++$pos);
  865. do_copy($o_root."usr/share/mylivecd/rc.sysinit", 755, "$dir/etc/rc.d/rc.sysinit", ++$pos);
  866.  
  867. if ($o_ufs =~ m/^unionfs/) {
  868. do_cmd("perl -pi -e 's/aufs/unionfs/' $dir/linuxrc");
  869. do_cmd("perl -pi -e 's/AUFS/UNIONFS/' $dir/etc/rc.d/rc.sysinit");
  870. do_cmd("perl -pi -e 's/aufs/unionfs/' $dir/etc/rc.d/rc.sysinit");
  871. do_cmd("perl -pi -e 's/ro none/ro unionfs/' $dir/etc/rc.d/rc.sysinit");
  872. }
  873.  
  874. # copy core library files
  875. do_copy($o_root."usr/share/mylivecd/halt.local", 755, "$dir/sbin/halt.local", ++$pos);
  876. do_copy($o_root."etc/inittab", 644, "$dir/etc/inittab", ++$pos);
  877. do_copy($o_root."etc/pclinuxos-release", 644, "$dir/etc/pclinuxos-release", ++$pos);
  878. do_copy($o_root."sbin/init", 755, "$dir/sbin/init.dynamic", ++$pos);
  879. do_copy($o_root."lib/libc.so.6", 0, "$dir/lib", ++$pos);
  880. do_copy($o_root."lib/ld-linux.so.2", 0, "$dir/lib", ++$pos);
  881. do_copy($o_root."lib/libpopt.so.0", 0, "$dir/lib", ++$pos);
  882. do_copy($o_root."lib/libdl.so.2", 0, "$dir/lib", ++$pos);
  883. do_copy($o_root."lib/libm.so.6", 0, "$dir/lib", ++$pos);
  884. do_copy($o_root."lib/libdevmapper.so.1.02", 0, "$dir/lib", ++$pos);
  885. do_copy($o_root."lib/libncurses.so.5", 0, "$dir/lib", ++$pos);
  886. do_copy($o_root."lib/libgcc_s.so.1", 0, "$dir/lib", ++$pos);
  887. do_copy($o_root."lib/libblkid.so.1", 0, "$dir/lib", ++$pos);
  888. do_copy($o_root."lib/libresolv.so.2", 0, "$dir/lib", ++$pos);
  889. do_copy($o_root."lib/i686/libpthread.so.0", 755, "$dir/lib", ++$pos);
  890. do_copy($o_root."lib/i686/libpthread-2.13.so", 755, "$dir/lib", ++$pos);
  891. do_copy($o_root."lib/libreadline.so.5", 0, "$dir/lib", ++$pos);
  892. do_copy($o_root."lib/i686/librt-2.13.so", 755, "$dir/lib", ++$pos);
  893. do_copy($o_root."lib/i686/librt.so.1", 755, "$dir/lib", ++$pos);
  894. do_copy($o_root."usr/lib/libnash.so.6.0.93", 0, "$dir/lib", ++$pos);
  895. do_copy($o_root."usr/lib/libparted.so.0", 0, "$dir/lib", ++$pos);
  896. do_copy($o_root."usr/lib/libbdevid.so.6.0.93", 0, "$dir/lib", ++$pos);
  897. do_copy($o_root."usr/lib/libelf.so.1", 0, "$dir/lib", ++$pos);
  898. do_copy($o_root."lib/libz.so.1", 0, "$dir/lib", ++$pos);
  899. do_copy($o_root."lib/libz.so.1.2.5", 0, "$dir/lib", ++$pos);
  900. do_copy($o_root."usr/lib/libpng12.so.0", 0, "$dir/usr/lib", ++$pos);
  901. do_copy($o_root."usr/lib/libpng12.so.0.47.0", 0, "$dir/usr/lib", ++$pos);
  902. do_copy($o_root."usr/lib/libpng.so.3", 0, "$dir/usr/lib", ++$pos);
  903. do_copy($o_root."usr/lib/libpng.so.3.47.0", 0, "$dir/usr/lib", ++$pos);
  904.  
  905. # udev library files
  906. do_copy($o_root."lib/libudev.so.0", 0, "$dir/lib", ++$pos);
  907. if ( -e "$o_root/lib/libudev.so.0.8.2" ) {
  908. do_copy($o_root."lib/libudev.so.0.8.2", 0, "$dir/lib", ++$pos);
  909. }
  910. if ( -e "$o_root/lib/libudev.so.0.10.0" ) {
  911. do_copy($o_root."lib/libudev.so.0.10.0", 0, "$dir/lib", ++$pos);
  912. }
  913. if ( -e "$o_root/lib/libudev.so.0.9.3" ) {
  914. do_copy($o_root."lib/libudev.so.0.9.3", 0, "$dir/lib", ++$pos);
  915. }
  916.  
  917. # Bootsplash Libs
  918. do_copy($o_root."lib/libply-splash-core.so.2", 0, "$dir/lib", ++$pos);
  919. do_copy($o_root."lib/libply-splash-core.so.2.0.0", 0, "$dir/lib", ++$pos);
  920. do_copy($o_root."lib/libply.so.2", 0, "$dir/lib", ++$pos);
  921. do_copy($o_root."lib/libply.so.2.0.0", 0, "$dir/lib", ++$pos);
  922.  
  923. # Bootsplash files
  924. do_copy($o_root."sbin/plymouthd", 755, "$dir/bin/plymouthd", ++$pos);
  925. do_copy($o_root."usr/bin/plymouth", 755, "$dir/bin/plymouth", ++$pos);
  926. do_copy($o_root."usr/lib/plymouth/details.so", 0, "$dir/usr/lib/plymouth", ++$pos);
  927. do_copy($o_root."usr/lib/plymouth/script.so", 0, "$dir/usr/lib/plymouth", ++$pos);
  928. do_copy($o_root."usr/lib/plymouth/text.so", 0, "$dir/usr/lib/plymouth", ++$pos);
  929. do_copy($o_root."usr/share/plymouth/*", 0, "$dir/usr/share/plymouth", ++$pos);
  930. do_copy($o_root."usr/share/icons/large/pclinuxos.png", 0, "$dir/usr/share/icons/large", ++$pos);
  931.  
  932. do_copy($o_root."etc/plymouth/plymouthd.conf", 0, "$dir/etc/plymouth", ++$pos);
  933.  
  934. # Plymouth dependency library files
  935. do_copy($o_root."usr/lib/libply-boot-client.so.2", 0, "$dir/usr/lib", ++$pos);
  936. do_copy($o_root."usr/lib/libply-boot-client.so.2.0.0", 0, "$dir/usr/lib", ++$pos);
  937. do_copy($o_root."usr/lib/libply-splash-graphics.so.2", 0, "$dir/usr/lib", ++$pos);
  938. do_copy($o_root."usr/lib/libply-splash-graphics.so.2.0.0", 0, "$dir/usr/lib", ++$pos);
  939.  
  940. do_copy($o_root."usr/lib/plymouth/renderers/drm.so", 0, "$dir/usr/lib/plymouth/renderers", ++$pos);
  941. do_copy($o_root."usr/lib/plymouth/renderers/frame-buffer.so", 0, "$dir/usr/lib/plymouth/renderers", ++$pos);
  942. do_copy($o_root."usr/lib/plymouth/renderers/x11.so", 0, "$dir/usr/lib/plymouth/renderers", ++$pos);
  943.  
  944.  
  945. # Kernel stuff
  946. do_copy($o_root."lib/module-init-tools/ldetect-lst-modules.alias", 0, "$dir/lib/module-init-tools", ++$pos);
  947.  
  948. # Hardware detection stuff
  949. do_copy($o_root."usr/share/pci.ids", 0, "$dir/usr/share", ++$pos);
  950. do_copy($o_root."usr/share/usb.ids", 0, "$dir/usr/share", ++$pos);
  951. do_copy($o_root."usr/share/ldetect-lst/fallback-modules.alias", 0, "$dir/usr/share/ldetect-lst", ++$pos);
  952. do_copy($o_root."usr/share/ldetect-lst/pcitable.gz", 644, "$dir/usr/share/ldetect-lst", ++$pos);
  953. do_copy($o_root."usr/share/ldetect-lst/usbtable.gz", 644, "$dir/usr/share/ldetect-lst", ++$pos);
  954.  
  955. # Copy but hide the udev binaries
  956. do_cmd("mkdir -p $dir/sbin/tmp", ++$pos);
  957. do_copy($o_root."/sbin/udev*", 755, "$dir/sbin/tmp", ++$pos);
  958. do_copy($o_root."/sbin/start_udev", 755, "$dir/sbin/tmp", ++$pos);
  959. do_cmd("cp -a $o_root/etc/udev $dir/etc", ++$pos);
  960. if (-e "$o_root/etc/dev.d") {
  961. do_cmd("cp -a $o_root/etc/dev.d $dir/etc", ++$pos);
  962. }
  963. do_cmd("cp -a $o_root/etc/hotplug $dir/etc", ++$pos);
  964. do_cmd("cp -a $o_root/etc/sysconfig $dir/etc", ++$pos);
  965.  
  966. do_cmd("mknod $dir/dev/initrd b 1 250", ++$pos);
  967. do_cmd("mknod $dir/dev/console c 5 1", ++$pos);
  968. do_cmd("mknod $dir/dev/fb c 29 0", ++$pos);
  969. do_cmd("mknod $dir/dev/null c 1 3", ++$pos);
  970. do_cmd("mknod $dir/dev/systty c 4 0", ++$pos);
  971. do_cmd("mknod $dir/dev/ram b 1 1", ++$pos);
  972. do_cmd("mknod $dir/dev/tty$_ c 4 $_", ++$pos) foreach((0,1,2,3,4,5,6,7,8,9,10,11,12));
  973. do_cmd("mknod $dir/dev/ttyS0 c 4 64", ++$pos);
  974. do_cmd("mknod $dir/dev/ttyS1 c 4 65", ++$pos);
  975. do_cmd("mknod $dir/dev/ttyS2 c 4 66", ++$pos);
  976. do_cmd("mknod $dir/dev/ttyS3 c 4 67", ++$pos);
  977. do_cmd("mknod $dir/dev/lvm b 109 0", ++$pos);
  978.  
  979.  
  980. # Copy specific kernel drivers for linuxrc
  981. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/ata $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  982. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/block $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  983. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/ide $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  984. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/message $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  985. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/parport $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  986. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/pcmcia $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  987. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/scsi $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  988. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/usb $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  989. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/uwb $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  990. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/cdrom $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  991. if (-e "$o_root/lib/modules/$o_mbkopt/kernel/drivers/ieee1394") {
  992. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/drivers/ieee1394 $dir/lib/modules/$o_mbkopt/kernel/drivers", ++$pos);
  993. }
  994. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/fs/ext4 $dir/lib/modules/$o_mbkopt/kernel/fs", ++$pos);
  995. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/fs/jbd2 $dir/lib/modules/$o_mbkopt/kernel/fs", ++$pos);
  996. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/fs/fat $dir/lib/modules/$o_mbkopt/kernel/fs", ++$pos);
  997. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/fs/isofs $dir/lib/modules/$o_mbkopt/kernel/fs", ++$pos);
  998. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/fs/nls $dir/lib/modules/$o_mbkopt/kernel/fs", ++$pos);
  999. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/fs/squashfs $dir/lib/modules/$o_mbkopt/kernel/fs", ++$pos);
  1000. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/fs/unionfs $dir/lib/modules/$o_mbkopt/kernel/fs", ++$pos);
  1001. if ( -e "$o_root/lib/modules/$o_mbkopt/kernel/fs/aufs" ) {
  1002. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/fs/aufs $dir/lib/modules/$o_mbkopt/kernel/fs", ++$pos);
  1003. }
  1004.  
  1005. do_cmd("cp -r $o_root/lib/modules/$o_mbkopt/kernel/lib $dir/lib/modules/$o_mbkopt/kernel", ++$pos);
  1006.  
  1007. # generate modules file
  1008. do_cmd(":>$dir$modfile", ++$pos);
  1009. my $cfg = defined($kernel26) ? "" : "--config $dir$modfile";
  1010. do_cmd("(depmod -a --basedir $dir ".$cfg." $o_mbkopt) 2>/dev/null", ++$pos);
  1011.  
  1012. # get sizes$o_kernel
  1013. my $size = get_exec("du -ks $dir | awk '{print \$1}'");
  1014. $size = $size + 250;
  1015. set_progress(++$pos, "du -ks $dir");
  1016.  
  1017. # number of inodes
  1018. my $inodes = 1250;
  1019. my $num = get_exec("find $dir | wc -l");
  1020. $inodes = $inodes + $num;
  1021. $size = int($size + ($inodes / 10)) + 1; # 10 inodes needs 1K
  1022. set_progress(++$pos, "find $dir | wc -l");
  1023.  
  1024. # do magic
  1025. my $initrd2 = "$workdir/livecd/isolinux/initrd2";
  1026. my $mntlg = "$workdir/initrd2.mnt";
  1027. do_cmd("mkdir -p $workdir/livecd/isolinux", ++$pos);
  1028. do_cmd("mkdir -p $workdir/livecd/boot/grub", ++$pos);
  1029. do_cmd("dd if=/dev/zero of=$initrd2 bs=1k count=$size 2> /dev/null", ++$pos);
  1030. do_cmd("mke2fs -q -m 0 -F -N $inodes -s 1 $initrd2", ++$pos);
  1031. do_cmd("mkdir -p $mntlg ; mount -o loop -t ext2 $initrd2 $mntlg", ++$pos);
  1032. do_cmd("rm -rf $mntlg/lost+found", ++$pos);
  1033. do_cmd("(cd $dir ; tar cf - .) | (cd $mntlg ; tar xf -)", ++$pos);
  1034. do_cmd("umount $mntlg", ++$pos);
  1035. do_cmd("(cd $workdir/livecd/isolinux ; gzip -9 initrd2)", ++$pos);
  1036.  
  1037.  
  1038. # make splash
  1039. if (($o_splash !~ m/no/) && ($o_root =~ m/union/)) {
  1040. if (-e "/tmp/bootsplash/scripts/make-boot-splash") {
  1041. do_cmd("rm -rf /tmp/bootsplash");
  1042. }
  1043. do_cmd("mkdir -p /tmp/bootsplash");
  1044. do_cmd("cp -r /usr/share/bootsplash/scripts /tmp/bootsplash");
  1045. do_cmd("perl -pi -e 's#usr/share/bootsplash#tmp/bootsplash#' /tmp/bootsplash/scripts/make-boot-splash");
  1046. do_cmd("perl -pi -e 's#usr/share/bootsplash#tmp/bootsplash#' /tmp/bootsplash/scripts/make-boot-splash-raw");
  1047. do_cmd("perl -pi -e 's/^warn/#warn/' /tmp/bootsplash/scripts/remove-boot-splash");
  1048.  
  1049. do_cmd("mv -f $initrd2.gz /tmp ; \
  1050. /tmp/bootsplash/scripts/make-boot-splash-raw /tmp/initrd2.gz $o_theme; \
  1051. mv -f /tmp/initrd.gz $workdir/livecd/isolinux", ++$pos);
  1052.  
  1053. }
  1054.  
  1055. }
  1056. else {
  1057. print "\n";
  1058. print "The option --mbkopt $o_mbkopt was used.\n";
  1059. print "Is kernel $o_mbkopt installed?\n";
  1060. print "\n";
  1061. cleanup ();
  1062. exit (1);
  1063. }
  1064. # we are done
  1065. end_progress();
  1066. }
  1067.  
  1068.  
  1069. ### create the compressed image
  1070. sub create_compressed {
  1071. if (defined($opts{img}) && (-f $opts{img})) {
  1072. do_cmd("ln $opts{img} $workdir/livecd/livecd.$o_looptype");
  1073. }
  1074. else {
  1075. my $pos = 0;
  1076. start_progress("Setting filesystem parameters", 5);
  1077.  
  1078. # handle excludes
  1079. do_cmd(":>$workdir/excludes.list", ++$pos);
  1080. if (defined($opts{nodir})) {
  1081. my $ex = join("\n", @{$opts{nodir}});
  1082. do_cmd("(find $o_root -type d 2>/dev/null | sed -e 's,^$o_root,/,g' | grep '$ex' | sed 's,^/,$o_root,' >>$workdir/excludes.list)", ++$pos);
  1083.  
  1084. }
  1085. if (defined($opts{nofile})) {
  1086. my $ex = join("\n", @{$opts{nofile}});
  1087. do_cmd("(find $o_root -type f 2>/dev/null | sed -e 's,^$o_root,/,g' | grep '$ex' | sed 's,^/,$o_root,' >>$workdir/excludes.list)", ++$pos);
  1088. #work around to avoid excluding /etc/X11/xorg.conf.d
  1089. do_cmd("echo /etc/X11/xorg.conf >>$workdir/excludes.list");
  1090. #optional to exclude Synaptic file lists
  1091. do_cmd("echo /var/cache/apt/pkgcache.bin >>$workdir/excludes.list");
  1092. do_cmd("echo /var/cache/apt/srcpkgcache.bin >>$workdir/excludes.list");
  1093. }
  1094.  
  1095. # handle sort
  1096. do_cmd(":>$workdir/sort.list", ++$pos);
  1097. do_cmd("cat ".$opts{sort}." >>$workdir/sort.list", ++$pos) if (defined($opts{sort}));
  1098. end_progress();
  1099.  
  1100. my $withgzip;
  1101. if (defined($opts{gzip})) {
  1102. $withgzip = ""
  1103. }
  1104. elsif (defined($opts{lzma})) {
  1105. $withgzip = "-comp lzma"
  1106. }
  1107. elsif (defined($opts{xz})) {
  1108. $withgzip = "-comp xz"
  1109. }
  1110. else {
  1111. $withgzip = "-comp xz -Xbcj x86 -b 1048576"
  1112. }
  1113.  
  1114. $pos = 0;
  1115. if ($o_looptype =~ m/sqfs/) {
  1116. my @files = qx(find $o_root -type f 2>/dev/null);
  1117. my $total = scalar(@files);
  1118. start_progress("Creating compressed image", $total+2);
  1119. my $iso = "$loopcmp $o_root $workdir/livecd/livecd.$o_looptype $withgzip -info -ef $workdir/excludes.list";
  1120. $iso = "$iso -sort $workdir/sort.list" if (defined($opts{sort}));
  1121. $iso = "$iso 2>&1";
  1122. print "DEBUG: $iso\n" if (defined($opts{debug}));
  1123. open CMP, "$iso |" or die_("\nFATAL: Unable to execute '$iso'\n");
  1124. my $line;
  1125. my $linep = "";
  1126. while ($line = <CMP>) {
  1127. if ($line =~ m/mksquashfs: file/) {
  1128. $linep = $line;
  1129. $pos++;
  1130. set_progress($pos, $linep);
  1131. }
  1132. else {
  1133. if (defined($opts{debug})) {
  1134. print "$line\n" if ($line =~ m/Error/);
  1135. }
  1136. }
  1137. set_progress($pos, $linep);
  1138. }
  1139. close CMP;
  1140. do_cmd("chmod 644 $workdir/livecd/livecd.$o_looptype", $total+1); # Failure = out of space
  1141. do_cmd("ln $workdir/livecd/livecd.$o_looptype $opts{img}", $total+2) if (defined($opts{img}));
  1142. end_progress();
  1143. }
  1144. else {
  1145. start_progress("Creating loop image", 10001);
  1146. my $iso = "genisoimage $genisoimage_opts -R -exclude-list $workdir/excludes.list -hide-rr-moved -cache-inodes -no-bak -pad -v -v";
  1147. $iso = "$iso -sort $workdir/sort.list" if (defined($opts{sort}));
  1148.  
  1149.  
  1150. $iso = "$iso -o $workdir/livecd/livecd.$o_looptype $o_root";
  1151.  
  1152. $iso = "($iso) 2>&1";
  1153. print "DEBUG: $iso\n" if (defined($opts{debug}));
  1154. open CMP, "$iso |" or die_("\nFATAL: Unable to execute '$iso'\n");
  1155. my $line;
  1156. while ($line = <CMP>) {
  1157. if ($line =~ m/done, estimate/) {
  1158. $line =~ s/^ //g while ($line =~ m/^ /);
  1159. my ($per, @rest) = split(/ /, $line);
  1160. $per =~ s/%//;
  1161. $pos = int($per*100);
  1162. }
  1163. set_progress($pos, $line);
  1164. }
  1165. close CMP;
  1166. do_cmd("ln $workdir/livecd/livecd.$o_looptype $opts{img}", 10001) if (defined($opts{img}));
  1167. end_progress();
  1168. }
  1169. }
  1170. }
  1171.  
  1172.  
  1173. ### create the isolinux stuff
  1174. sub create_isolinux {
  1175. my $pos = 0;
  1176. start_progress("Creating isolinux boot", 9);
  1177.  
  1178. # copy boot images
  1179. my $bin = "/usr/lib/syslinux/isolinux.bin";
  1180. die_("\nFATAL: '$bin' does not exist on your machine. You need to install the syslinux package.\n") unless (-f $bin);
  1181. do_copy($bin, 644, "$workdir/livecd/isolinux/isolinux.bin", ++$pos);
  1182. die_("\nFATAL: The kernel '".$o_root."boot/vmlinuz-$o_kernel' does not exist on your machine.\n") unless (-f $o_root."boot/vmlinuz-$o_kernel");
  1183. do_copy($o_root."boot/vmlinuz-$o_kernel", 644, "$workdir/livecd/isolinux/vmlinuz", ++$pos);
  1184. do_copy($o_root."usr/lib/syslinux/gfxboot.com", 755, "$workdir/livecd/isolinux/gfxboot.com", ++$pos);
  1185. do_copy($o_root."usr/share/mylivecd/gfxboot.cfg", 755, "$workdir/livecd/isolinux/gfxboot.cfg", ++$pos);
  1186. if ($o_mbkopt ne "") {
  1187. do_copy($o_root."boot/vmlinuz-$o_mbkopt", 644, "$workdir/livecd/isolinux/vmlinuz2", ++$pos)
  1188. }
  1189. do_copy("/usr/bin/mediacheck", 755, "$workdir/livecd/isolinux/mediacheck", ++$pos);
  1190. #do_copy("/usr/bin/checkisomd5", 755, "$workdir/livecd/isolinux/checkisomd5", ++$pos);
  1191. #do_copy($o_root."boot/memtest-4.20", 644, "$workdir/livecd/isolinux/memtest", ++$pos);
  1192. if ($o_bootloader =~ m/^iso/) {
  1193. do_copy($o_root."usr/share/gfxboot/themes/$opts{boottheme}/install/*", 644, "$workdir/livecd/isolinux", ++$pos);
  1194. } else {
  1195. do_copy($o_stage2, 644, "$workdir/livecd/boot/grub/stage2_eltorito", ++$pos);
  1196. do_copy($o_root."boot/grub/*.xpm.gz", 644, "$workdir/livecd/boot/grub/livecd.xpm.gz", ++$pos);
  1197. do_copy($o_root."usr/share/gfxboot/themes/$opts{boottheme}/boot/*", 644, "$workdir/livecd/boot/grub", ++$pos);
  1198. }
  1199.  
  1200. # copy messages
  1201. do_copy($opts{bootmsg}, 644, "$workdir/livecd/isolinux/livecd.msg", ++$pos) if (defined($opts{bootmsg}));
  1202. if (defined($opts{bootimg})) {
  1203. do_cmd("echo -n '' >$workdir/livecd/isolinux/livecd.msg", ++$pos);
  1204. do_cmd("echo -e '\\030livecd.lss' >>$workdir/livecd/isolinux/livecd.msg", ++$pos);
  1205. do_copy($opts{bootimg}, 644, "$workdir/livecd/isolinux/livecd.lss", ++$pos);
  1206. }
  1207.  
  1208. # write config
  1209. my $appopt;
  1210. if ($kernel26 == 1) {
  1211. $appopt = "initrd=initrd.gz root=/dev/rd/3 acpi=on vga=$o_vgamode keyb=$o_keyboard vmalloc=256M nokmsboot";
  1212. } else {
  1213. $appopt = "initrd=initrd.gz root=/dev/rd/3 devfs=mount vga=$o_vgamode";
  1214. }
  1215. #$appopt .= " splash=$o_splash" if ($o_splash !~ m/no/);
  1216. $appopt = "$appopt fastboot=yes automatic=method:cdrom ramdisk_size=32000" if (!defined($kernel26));
  1217. $appopt = "$appopt fstab=".$opts{fstab} if (defined($opts{fstab}));
  1218. $appopt = "$appopt home=usb" if (defined($opts{usbhome}));
  1219. $appopt = "$appopt $_" foreach (@{$opts{bootopt}});
  1220.  
  1221. open LANG, '>', "$workdir/livecd/isolinux/lang";
  1222. print LANG $opts{bootlang}."\n";
  1223. close LANG;
  1224.  
  1225. if (defined($opts{bootmenu}) && -f $opts{bootmenu} )
  1226. {
  1227. do_copy($opts{bootmenu}, 644, "$workdir/livecd/isolinux", ++$pos);
  1228. } else {
  1229. open CFG, '>', "$workdir/livecd/isolinux/isolinux.cfg";
  1230. print CFG "default LiveCD\n";
  1231. print CFG "prompt ".(defined($opts{noprompt}) ? "0" : "1")."\n";
  1232. print CFG "timeout $o_timeout\n";
  1233. print CFG "display livecd.msg\n" if (-f "$workdir/livecd/isolinux/livecd.msg");
  1234. foreach my $k (keys %{$opts{bootkey}}) {
  1235. do_copy(${$opts{bootkey}}{$k}, 644, "$workdir/livecd/isolinux/livecd_$k.msg");
  1236. print CFG "$k livecd_$k.msg\n";
  1237. }
  1238. print CFG "ui gfxboot.com bootlogo\n";
  1239. print CFG "label LiveCD\n";
  1240. print CFG " kernel vmlinuz\n";
  1241. print CFG " append livecd=livecd $appopt splash=$o_splash\n";
  1242. print CFG "label LiveCD - No Boot Splash\n";
  1243. print CFG " kernel vmlinuz\n";
  1244. print CFG " append livecd=livecd $appopt splash=verbose\n";
  1245. print CFG "label Video safe mode - FBDEV\n";
  1246. print CFG " kernel vmlinuz\n";
  1247. print CFG " append livecd=livecd $appopt splash=$o_splash fbdev\n";
  1248. print CFG "label Safe boot\n";
  1249. print CFG " kernel vmlinuz\n";
  1250. print CFG " append livecd=livecd initrd=initrd.gz root=/dev/rd/3 acpi=off vga=normal keyb=us vmalloc=256M noapic nolapic nopinit fbdev\n";
  1251. print CFG "label Console\n";
  1252. print CFG " kernel vmlinuz\n";
  1253. print CFG " append livecd=livecd 3 $appopt splash=$o_splash\n";
  1254. print CFG "label Copy to RAM\n";
  1255. print CFG " kernel vmlinuz\n";
  1256. print CFG " append livecd=livecd copy2ram $appopt splash=verbose\n";
  1257. print CFG "label Install PCLinuxOS\n";
  1258. print CFG " kernel vmlinuz\n";
  1259. print CFG " append livecd=livecd $appopt splash=$o_splash install\n";
  1260. print CFG "#label LegacyKernel\n";
  1261. print CFG "# kernel vmlinuz2\n";
  1262. print CFG "# append livecd=livecd initrd=initrd2.gz $appopt\n";
  1263. print CFG "#label Memtest\n";
  1264. print CFG "# kernel memtest\n";
  1265. close CFG;
  1266. }
  1267.  
  1268. if ($o_bootloader =~ m/^grub/) {
  1269. if (defined($opts{bootmenu}) && -f $opts{bootmenu} )
  1270. {
  1271. do_copy($opts{bootmenu}, 644, "$workdir/livecd/boot/grub", ++$pos);
  1272. } else {
  1273. open CFG, '>', "$workdir/livecd/boot/grub/menu.lst";
  1274. print CFG "default 0\n";
  1275. print CFG "timeout 10\n";
  1276. print CFG "gfxmenu (cd)/boot/grub/message\n\n";
  1277. print CFG "title LiveCD\n";
  1278. print CFG "kernel (cd)/isolinux/vmlinuz livecd=livecd $appopt splash=$o_splash\n";
  1279. print CFG "initrd (cd)/isolinux/initrd.gz\n\n";
  1280. print CFG "title LiveCD - No Boot Splash\n";
  1281. print CFG "kernel (cd)/isolinux/vmlinuz livecd=livecd $appopt splash=verbose\n";
  1282. print CFG "initrd (cd)/isolinux/initrd.gz\n\n";
  1283. print CFG "title Video safe mode - FBDEV\n";
  1284. print CFG "kernel (cd)/isolinux/vmlinuz livecd=livecd $appopt splash=$o_splash fbdev\n";
  1285. print CFG "initrd (cd)/isolinux/initrd.gz\n\n";
  1286. print CFG "title Safe boot\n";
  1287. print CFG "kernel (cd)/isolinux/vmlinuz livecd=livecd root=/dev/rd/3 acpi=off vga=normal keyb=us vmalloc=256M noapic nolapic nopinit fbdev\n";
  1288. print CFG "initrd (cd)/isolinux/initrd.gz\n\n";
  1289. print CFG "title Console\n";
  1290. print CFG "kernel (cd)/isolinux/vmlinuz $appopt splash=$o_splash 3\n";
  1291. print CFG "initrd (cd)/isolinux/initrd.gz\n\n";
  1292. print CFG "title Copy to RAM\n";
  1293. print CFG "kernel (cd)/isolinux/vmlinuz livecd=livecd copy2ram $appopt splash=verbose\n";
  1294. print CFG "initrd (cd)/isolinux/initrd.gz\n\n";
  1295. print CFG "#title Media check\n";
  1296. print CFG "#kernel (cd)/isolinux/vmlinuz livecd=livecd md5sum $appopt splash=verbose\n";
  1297. print CFG "#initrd (cd)/isolinux/initrd.gz\n\n";
  1298. print CFG "#title LegacyKernel\n";
  1299. print CFG "#kernel (cd)/isolinux/vmlinuz2 livecd=livecd initrd=initrd2.gz $appopt\n";
  1300. print CFG "#initrd (cd)/isolinux/initrd2.gz\n\n";
  1301. close CFG;
  1302. }
  1303. }
  1304.  
  1305. set_progress(++$pos, "$workdir/livecd/isolinux/isolinux.cfg");
  1306.  
  1307. if ($o_mbkopt ne "") {
  1308. if ($o_bootloader =~ m/^iso/) {
  1309. do_cmd("perl -pi -e 's/initrd2.gz initrd=initrd.gz/initrd2.gz/' $workdir/livecd/isolinux/isolinux.cfg");
  1310. do_cmd("perl -pi -e 's/#//' $workdir/livecd/isolinux/isolinux.cfg");
  1311. # if ($o_mbkopt !~ m/lgc/) {
  1312. do_cmd("perl -pi -e 's/LiveCD/LiveCD-".$o_kernel."/' $workdir/livecd/isolinux/isolinux.cfg");
  1313. if ($o_mbkopt_label ne "") {
  1314. do_cmd("perl -pi -e 's/LegacyKernel/".$o_mbkopt_label."/' $workdir/livecd/isolinux/isolinux.cfg");
  1315. } else {
  1316. do_cmd("perl -pi -e 's/LegacyKernel/Kernel-".$o_mbkopt."/' $workdir/livecd/isolinux/isolinux.cfg");
  1317. }
  1318. # }
  1319. } else {
  1320. do_cmd("perl -pi -e 's/initrd2.gz initrd=initrd.gz/initrd2.gz/' $workdir/livecd/boot/grub/menu.lst");
  1321. do_cmd("perl -pi -e 's/#//' $workdir/livecd/boot/grub/menu.lst");
  1322. # if ($o_mbkopt !~ m/lgc/) {
  1323. do_cmd("perl -pi -e 's/LiveCD/LiveCD-".$o_kernel."/' $workdir/livecd/boot/grub/menu.lst");
  1324. if ($o_mbkopt_label ne "") {
  1325. do_cmd("perl -pi -e 's/LegacyKernel/".$o_mbkopt_label."/' $workdir/livecd/boot/grub/menu.lst");
  1326. } else {
  1327. do_cmd("perl -pi -e 's/LegacyKernel/Kernel-".$o_mbkopt."/' $workdir/livecd/boot/grub/menu.lst");
  1328. }
  1329. # }
  1330. }
  1331. }
  1332. # create boot catalogue
  1333. do_cmd("dd if=/dev/zero of=$workdir/livecd/isolinux/boot.cat bs=1k count=2 2> /dev/null", ++$pos);
  1334.  
  1335. end_progress();
  1336. }
  1337.  
  1338.  
  1339. ### create the final iso
  1340. sub create_finaliso {
  1341. # create a sort-file
  1342. my $pos = 0;
  1343. start_progress("Creating final iso", 10001);
  1344. open SORT, '>', "$workdir/sort_iso.list";
  1345. print SORT "$workdir/livecd/isolinux/isolinux.bin 500\n";
  1346. print SORT "$workdir/livecd/isolinux/isolinux.cfg 499\n";
  1347. print SORT "$workdir/livecd/isolinux/vmlinuz 498\n";
  1348. print SORT "$workdir/livecd/isolinux/initrd.gz 497\n";
  1349. print SORT "$workdir/livecd/isolinux/* 450\n";
  1350. print SORT "$workdir/livecd/livecd.$o_looptype 400\n";
  1351. close SORT;
  1352. set_progress(++$pos, "$workdir/sort_iso.list");
  1353.  
  1354. # create actual iso
  1355. $opts{isoextrafiles} = "" unless (defined($opts{isoextrafiles}));
  1356. if ($o_bootloader =~ m/^grub/) {
  1357. $loader = "boot/grub/stage2_eltorito";
  1358. }
  1359. elsif ($o_bootloader =~ m/^iso/) {
  1360. $loader = "isolinux/isolinux.bin";
  1361. }
  1362. my $cmd="genisoimage -pad -l -R -J -v -v \\\
  1363. -V '".$opts{volumeid}."' \\\
  1364. -A '".$opts{application}."' \\\
  1365. -p '".$opts{preparer}."' \\\
  1366. -P '".$opts{publisher}."' \\\
  1367. -b $loader -c isolinux/boot.cat -hide-rr-moved -no-emul-boot -boot-load-size 4 -boot-info-table -sort $workdir/sort_iso.list -o $finaliso $workdir/livecd/ ".$opts{isoextrafiles}." 2>&1";
  1368. open ISO, "$cmd |" or die_("\nFATAL: Unable to execute '$cmd'\n");
  1369. my $line;
  1370. while ($line = <ISO>) {
  1371. if ($line =~ m/done, estimate/) {
  1372. $line =~ s/^ //g while ($line =~ m/^ /);
  1373. my ($per, @rest) = split(/ /, $line);
  1374. $per =~ s/%//;
  1375. $pos = int($per*100)+1;
  1376. }
  1377. set_progress($pos, $line);
  1378. }
  1379. close ISO;
  1380. end_progress();
  1381. }
  1382.  
  1383.  
  1384. ### create the embedded md5sum
  1385. sub create_md5 {
  1386. my $isosize = get_exec("ls -al --block-size=1M $finaliso | awk '{print \$5 }'");
  1387. start_progress("Embedding MD5 checksum", $isosize);
  1388. open MD5, "implantisomd5 $finaliso |" or die_("\nFATAL: Unable to execute 'implantisomd5'\n");
  1389. my $line;
  1390. my $pos = 0;
  1391. while ($line = <MD5>) {
  1392. chomp($line);
  1393. if ($line =~ /^Read/) {
  1394. $pos = $line;
  1395. $pos =~ s/Read//;
  1396. $pos =~ s/MB//;
  1397. $pos =~ s/\s// while ($pos =~ /\s/);
  1398. }
  1399. set_progress($pos, $line);
  1400. }
  1401. close MD5;
  1402. end_progress();
  1403. }
  1404.  
  1405.  
  1406. ### clean everything
  1407. sub cleanup {
  1408. if (defined($workdir)) {
  1409. system("umount $workdir/initrd.mnt 2>/dev/null");
  1410. system("rm -rf $workdir") unless (defined($opts{noclean}));
  1411. }
  1412. if (-e "/tmp/bootsplash/scripts/make-boot-splash") {
  1413. do_cmd("rm -rf /tmp/bootsplash");
  1414. }
  1415.  
  1416. # enable back some disabled services
  1417. print STDERR "\nRestoring Services on the installed system\n\n";
  1418. services::start_service_on_boot($_) foreach @services;
  1419. }
  1420.  
  1421.  
  1422.  
  1423. ### signals
  1424. sub die_ {
  1425. die('DIE', join(' ', @_));
  1426. }
  1427. sub do_signal {
  1428. my ($signal, $text) = @_;
  1429. end_thread();
  1430. my $to = $text ? $text : "\nFATAL: Interrupted.\n";
  1431. chomp($to);
  1432. print pack("A80", $to)."\n";
  1433. cleanup();
  1434. exit(1);
  1435. }
  1436.  
  1437.  
  1438. ### main program entry point
  1439. MAIN: {
  1440. $SIG{INT} = \&do_signal;
  1441. $SIG{KILL} = \&do_signal;
  1442. $SIG{PIPE} = \&do_signal;
  1443.  
  1444. print_banner();
  1445. parse_options();
  1446.  
  1447. create_initrd();
  1448. create_initrd2() if ($o_mbkopt ne "");;
  1449. create_compressed();
  1450. create_isolinux();
  1451. create_finaliso();
  1452. create_md5() if (defined($opts{md5sum}));;
  1453. cleanup();
  1454.  
  1455. my $finalsize = get_exec("ls -al $finaliso | awk '{print \$5 }'");
  1456. print "\nCreated '$finaliso' (".fmt_number($finalsize)." bytes) in ".fmt_elapsed(time-$starttime)."\n\n";
  1457. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement