#!/usr/local/bin/perl -w # # $Id: cdmaster,v 1.4 1999/02/23 21:46:30 mccannwj Exp $ # ------------------------------------------------------------------------- # Pre-mastering # Interface to Young Minds MakeDisc CD Mastering System # # exit(0) if CD was written # exit(1) otherwise # ------------------------------------------------------------------------- # written by: # William Jon McCann # 8-12-97 # Advanced Camera for Surveys # Johns Hopkins University # ------------------------------------------------------------------------- # --------------------Local Configuration--------------------------- # (no trailing slashes on directories) $SYSmakedisc_path = '/usr/local/site/makedisc-1.30b2'; # system affiliation (used for startup message) $SYSaffiliation = 'JHU/ACS'; # default error log to append to $SYSerror_log = '/var/adm/makedisc.log'; # work directory for makedisc to create image (also serves as lock file) $SYSwork_dir = '/tmp/makedisc'; # output device name $SYSoutput_dev = '/dev/rmt/0'; # out device size (in megabytes) $SYSoutput_dev_size = "650"; # files that must exist in base directory in order to begin @SYSbase_files = ( 'COPYRIGH.T', 'cd_copy', ); # Volume information (used in CD header) # must be all caps (see makedisc manual for specifics) $VIpublisher = 'ADVANCED CAMERA FOR SURVEYS'; $VIpreparer = 'THE JOHNS HOPKINS UNIVERSITY'; # --------------------Program Configuration--------------------------- # name of translation table file $CDtranslate_file = 'YMTRANS.TBL'; # makedisc calling parameters $CDoptions = '-C -R -d -s -H -b16 -L -g'; # ---------------------Do Not Edit Below This Line-------------------- $VERSION = substr '$Revision: 1.4 $ ', 11, -3; $VERSION_DATE = substr '$Date: 1999/02/23 21:46:30 $ ', 7, -3; $| = 1; # set autoflush on # Process Command Line use Getopt::Std; use vars qw( $opt_b $opt_e $opt_l $opt_s $opt_h $opt_q $opt_v $opt_V ); getopt('bels'); getopts('hqvV'); $CDbase_dir = ''; $CDbase_dir = $opt_b; $CDlabel = $opt_l; $CDnumber = $opt_s; $CDerror_log = $opt_e; $Help_Flag = $opt_h; $Quiet_Flag = $opt_q; $Verbose_Flag = $opt_v; $Version_Flag = $opt_V; # initialize variables if not defined $Help_Flag = 0 unless (defined $Help_Flag); $Quiet_Flag = 0 unless (defined $Quiet_Flag); $Verbose_Flag = 0 unless (defined $Verbose_Flag); $Version_Flag = 0 unless (defined $Version_Flag); $CDbase_dir = '' unless (defined $CDbase_dir); $CDlabel = '' unless (defined $CDlabel); $CDnumber = '' unless (defined $CDnumber); $CDerror_log = '' unless (defined $CDerror_log); $interactive_flag = 0; &usage if ($Help_Flag == 1); &version( $VERSION, $VERSION_DATE ) if ($Version_Flag == 1); if ( ($CDbase_dir eq '') || ($CDlabel eq '') || ($CDnumber eq '') ) { $interactive_flag = 1; } if (($Quiet_Flag == 1) && ($interactive_flag == 1)) { print STDERR "error: No base directory, volume name, or set number specified.\n"; print STDERR "\n You must specify base directory, volume name, and set number\n"; print STDERR " on the command line in order to use the quiet switch.\n\n"; exit(1); } $SYSerror_log = $CDerror_log unless ($CDerror_log eq ''); # Get user name $Current_user = getlogin || (getpwuid($<))[0] || "Unknown user!"; # check to see if program is in use &check_work_dir(); if ($interactive_flag == 1) { # Prompt user print "$SYSaffiliation CD mastering facility.\n\n"; print "Ready to pre-master CD (y/n)? "; $input = lc ; chop $input; exit(1) unless ( ($input eq "y") || ($input eq "yes") ); } for(;;) { &get_input() if ($interactive_flag == 1); $is_good = &error_check_input(); last if $is_good == 1; } &create_work_dir(); &write_vol_inf(); &pre_master(); &log_usage('Success'); exit(0); # exits leaving CDwork_dir in place - locking use until the CD is cut. # --------------------Subroutines--------------------------- sub check_work_dir { # If CDwork_dir exists exit, else do nothing. if( -e $SYSwork_dir ) { print STDERR "error: The work directory $SYSwork_dir exists.\n"; unless ($Quiet_Flag == 1) { print STDERR "\n Either the program is in use or an" . " error has occurred.\n"; print STDERR " If an error has occurred, remove the" . " work directory and try again.\n\n"; } exit(1); } } sub create_work_dir { # If SYSwork_dir doesn't exist, create it. Else exit. # this routine will exit if directory exists. &check_work_dir(); print " creating $SYSwork_dir..." if ($Verbose_Flag == 1); mkdir $SYSwork_dir, 0766; print " done.\n" if ($Verbose_Flag == 1); } sub get_input() { my ( $input ); # get CDbasedir $input = ""; while( $input eq "" ) { print "\nBase Directory (becomes root of cd): "; $input = ; chop $input; } $CDbase_dir = $input; # get CDlabel $input = ""; while( $input eq "" ) { print "Volume Name (no spaces): "; $input = ; chop $input; } $CDlabel = $input; # get CDnumber $input = ""; while( $input eq "" ) { print "Volume Set Number (no spaces): "; $input = ; chop $input; } $CDnumber = $input; } sub error_check_input { # returns 1 if input is good, 0 if bad, exits on q/quit selection my ( $input, $file, $path ); $CDbase_dir = glob $CDbase_dir; # shell filename expansion $CDlabel = uc $CDlabel; # make uppercase $CDnumber = uc $CDnumber; # make uppercase $CDlabel =~ tr/0-9A-Z/_/cs; # replace non-alphanumerics with underscores $CDnumber =~ tr/0-9A-Z /_/cs; if ($interactive_flag == 1) { # check to see if changes are ok print "\nBase directory $CDbase_dir\n"; print "Volume name $CDlabel\nVolume set number $CDnumber\nAll OK (y/n/q)? "; $input = lc ; chop $input; if( ($input eq "q") || ($input eq "quit") ) { exit(1); } unless ( ($input eq "y") || ($input eq "yes") ) { return 0; # return bad } } # make sure CDbasedir is a directory unless( -d $CDbase_dir ) { print STDERR "error: Base directory $CDbase_dir not found !\n"; exit(1); } # ensure SYSbase_files exist in base directory foreach $file (@SYSbase_files) { $path = $CDbase_dir.'/'.$file; unless( -e $path ) { print STDERR "error: $path not found !\n"; exit(1); } } return 1; # return good } sub write_vol_inf { my ( @Template ); # get template @Template = &get_volinf_template(); # this is not great, dependent upon stability of template $Template[4] = "VI\"$CDlabel\"\n"; $Template[5] = "VS\"$CDnumber\"\n"; # if SYSwork_dir exits write the VOLINF file if( -e $SYSwork_dir ) { print " writing volume information file..." if $Verbose_Flag == 1; open( VOLINF, ">$SYSwork_dir/volume.inf" ); print VOLINF @Template; close VOLINF; print " done.\n" if $Verbose_Flag == 1; } else { &cleanexit( "error: Work directory $SYSwork_dir not found !" ); } } sub pre_master { my ( $MDcmd_line, $cmdresult, $cmdout ); $CDoptions = $CDoptions . ' -q -w ' if ($Quiet_Flag == 1); $MDcmd_line="makedisc $CDoptions $SYSwork_dir $CDbase_dir " . "$CDtranslate_file $SYSoutput_dev $SYSoutput_dev_size"; print " sending makedisc command...\n$MDcmd_line\n" if $Verbose_Flag == 1; # send the makedisc command if ($Quiet_Flag == 1) { $cmdout = `$SYSmakedisc_path/$MDcmd_line 2>&1`; } else { $cmdout = `$SYSmakedisc_path/$MDcmd_line`; } print " done.\n" if $Verbose_Flag == 1; $cmdresult = $?; # if the command resulted in an error if( $cmdresult != 0 ) { if ($Verbose_Flag == 1) { &cleanexit( "error running makedisc:\n $cmdout" ); } else { &cleanexit( "error running makedisc command !" ); } } else { print "Pre-mastering Complete.\n" unless ($Quiet_Flag == 1); } } sub log_usage { my ( $date_string ); $date_string = scalar localtime; # append to the system log if ( -e $SYSerror_log ) { `echo $date_string $Current_user $CDbase_dir @_ >> $SYSerror_log 2>&1`; } } sub cleanexit { # print exit message arguments print STDERR "@_\n" unless ($Quiet_Flag == 1); print "Cleaning up..." unless ($Quiet_Flag == 1); &log_usage( @_ ); # remove the work directory if (-e $SYSwork_dir) { `rm -rf $SYSwork_dir 2>&1`; } print "done.\n" unless ($Quiet_Flag == 1); exit(1); } sub usage { # Show usage help and then exit my ( @message ) = @_; my ( $program ); $program = $0; $program =~ s/^.*\/([\S]+)$/$1/o; print STDERR "@message\n"; print STDERR "usage: $program [-vhqV] [-b basedir] [-l volname] [-s setnum] [-e logfile]\n"; print STDERR " -b basedir use basedir as root directory for cd\n"; print STDERR " -e logfile append usage description to logfile\n"; print STDERR " -h give this help\n"; print STDERR " -l volname specify volume name for cd\n"; print STDERR " -s setnum specify set number for cd\n"; print STDERR " -q supress all messages\n"; print STDERR " -v verbose mode\n"; print STDERR " -V display version number\n"; exit(1); } sub version { # show version info and exit my ( $ver, $ver_date ) = @_; my ( $program ); $ver = lc $ver; $ver_date = lc $ver_date; $ver =~ s/\$//g; $ver_date =~ s/\$//g; $program = $0; $program =~ s/^.*\/([\S]+)$/$1/o; print STDERR "$program $ver released on $ver_date\n"; exit(1); } sub get_volinf_template { local @volinf; @volinf = ( "CM Primary Volume Descriptor File\n", "CM Copyright 1990-1994 By Young Minds, Incorporated\n", "CM\n", "SI\"ISO 9660 RECEIVING SYSTEMS\"\n", "VI\"\"\n", "VS\"\"", "PI\"$VIpublisher\"\n", "DP\"$VIpreparer\"\n", "AI\"\"\n", "CF\"COPYRIGH.T;1\"\n", "AF\"\"\n", "BF\"\"\n", "CD\n", "MD\n" ); return (@volinf); }