1#! perl -w 2# 3# TWiki Collaboration Platform, http://TWiki.org/ 4# 5# Copyright (C) 2005-2018 TWiki Contributors. 6# All Rights Reserved. TWiki Contributors are listed in 7# the AUTHORS file in the root of this distribution. 8# NOTE: Please extend that file, not this notice. 9# 10# For licensing info read license.txt file in the TWiki root. 11# This program is free software; you can redistribute it and/or 12# modify it under the terms of the GNU General Public License 13# as published by the Free Software Foundation; either version 3 14# of the License, or (at your option) any later version. 15# 16# This program is distributed in the hope that it will be useful, 17# but WITHOUT ANY WARRANTY; without even the implied warranty of 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19# GNU General Public License for more details, published at 20# http://www.gnu.org/copyleft/gpl.html 21# 22# HELP 23print <<'END'; 24Change the "shebang" lines of all perl scripts found in the current 25directory. 26 27"shebang" lines tell the shell what interpreter to use for running 28scripts. By default the TWiki bin scripts are set to user the 29"/usr/bin/perl" interpreter, which is where perl lives on most 30UNIX-like platforms. On some platforms you will need to change this line 31to run a different interpreter e.g. "D:\indigoperl\bin\perl" 32or "/usr/bin/speedy" 33 34This script will change the "shebang" lines of all scripts found in 35the directory where the script is run from. 36 37Note: the path to the interpreter *must not* contain any spaces. 38END 39 40use strict; 41 42my $new = 'perl'; 43$/ = "\n"; 44 45while (1) { 46 print "Enter path to interpreter [hit enter to choose '$new']: "; 47 my $n = <>; 48 chomp $n; 49 last if( !$n ); 50 $new = $n; 51}; 52 53unless( -x $new ) { 54 print "Warning: I could not find an executable at $new 55Are you sure you want to use this path (y/n)? "; 56 my $n = <>; 57 die "Aborted" unless $n =~ /^y/i; 58} 59 60my $changed = 0; 61my $scanned = 0; 62opendir(D, ".") || die $!; 63foreach my $file (grep { -f && /^\w+$/ } readdir D) { 64 $scanned++; 65 $/ = undef; 66 open(F, "<$file") || die $!; 67 my $contents = <F>; 68 close F; 69 70 if( $contents =~ s/^#!\s*\S+/#!$new/s ) { 71 open(F, ">$file") || die $!; 72 print F $contents; 73 close F; 74 print "$file modified\n"; 75 $changed++; 76 } else { 77 print "$file modified\n"; 78 } 79} 80closedir(D); 81print "$changed of $scanned files changed\n"; 82