# $Id$
use Config;
use File::Basename qw(basename dirname);
chdir(dirname($0));
($file = basename($0)) =~ s/\.PL$//;
$file =~ s/\.pl$//
        if ($Config{'osname'} eq 'VMS' or
            $Config{'osname'} eq 'OS2');  # "case-forgiving"
open OUT,">$file" or die "Can't create $file: $!";
chmod(0755, $file);
print "Extracting $file (with variable substitutions)\n";

print OUT <<"!GROK!THIS!";
$Config{'startperl'} -w
    eval 'exec perl -S \$0 "\$@"'
        if 0;

!GROK!THIS!

print OUT <<'!NO!SUBS!';

use strict;
use warnings;
use Sys::Hostname;
use IO::File;
print "Enter password: ";
my $password  = (<>);
my $encrypted = crypt( $password, $password );
if ( crypt( $password, $encrypted ) eq $encrypted ) {
	print "Encryption OK, writing...";
	{
		my $PWFILE = $ENV{'HOME'} . '/cipres/' . hostname() . '_regsrv.pwd';
		my $PWFH   = IO::File->new;
		$PWFH->autoflush( 1 );
		$PWFH->open( "> $PWFILE" ) or die "Couldn't open $PWFILE";
		$PWFH->print( $encrypted ) or die "Couldn't print to $PWFILE";
		$PWFH->close               or die "Couldn't close $PWFILE";
	}
	print "OK\n";
	exit 0;
}
else {
	die "Encryption failed!";
}

!NO!SUBS!
