#!/usr/local/bin/perl
#
# This script Configures PilotMail after prompting for path names
#

$Debug = 0;             # When the $Debug option is zero, no debug 
                        # statements are executed.

$MemoFileName = "TempFile";
$MailFileName = "TempFile2";

print ("Welcome to PilotMail!\n");
print ("To use this configuration file, you must know the path to your\n");
print ("perl (usually something like /usr/local/bin/perl), the path to\n");
print ("your sendmail (usually something like /usr/lib/sendmail), and you\n");
print ("should specify fully qualified pathnames\n\n");
                        # Instructions for the user

print ("What is the path to perl (the file, not just the directory)? ");
$PerlPath = <STDIN>;
chop ($PerlPath);

print ("What is the path to sendmail (the file, not just the directory)? ");
$SendmailPath = <STDIN>;
chop ($SendmailPath);

print ("What is the path where I can put temporary files during mail operations\n");
print ("(this time just the directory and leave off the trailing '/')? ");
$TempPath = <STDIN>;
chop ($TempPath);

$MemoFilePath = join ('/', $TempPath, $MemoFileName);
chop ($MemoFileName);
$MailFilePath = join ('/', $TempPath, $MailFileName);
chop ($MailFileName);

print ("Choose a Subject line for the email sent from your pilot (in the \n");
print ("future, this will be replaced with a seubject from the actual mail\n");
print ("on the pilot, but for now it is not yet implemented -- something like\n");
print ("'Mail From Matt's Pilot' or something): ");
$GenericSubject = <STDIN>;
chop ($GenericSubject);

print ("Now give me the path to pilot link's 'memos' file (the file, not\n");
print ("just the directory): ");
$MemosPath = <STDIN>;
chop ($MemosPath);

print ("And finally the device path to pass to memos (like /dev/ttya): ");
$DevicePath = <STDIN>;
chop ($DevicePath);

open (FILE, "PrePilotMail");
                        # open the generic Pilot file

open (FILE2, ">PilotMail");
                        # open PilotMail

while (<FILE>)          # While we are in the generic Pilot file...
{
    if ($_ =~ /<PathToPerl>/)
    {
      $_ =~ s/<PathToPerl>/$PerlPath/g;
    }

    if ($_ =~ /<PathToSendmail>/)
    {
      $_ =~ s/<PathToSendmail>/$SendmailPath/g;
    }

    if ($_ =~ /<PathToTempMemoFile>/)
    {
      $_ =~ s/<PathToTempMemoFile>/$MemoFilePath/g;
    }

    if ($_ =~ /<PathToTempMailFile>/)
    { 
      $_ =~ s/<PathToTempMailFile>/$MailFilePath/g;
    }

    if ($_ =~ /<GenericSubjectLine>/)
    {
      $_ =~ s/<GenericSubjectLine>/$GenericSubject/g;
    }

    if ($_ =~ /<PathToMemos>/)
    {
      $_ =~ s/<PathToMemos>/$MemosPath/g;
    }

    if ($_ =~ /<PathToDevice>/)
    {
      $_ =~ s/<PathToDevice>/$DevicePath/g;
    }
    print (FILE2 "$_");
next;
}

close (FILE);           # close PrePilotMail file like a responsible adult
close (FILE2);          # close PilotMail file like a responsible adult

system ('chmod 700 PilotMail');
                        # Make PilotMail readable/writeable and executable


exit;                   # Say "Good night," Gracie.
 
