#! /usr/local/bin/perl # addP4User.pl ######################################################################## ######################################################################## # ADD NEW PERFORCE USER # # Programmed by David Weintraub # Date: 13-Dec-2005 # Purpose: To help setup a new Windows User in one easy step # ######################################################################## ######################################################################## # PRAGMAS # use lib qw(/home/merbld/etc/perl); use strict; use warnings; use vars; # ######################################################################## ######################################################################## # MODULES # use Config; use Getopt::Long; use FormInfo; use File::Basename; # ######################################################################## ######################################################################## # CONSTANTS # *P4_SOLARIS = \"/home/merbld/bin/sparc-sunos/p4"; our $P4_SOLARIS; *P4_LINUX = \"/home/merbld/bin/i686-linux/p4"; our $P4_LINUX; *MAIL_LINUX=\"/bin/mail"; our $MAIL_LINUX; *MAIL_SOLARIS=\"/usr/bin/mailx"; our $MAIL_SOLARIS; if ($Config{"osname"} eq "linux") { *P4 = \"$P4_LINUX"; *MAIL_CMD = \"$MAIL_LINUX" } else { *P4 = \"$P4_SOLARIS"; *MAIL_CMD = \"$MAIL_SOLARIS"; } our $P4; our $MAIL_CMD; *CLEAR_CMD = \"clear"; our $CLEAR_CMD; *P4_SERVER = \"merlin-perforce:1666"; our $P4_SERVER; *P4_GROUPS_CMD = \"$P4 groups"; our $P4_GROUPS_CMD; *P4_GROUP_CMD = \"$P4 group"; our $P4_GROUP_CMD; *P4_USER_CMD = \"$P4 user"; our $P4_USER_CMD; *P4_CLIENT_CMD = \"$P4 client"; our $P4_CLIENT_CMD; *BOFA_DOMAIN = \"bofasecurities.com"; our $BOFA_DOMAIN; *TEMP_FILE = \"addUser.temp.$$"; our $TEMP_FILE; *SUBJECT = \"Perforce and You. Perfect Together"; our $SUBJECT; *MAIL_CC = \("David.Weintraub\@bofasecurities.com " . "Anthony.C.Pagliazzo\@bofasecurities.com"); our $MAIL_CC; # ######################################################################## ######################################################################## # USAGE # my $USAGE=<] [-name ] [-email ] Where: : User's Perforce ID (Should be Bank's NBK ID) : Full Name of User : User's Email Address USAGE # ######################################################################## ######################################################################## # VARIABLES # my $nbkId; my $userName; my $emailAddress; my $p4Group; my $p4WorkDir; my $p4Client; my $p4; my $help; # ######################################################################## ######################################################################## # GET COMMAND LINE OPTIONS # GetOptions ( "user=s" => \$nbkId, "name=s" => \$userName, "email=s" => \$emailAddress, "help" => \$help ) or die "$USAGE\n"; if ($help) { print "$USAGE\n"; exit 0; } ######################################################################## # GET NEEDED INPUTS # for (;;) { unless ($nbkId) { print "User's NBK ID: "; chomp ($nbkId = ); } unless ($userName) { print "User's Name: "; chomp ($userName = ); } unless ($emailAddress) { print "Email Address: "; chomp ($emailAddress = ); unless ($emailAddress) { ($emailAddress = $userName) =~ s/ /./g; } } $emailAddress .= "\@" . "$BOFA_DOMAIN" if ($emailAddress !~ /\@/); $p4Group = ""; while (not ($p4Group)) { system("$CLEAR_CMD"); print "Which Group Does the User Belong to?\n"; open(GROUPS, "$P4_GROUPS_CMD|") or die qq(Couldn't execute command "$P4_GROUPS_CMD"\n); my $groupNum; my @groupList; $groupNum = 1; while (my $group = ) { chomp ($group); print "\t$groupNum). $group\n"; $groupList[$groupNum] = "$group"; $groupNum++; } print "\nSELECTION: "; chomp (my $answer = ); next if (not defined($groupList[$answer])); $p4Group = $groupList[$answer]; } # ######################################################################## ######################################################################## # VERIFY ANSWERS # my $answer; for (;;) { system ($CLEAR_CMD); print "Is the following Correct?\n"; print qq(\tUser's NBK ID = "$nbkId"\n); print qq(\tUser's Name = "$userName"\n); print qq(\tUser's Email = "$emailAddress"\n); print qq(\tUser's Group = "$p4Group"\n); print "\nCorrect? "; chomp ($answer = ); last if ($answer =~ /^(y|n)/i); } last if ($answer =~ /^y/i); undef $nbkId; undef $userName; undef $emailAddress; } # ######################################################################## ######################################################################## # CREATE PASSWORD # my $password = sprintf("%s-%x", $nbkId, time); # ######################################################################## ######################################################################## # CREATE PERFORCE USER # { my %userHash; $userHash{"User"} = $nbkId; $userHash{"Email"} = $emailAddress; $userHash{"FullName"} = $userName; formWrite("user -f", \%userHash); my $error = system(qq(p4 passwd -P $password $nbkId)); if ($error) { print "WARNING: Password is not set!\n"; } } # ######################################################################## ######################################################################## # ADD USER TO GROUP # { my %groupHash; formRead("group", "$p4Group", \%groupHash); $groupHash{"Users"} .="\n" . "$nbkId"; formWrite("group", \%groupHash); } # ######################################################################## ######################################################################## # CREATE PERFORCE CLIENT # { my (%clientHash, $description, $altRoot, $view); if ($p4Group eq "unix") { $p4Client = "$nbkId-unix"; $description = "Default Main Branch Client Unix View for"; $p4WorkDir = "/home/$nbkId/p4clients/unix"; $altRoot = 'U:\p4clients\unix'; $view = "//depot/Efp/Unix/Apps/*/MAIN/... //$p4Client/apps/*/...\n" . "//depot/Efp/Unix/Libs/*/MAIN/... //$p4Client/libs/*/..."; } elsif ($p4Group eq "statarb") { $p4Client = "$nbkId-statarb"; $description = "Default Main Branch StatArb View for"; $p4WorkDir = 'C:\p4clients\statarb'; $view = "//depot/Statarb/MAIN/... //$p4Client/..."; } elsif ($p4Group eq "FASL") { $p4Client = "$nbkId-fasl"; $description = "Default ROOT Branch FASL View for"; $p4WorkDir = 'C:\p4clients\fasl'; $view = "//depot/Efp/Fasl/... //$p4Client/..."; } else { #Group is Efp Main Group $p4Client = "$nbkId-default"; $description = "Default Efp Root Client View"; $p4WorkDir = 'C:\p4clients\default'; $view = "//depot/*/Assembly/... //$p4Client/*/Assembly/...\n" . "//depot/*/Tools/... //$p4Client/*/Tools/...\n" . "//depot/*/Components/... //$p4Client/*/Components/...\n" . "//depot/DevelopmentTools/... //$p4Client/DevelopmentTools/..."; } $clientHash{"Client"} = $p4Client; $clientHash{"Owner"} = $nbkId; $clientHash{"Description"} = $description; $clientHash{"Description"} .= "\n" . "for $userName ($nbkId)"; $clientHash{"Root"} = $p4WorkDir; $clientHash{"AltRoots"} = $altRoot if ($altRoot); $clientHash{"View"} = $view; formWrite("client", \%clientHash); } # ######################################################################## ######################################################################## # EMAIL USER INSTRUCTIONS ABOUT SETTING THEIR P4PORT # open (MAIL, qq(|$MAIL_CMD -c "$MAIL_CC" -s "$SUBJECT" $emailAddress)) or die qq(Can't mail user "$emailAddress"\n); print MAIL < Directions can be found at: <\\\\crprdndfs01\\DS_DFS\\Equities\\Global Equities Technology\\ED_APPS\\Merlin\\Perforce\\README.txt> Your Perforce client was setup, assuming your Unix HOME directory is mapped to your "U:" drive. If it isn't, run the following command from a Windows Console Window: \$ net use /PERSISTENT \$ net use U: \\\\njefpdcs1\\$nbkId You can also use the Cygwin client on your PC if you have Cygwin installed. The Cygwin client is only available from the command line. This is available from Perforce at: PERFORCE BUILT IN HELP ====================== Perforce has built in help by simply typing: \$ p4 help at the command line. To get a list of the basic commands, do: \$ p4 help simple To get a listing of all the commands, type: \$ p4 help commands To get help on a specific command, type: \$ p4 help where is the name of the Perforce command. The documentation for Perforce is located at: <\\\\crprdndfs01\\ds_dfs\\Equities\\Global Equities Technology\\ED_APPS\\Merlin\\Perforce\\Documentation\\Perforce User's Guide.pdf> More information about Perforce can be found on our Wiki: This also includes a CVS vs. Subversion vs. Perforce command chart: MAIL } else { print MAIL < Installation instructions are found in <\\\\crprdndfs01\\DS_DFS\\Equities\\Global Equities Technology\\ED_APPS\\Merlin\\Perforce\\README.txt> 2). After you've installed, Perforce on your PC, you will need to create a directory called "$p4WorkDir". This will be your working directory where Perforce will download the files from its depot for you to work on. 3). You will also need to know the name of your default Perforce Client which you'll need when you sign into P4V. Your default Perforce Client is: "$p4Client". 4). You will need to add a few entries into your Windows Registry file. Copy the lines that appear between the rows of equal signs (but not including the row of equal signs), and paste them into a file. ============================================================ REGEDIT4 [HKEY_CURRENT_USER\\Software\\perforce\\environment] "P4PORT"="$P4_SERVER" "P4CONFIG"="_p4rc" "P4CLIENT"="$p4Client" ============================================================ Call this file "perforce.reg" and place this file on your desktop. Now, double click on this file. This should set the needed Perforce registry entries for you. 5). Finally, you need to know your password. Your randomly assigned password is "$password". You can change your password to something a bit easier to remember by going into P4V and selecting "Change Password" from the "Connection" menu. 6). If you are using VisualStudio, and want to integrate Perforce into VisualStudio, you will need to read the following step-by-step instructions: <\\\\crprdndfs01\\DS_DFS\\Equities\\Global Equities Technology\\ED_APPS\\Merlin\\Perforce\\Documentation\\Perforce-VisualStudio Integration.pdf"> and <\\\\crprdndfs01\\DS_DFS\\Equities\\Global Equities Technology\\ED_APPS\\Merlin\\Perforce\\Documentation\\EFP Perforce Documentation\\Mapping a Perforce Client into VisualStudio.doc> MAIL } print MAIL <