home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Complet / emovix / eMovix-0.9.0pre1_Setup.exe / {app} / scripts / mkmovixiso < prev    next >
Encoding:
Text File  |  2003-12-16  |  15.6 KB  |  486 lines

  1. #!/usr/bin/perl
  2.  
  3. #### add option args for movixrc opts
  4.  
  5. use strict;
  6. use Cwd 'abs_path';
  7. use vars qw(
  8.         %RC
  9.         $title
  10.         $isoOut
  11.         $bootLabel
  12.         @extra_mkisofs_options
  13.         $extra_mkisofs_options
  14.         @extra_mplayer_options
  15.         $extra_mplayer_options
  16.         @unwanted_mplayer_options
  17.         $unwanted_mplayer_options
  18.         $make_empty_iso
  19.         $css
  20.         $loop
  21.         $random
  22.         $shut
  23.         $reboot
  24.         $eject
  25.         $fontSet
  26.         $bgVideo
  27.         $language
  28.         $verbose
  29.         $version
  30.         $movixDir
  31.         $fontDir
  32.         $isoDir
  33.         $mkisofs_bin
  34.         $noSubs
  35.         $bootOptions
  36.         $stdOptions
  37.         $extraOptions
  38.         $hasQT
  39.         $hasASF
  40.         $hasWMV
  41.         $hasRP
  42.         $hasXANIM
  43.         $autoDelete
  44.         $help
  45.         $nodma
  46.         $dma
  47.         $keyboard
  48.         );
  49.  
  50. my $pwd = $ENV{"PWD"};
  51. my $bin_dir  = $0 =~ /^\// ? $0 : abs_path($0);
  52. $bin_dir     =~ s/\/?[^\/]*$//g;
  53. $mkisofs_bin = "mkisofs";
  54.  
  55. ##################################
  56. ###  Retrieving options from .mkmovixisorc
  57. ###  These are the default options for this script
  58. ###########################
  59. my $mkmovixisorc = $ENV{"HOME"}."/.mkmovixisorc";
  60. if( -e $mkmovixisorc ){
  61.   open(RC,$mkmovixisorc);
  62.   while(<RC>){
  63.     next if /^\#/;
  64.     next unless /^([^\=]+)\=(.*)$/;
  65.     $RC{$1}=$2;
  66.   }
  67.   close(RC);
  68. }
  69. $isoOut    = $RC{'output-file'}   if exists $RC{'output-file'};
  70. $bootLabel = $RC{'boot-label'}    if exists $RC{'boot-label'};
  71. $fontSet   = $RC{'subtitleFonts'} if exists $RC{'subtitleFonts'};
  72. $bgVideo   = $RC{'bgVideo'}       if exists $RC{'bgVideo'};
  73. $language  = $RC{'language'}      if exists $RC{'language'};
  74. $mkisofs_bin = $RC{'mkisofs_bin'} if exists $RC{'mkisofs_bin'};
  75. $keyboard  = $RC{'keyboard'}      if exists $RC{'keyboard'};
  76. $extra_mkisofs_options    = $RC{'extra-mkiso-options'}      if exists $RC{'extra-mkiso-options'};
  77. $extra_mplayer_options    = $RC{'extra-mplayer-options'}    if exists $RC{'extra-mplayer-options'};
  78. $unwanted_mplayer_options = $RC{'unwanted-mplayer-options'} if exists $RC{'unwanted-mplayer-options'};
  79. $css    = "y" if $RC{'css'} eq "y";
  80. $loop   = $RC{'loop'} if exists $RC{'loop'} and $RC{'loop'} =~ /^\d+$/;
  81. $random = "y" if $RC{'random'} eq "y";
  82. $shut =   "y" if $RC{'shut'}   eq "y";
  83. $reboot = "y" if $RC{'reboot'} eq "y";
  84. $eject  = "y" if $RC{'eject'}  eq "y";
  85. $nodma  = "y" if $RC{'dma'}    eq "n";
  86. $autoDelete  = 1 if $RC{'auto-delete'}  eq "y";
  87.  
  88. #######################
  89. ### Retrieve options from command line
  90. #################################
  91. use Getopt::Long;
  92. use Pod::Usage;
  93.  
  94. GetOptions (
  95.         "title=s"             => \$title,
  96.         "output-file=s"       => \$isoOut,
  97.         "boot-label=s"        => \$bootLabel,
  98.         "extra-mkiso-options=s"       => \@extra_mkisofs_options,
  99.         "extra-mplayer-options=s"     => \@extra_mplayer_options,
  100.         "unwanted-mplayer-options=s"  => \@unwanted_mplayer_options,
  101.         "make-empty-iso"      => \$make_empty_iso,
  102.         "css"                 => \$css,
  103.         "loop=i"              => \$loop,
  104.         "random"              => \$random,
  105.         "reboot"              => \$reboot,
  106.         "shut"                => \$shut, 
  107.         "eject"               => \$eject,
  108.         "auto-delete"         => \$autoDelete,
  109.         "movixDir=s"          => \$movixDir,
  110.         "mkisofs=s"           => \$mkisofs_bin,
  111.         "subtitleFonts=s"     => \$fontSet,
  112.         "bgVideo=s"           => \$bgVideo,
  113.         "language=s"          => \$language,
  114.         "keyboard=s"          => \$keyboard,
  115.         "hasQT"               => \$hasQT,
  116.         "hasWMV"              => \$hasWMV,
  117.         "hasASF"              => \$hasASF,
  118.         "hasRP"               => \$hasRP,
  119.         "hasXANIM"            => \$hasXANIM,
  120.         "verbose"             => \$verbose,
  121.         "nodma"               => \$nodma,
  122.         "movix-version"       => \$version,
  123.         'help|?'              => \$help
  124.         );
  125.  
  126. $extra_mkisofs_options = join(' ',split(/,/,join(',',@extra_mkisofs_options))) if @extra_mkisofs_options > 0;
  127. $extra_mplayer_options = join(' ',split(/,/,join(',',@extra_mplayer_options))) if @extra_mplayer_options > 0;
  128. $unwanted_mplayer_options = join(' ',split(/,/,join(',',@unwanted_mplayer_options))) if @unwanted_mplayer_options > 0;
  129.  
  130. $fontSet  = "FreeSerifBoldItalic" unless defined $fontSet;
  131.  
  132. my $prefix = -e "$bin_dir/movix-conf" ? `$bin_dir/movix-conf` : `movix-conf`;
  133. chop $prefix;
  134.  
  135. ### collect all known languages avaialble for the boot messages
  136. my $knownLanguages = `ls \"$prefix/boot-messages/\"`;
  137. $knownLanguages =~ s/\n/ /g;
  138. chop $knownLanguages;
  139. $knownLanguages = " $knownLanguages ";
  140.  
  141. ### collect all known kbd layouts avaialble 
  142. my $knownKeymaps = `ls \"$prefix/keyboard-i18n/\"`;
  143. $knownKeymaps =~ s/\n/ /g;
  144. chop $knownKeymaps;
  145. $knownKeymaps = " $knownKeymaps ";
  146.  
  147. # Check if the given lang is available
  148. $language = "en" unless defined $language;
  149. unless( $knownLanguages =~ / $language / ){
  150.     print "Label $language does not correspond to any language supported by eMoviX :-(\nIf you would like to provide translations for it post a message on the MoviX forums!\n\n";
  151.     help();
  152.     exit;
  153. }
  154.  
  155. if( defined $keyboard ){
  156.   unless( $knownKeymaps =~ / $keyboard / ){
  157.     print "Keyboard layout $keyboard does not correspond to any layouts supported by eMoviX :-(\nIf you would like to provide a keyboard layout, read keyboard-i18n/README in the eMoviX distribution! :-)\n\n";
  158.     help();
  159.     exit;
  160.   }
  161. } else {
  162.   $keyboard = ( $knownKeymaps =~ / $language / ) ? $language : "us";
  163.   $keyboard =~ s/^en$/us/;
  164. }
  165.  
  166. if( ! defined $movixDir ){
  167.     $movixDir = `$bin_dir/movix-conf`;
  168.     chop $movixDir;
  169. }
  170.  
  171. #$bgVideo  = "$movixDir/movix/movix.music.avi" unless defined $bgVideo;
  172.  
  173. if( defined $help ){
  174.   help();
  175.   exit;
  176. }
  177.  
  178. if( defined $version ){
  179.   system "movix-version";
  180.   exit;
  181. }
  182.  
  183. if( defined $isoOut ){
  184.   $isoOut = $pwd."/".$isoOut if $isoOut !~ /^\//;
  185. } else {
  186.   print "\nYou _must_ provide an output file!\n";
  187.   help();
  188.   exit;
  189. }
  190.  
  191. if( @ARGV == 0 and ! defined $make_empty_iso ){
  192.   print "\nYou _must_ provide at least one input file!\n";
  193.   help();
  194.   exit;
  195. }
  196.  
  197. if( defined $title ) {
  198.   my @chars = split '', $title;
  199.   if( @chars > 32 ){
  200.     print "\nTitle length cannot be longer than 32 characters!\n";
  201.     exit;
  202.   }
  203. } else {
  204.   my $version = `$bin_dir/movix-version`;
  205.   chop $version;
  206.   $title    = "eMoviX $version CD";
  207. }
  208.  
  209. ################################
  210. ### Building the temporary dir and linking there
  211. ### all audio/video/auxiliary files
  212. ################################
  213. my $date = `date +%s`;
  214. chop $date;
  215. my $tmpDir = "/tmp/movix-$date";
  216. mkdir  "$tmpDir";
  217. chdir  "$tmpDir";
  218. mkdir  "movix";
  219. foreach ( split "\n", `$bin_dir/movix-files` ){
  220.   `ln -s "$movixDir/movix/$_" movix`;
  221. }
  222. #system "ln -s \"$movixDir\"/movix/* movix";
  223.  
  224. ### dealing with codecs
  225. #`rm -f movix/win32`;
  226. my @codecs = split "\n", `ls "$movixDir"/codecs/ 2> /dev/null`;
  227. if( @codecs > 0 ){
  228.   `mkdir -p mplayer/codecs/`;
  229.   `ln -s "$movixDir"/codecs/* mplayer/codecs`;
  230.   `rm -f mplayer/codecs/qt*`    unless defined $hasQT;
  231.   `rm -f mplayer/codecs/win32*` unless defined $hasASF or defined $hasWMV;
  232.   `rm -f mplayer/codecs/rp*`    unless defined $hasRP;
  233.   `rm -f mplayer/codecs/xanim*` unless defined $hasXANIM;
  234. }
  235.  
  236. ### dealing with libdvdcss - you'll need this if you want to play encrypted DVDs
  237. `ln -s "$movixDir"/movix/libdvdcss* movix` if defined $css;
  238. #system "rm -f movix/libdvdcss*"   unless defined $css;
  239.  
  240. mkdir  "isolinux";
  241. system "ln -s \"$movixDir\"/isolinux/* isolinux";
  242.  
  243. # Link the isolinux boot-keymap to the selected keyboard layout
  244. system "ln -s \"$movixDir\"/keyboard-i18n/$keyboard/bootkey.map isolinux/bootkey.map";
  245.  
  246. system "rm -f isolinux/isolinux.bin";
  247. system "cp \"$movixDir\"/isolinux/isolinux.bin isolinux/isolinux.bin";
  248. if( defined $bootLabel ){
  249.   die "boot label $bootLabel is unknown :-(\n"
  250.     unless $bootLabel =~ /^vesa|vesaFB(\d*)?|FB|aa(\d*)?|sdl$/;
  251.   my $isolinuxcfg = "default $bootLabel\n";
  252.   open CFG, "isolinux/isolinux.cfg";
  253.   <CFG>;
  254.   while(<CFG>){
  255.     $isolinuxcfg .= $_;
  256.   }
  257.   close CFG;
  258.   system "rm -f isolinux/isolinux.cfg";
  259.   open CFG, "> isolinux/isolinux.cfg";
  260.   print CFG $isolinuxcfg;
  261.   close CFG;
  262. }
  263.  
  264. ### next instruction will disappear once the old txt messages will be
  265. ### removed from the src/isolinux dir
  266. system "rm -f isolinux/*txt";
  267. system "ln -s \"$movixDir\"/boot-messages/$language/*txt isolinux";
  268.  
  269. foreach my $file (@ARGV){
  270.     $file = $pwd."/".$file if $file !~ /^\//;
  271.     if( -d $file ){
  272.     system "ln -s $file/* .";
  273.     } elsif( -e $file ) {
  274.     system "ln -s \"$file\" .";
  275.     } else {
  276.     die "The file $file does not exist! Please check and retry.\n";
  277.     }
  278. }
  279.  
  280. $fontDir = "mplayer/font";
  281. if( -e "$movixDir/mplayer-fonts/$fontSet/font.desc" ){
  282.   system "mkdir -p $fontDir";
  283.   system "ln -s \"$movixDir\"/mplayer-fonts/$fontSet/* $fontDir";
  284. } else {
  285. #  print "\"$movixDir\"/mplayer-fonts/$fontSet/font.desc"."\n";
  286. #  print "pippo\n" if -e "/usr/local/share/emovix";
  287. #  print "pippo->\n" if -e "$movixDir";
  288. #  $movixDir = "/usr/a b";
  289. #  print "<-pippo\n" if -e "$movixDir";
  290. #  print "pippo\n" if -e "$movixDir/mplayer-fonts/$fontSet/font.desc";
  291. #  die "che ci fo qui?";
  292.   system "mkdir -p mplayer";
  293.   system "ln -s \"$movixDir\"/mplayer-fonts/$fontSet\.ttf mplayer/subfont.ttf";
  294. }
  295.  
  296. if ( $bgVideo =~ /^none$/ ) {
  297.   #print "Not including a background video.";
  298.   system "rm movix/movix.music.avi";
  299. } elsif ( $bgVideo eq '' ) {
  300. # No special background video given, use the one already determined by movix-files
  301.   # do nothing
  302. } else {
  303. # A filename was given
  304.  
  305.   if ( -e $bgVideo ) {
  306.   # Absolute path to an existing file
  307.     system "rm movix/movix.music.avi; \
  308.             ln -s '$bgVideo' movix/movix.music.avi";
  309.  
  310.   } elsif ( -e "$pwd/$bgVideo" ){
  311.   # The video is in the current directory, or a relative path was given
  312.     system "rm movix/movix.music.avi; \
  313.             ln -s '$pwd/$bgVideo' movix/movix.music.avi";
  314.  
  315.   } elsif ( -e "$movixDir/backgrounds/$bgVideo" ){
  316.   # Perhaps in $movixDir/backgrounds/?
  317.     system "rm movix/movix.music.avi; \
  318.             ln -s '$movixDir/backgrounds/$bgVideo' movix/movix.music.avi";
  319.   } else {
  320.   # Sorry
  321.     die "Background video $bgVideo couldn't be found!\n";
  322.   }
  323. }
  324.  
  325. # Link the selected shell keymap
  326. system "ln -s \"$movixDir\"/keyboard-i18n/$keyboard/shellkey.map movix/shellkey.map";
  327.  
  328. open MOVIXRC, "> movix/movixrc";
  329. print MOVIXRC "extra-mplayer-options=$extra_mplayer_options\n" if defined $extra_mplayer_options;
  330. print MOVIXRC "unwanted-mplayer-options=$unwanted_mplayer_options\n" if defined $unwanted_mplayer_options;
  331. print MOVIXRC "loop=$loop\n" if defined $loop;
  332. print MOVIXRC "shut=y\n"     if defined $shut;
  333. print MOVIXRC "reboot=y\n"   if defined $reboot;
  334. print MOVIXRC "random=y\n"   if defined $random;
  335. print MOVIXRC "eject=y\n"    if defined $eject;
  336. print MOVIXRC "dma=n\n"      if defined $nodma;
  337. close MOVIXRC;
  338.  
  339. print "\n";
  340. if( $verbose == 1 ){
  341.     print "Your movix directory seems to be in: \"$movixDir\"\n";
  342.     print "MoviX temporary directory is:        $tmpDir\n";
  343. }
  344.  
  345. ##############
  346. ### Standard booting options, from SysLinux docs
  347. ### and from slackware installation CD README
  348. ###############
  349. $bootOptions = "-no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/isolinux.boot -sort isolinux/iso.sort";
  350.  
  351. ##############
  352. ### Standard mkisofs options: -v=>verbose, -r=>rock-ridge,
  353. ####                          -J=>Joliet,  -f=>follow symbolic links
  354. ##############
  355. $stdOptions = "-v -r -J -f";
  356.  
  357. #######
  358. ### User's extra options (if any)
  359. #########
  360. if( defined @extra_mkisofs_options ) {
  361.     $extraOptions .= $extra_mkisofs_options;
  362. }
  363.  
  364. my $mkiso  = "$mkisofs_bin -o \"$isoOut\" $stdOptions -V \"$title\" $extraOptions $bootOptions .";
  365. if( $verbose == 1 ){
  366.     print "Starting mkisofs...\n$mkiso\n";
  367. } else {
  368.     $mkiso .= "> /dev/null 2> /dev/null";
  369. }
  370. system "$mkiso";
  371.  
  372. print "Your iso image is now in \"$isoOut\":\n";
  373. print `ls -l \"$isoOut\"`;
  374. if ( $autoDelete == 1 ) {
  375.     system "rm -rf '$tmpDir'";
  376.     print "The temporary directory '$tmpDir' was deleted.\n\n";
  377. } else {
  378.     print "You can safely delete the temporary directory $tmpDir\n\n";
  379. }
  380.  
  381. ##########################################################
  382. ####  Eventually this should be replaced by pod docs
  383. ######################
  384.  
  385. sub help {
  386.     print
  387. "Usage: mkmovixiso [options] file1 ... fileN dir1 ... dirN
  388. Note: All options may be be abbreviated to uniqueness and
  389.       a single dash is sufficient
  390. Options:
  391.  
  392.  Generic:
  393.  
  394.    --title=<title>         Title of the iso image
  395.    --output-file=<file>    Name [with full path!] of the output iso image
  396.    --boot-label=<label>    Make MoviX boot by default with your favorite label
  397.    --subtitleFonts=<lang>  Specify which font set will be included in the iso image.
  398.  
  399. Available font sets:
  400.  - MPlayer standard font sets
  401.    ";
  402.  
  403.     my $prefix = `$bin_dir/movix-conf`;
  404.     chop $prefix;
  405.     my @fonts = split "\n", `ls $prefix/mplayer-fonts/`;
  406.     my @stFonts;
  407.     my @ttFonts;
  408.     foreach (@fonts){
  409.       push @stFonts, $_ if -d "$prefix/mplayer-fonts/$_";
  410.       push @ttFonts, $_ if /.ttf$/i;
  411.     }
  412.     for( my $i=0; $i < @stFonts; $i++ ){
  413.       print "$stFonts[$i]";
  414.       print " (default)" if $fontSet eq $stFonts[$i];
  415.       print ", " unless $i == @stFonts - 1;
  416.     }
  417.     print "
  418.  
  419.  - True type font sets:
  420.    ";
  421.  
  422.     for( my $i=0; $i < @ttFonts; $i++ ){
  423.       $ttFonts[$i] =~ s/.ttf$//i;
  424.       print "$ttFonts[$i]";
  425.       print " (default)" if $fontSet eq $ttFonts[$i];
  426.       print ", " unless $i == @ttFonts - 1;
  427.     }
  428.  
  429. print "
  430.  
  431.    --language=<lang>       Specify the language of the CD boot messages
  432.  
  433. Available Languages:
  434. en - English (default),  it - Italian,     es - Spanish,      nl - Dutch,
  435. hu - Hungarian,          de - German,      fr - French,       pt - Portuguese,
  436. pl - Polish,             jp - Japanese,    sar - Sardinian,   esp - Esperanto
  437.  
  438.    --keyboard=<lang>       Specify the keyboard layout to use
  439.  
  440. Available keyboard layouts:
  441. us - US English (default), de - German     es - Spanish,      fr - French,
  442. hu - Hungarian,            it - Italian,   nl - Dutch,        pt - Portuguese,
  443. be - Belgian
  444.  
  445.    --movixDir=<dir>        Where the movix data dir is (no need to specify it if
  446.                            you didn't move it from its default install location)
  447.    --mkisofs=<mkisofs exe> Full path of mkisofs, in case it's not in the \$PATH
  448.    --bgVideo=file.avi      A video file to be used as background for audio file playback
  449.                            ('none' for not including the video file)
  450.  - Available backgrounds:
  451. ";
  452.  
  453.     my $prefix = `$bin_dir/movix-conf`;
  454.     chop $prefix;
  455.     my @bkg = split "\n", `ls $prefix/backgrounds/`;
  456.     foreach(@bkg){
  457.       print "$_\n";
  458.     }
  459.  
  460. print "
  461.    --css                   Include the dvdcss library (see README for more info)
  462.    --loop=<k>              Make MPlayer play k times your files before stopping [0=infinity]
  463.    --random                Make MPlayer play your files in random order
  464.    --eject                 Make MoviX eject the CD once it finished playing
  465.    --reboot                Make MoviX reboot the PC once it finished playing
  466.    --shut                  Make MoviX shut the PC off once it finished playing
  467.    --hasQT                 Include DLL files required to play QuickTime files
  468.    --hasASF                Include DLL files required to play .asf files
  469.    --hasWMV                Include DLL files required to play .wmv files
  470.    --hasRP                 Include DLL files required to play RealPlayer files
  471.    --hasXANIM              Include DLL files extracted from the xanim project
  472.    --nodma                 Do not enable fast mode for CD-ROM devices by default
  473.    --auto-delete           Automatically remove the temporary directory
  474.    --extra-mkiso-options=\"opt1 opt2 ...\"
  475.                            Extra options for mkisofs
  476.    --extra-mplayer-options=\"opt1 opt2 ...\"
  477.                            Extra options for mplayer
  478.    --unwanted-mplayer-options=\"opt1 opt2 ...\"
  479.                            MPlayer options you want to be sure MPlayer will not use
  480.    --movix-version         Print the version number and exit
  481.    --verbose               Be verbose
  482.    --help                  This help
  483.  
  484. ";
  485. }
  486.