Skip Menu |

This queue is for tickets about the Perl-Dist-Strawberry CPAN distribution.

Report information
The Basics
Id: 51003
Status: resolved
Priority: 0/
Queue: Perl-Dist-Strawberry

People
Owner: csjewell [...] cpan.org
Requestors: csjewell [...] cpan.org
Cc: matthew.persico [...] gmail.com
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



CC: matthew.persico [...] gmail.com
Subject: Adding script to .zip versions to set environment variables permanently.
From IRC on 10/31/2009: (Times are U.S. Mountain Daylight) [05:06] <mpersico> Good morning, at least in the Americas [05:07] <mpersico> I am looking at a deploement of strawberry using the relocatble version [05:07] <mpersico> Now, I guess that the MSI version goes through the trouble of makeing [05:08] <mpersico> Registry entries that alter environment variables - PATH, INCLUDE and LIB [05:08] <mpersico> The relocatable version does not. [05:08] <mpersico> How hard would it be to include a Perl script that does that editing for you [05:09] <mpersico> with the relocatable version [05:09] <mpersico> something like [05:09] <mpersico> get pwd [05:09] <mpersico> build PATH, INCULDE and LIB entries for the strawberry bits [05:09] <mpersico> open the registry using the Win32::Registry module? [05:09] <mpersico> modify the registry [05:10] <mpersico> Doable? [05:10] <mpersico> matthew dot persico at gmail dot com Doable. Tracking it with this bug.
RT-Send-CC: matthew.persico [...] gmail.com
Hi,

please find eclosed proof-of-concept for permanently updating PATH via perl script.

The questions are:

1/ is this approach acceptable?

2/ what other ENV variables apart from PATH we want fo update? (TERM?)

3/ where to put this code? (maybe we can add some special option --update-env to relocation.pl)

--
kmx
Subject: update_path.pl.pl
use strict; use warnings; use Win32::TieRegistry qw[:KEY_]; #the following items will be added to PATH my @items_to_add = qw[c:\strawberry\c\bin c:\strawberry\perl\bin]; my $hklm_env = Win32::TieRegistry->new( 'HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Environment', { Access => KEY_READ() | KEY_WRITE(), Delimiter => '/' } ); # returns undef if SYSTEM ENV not writable my $hkcu_env = Win32::TieRegistry->new( 'HKEY_CURRENT_USER/Environment', { Access => KEY_READ() | KEY_WRITE(), Delimiter => '/' } ); # if SYSTEM ENV not writable try USER ENV my $e = defined($hklm_env) ? $hklm_env : $hkcu_env; if(defined $e) { my $path = $e->GetValue('Path'); foreach my $i (@items_to_add) { $path = "$path;$i" unless $path =~ /\Q$i\E/; } $e->SetValue('Path', $path); } else { warn "Cannot open neither SYSTEM ENV nor USER ENV registry for Read+Write"; }
On Tue May 04 20:30:45 2010, KMX wrote: Show quoted text
> Hi, > > please find eclosed proof-of-concept for permanently updating PATH via > perl > script. > > The questions are: > > 1/ is this approach acceptable? > > 2/ what other ENV variables apart from PATH we want fo update? (TERM?) > > 3/ where to put this code? (maybe we can add some special option > --update-env > to relocation.pl)
1/ It's a start. (It's the way I'd do it - and did for the local::lib script.) Note 4 - 8 below, as well. 2/ Yes, TERM. Anything we tell them to set in the README needs to be set by this script. 3/ This would be copied to c:\strawberry\perl\bin, and we'd copy runperl.bat to update_environment.bat, (with the part before the .bat being what we called it before the .pl) as well, to make it a batch file (or at least, callable by one. What runperl.bat does is documented in perlwin32.pod.) 4/ ...\perl\site\bin needs to be added to the path entries, by the way. 5/ It really needs a --directory option as well [5.12 DOES relocate, after all] which means it needs some pod, and the --man, --help/-?, --usage, and --version standard options to go with it. Again, see what I did with relocation.pl as to how I implement those. You may wish to do it a little differently. I also prefer to set a $VERSION in scripts, even though it's not 'required', so other people know when the script has been updated, and to use in my own 'print' statements. I think the --directory option would take the place of an --update-env option to the relocation script - or maybe the relocation script can have that option and call this script to do it. (the .msi relocates the path all by itself already, so yes, it needs to be an option.) I know all the options may seem complicated for a small script, but the man/usage/help/version options are the 4 'meta-options' recommended by /PBP/ for scripts, and that are used in non-interactive GNUish programs. Once I include any options at all, I include those 4. (I consider interactive scripts to have different rules apply to them.) An option to remove the directory entries (--remove ?) is nice, but not absolutely REQUIRED, I wouldn't think. Note that I assume Getopt::Long and Pod::Usage, which are both core. 6/ One major problem - it won't affect the right registry locations when you run a 32-bit perl on a 64-bit system, because 32-bit apps are redirected by default. The way to turn that off is shown in http://svn.ali.as/cpan/trunk/App-local-lib-Win32Helper/script/llw32helper.pl , where the access ends up being KEY_READ() | KEY_WRITE()| 256 # KEY_WOW64_64KEY, so that the redirection is turned off. 7/ Print something on success, unless a --quiet option is given. I would worry about what a script did if it ran successfully, but printed NOTHING out, unless I asked it not to print anything. The --quiet would be how I asked it. 8/ The script should check to see if each PATH entry is already there before it adds an entry. If you get this done for 5.12.0.1 (the 5.12.0 rebuild), it'd be fantastic, but I know that allows you very little time (as in only 2 days or so) to do it, so don't feel like you have to rush to get it in on time, OK? Keep up the good work.
I'm including an updated version of it as a .pl in r12310. We can't make it a .bat file by the "standard methods", either by running it through pl2bat or copying runperl.bat, because both those methods assume perl is already IN the path. It would create a "Which came first, the chicken, or the egg?" problem. And again, this is a script that should only need to be run once, so why have it as a batch file?