-
Notifications
You must be signed in to change notification settings - Fork 10
/
make_mine
executable file
·97 lines (76 loc) · 1.87 KB
/
make_mine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::Path;
use File::Basename;
use Cwd;
# get the directory where this script is
my $script_directory = dirname($0);
# point to the skeletons to make a basic mine
my $STRUCTURE_DIR = "$script_directory/skeletons/mine";
sub usage
{
my $message = shift;
die <<"MESSAGE";
$0: $message
usage:
$0 <mine-name>
The mine will be created in directory with a lowercase name
eg. $0 FooMine
will create a directory called foomine
MESSAGE
}
if (@ARGV != 1) {
usage (<<USAGE);
needs one argument
USAGE
}
my $mine_name = shift;
$mine_name = lc $mine_name;
my $mine_dir = lc $mine_name;
my %substitutions = (
'mineInstanceName' => $mine_name
);
# will create mine in current directory
my $start_dir = getcwd;
my $new_mine_dir = "$start_dir/$mine_dir";
if (-e $new_mine_dir) {
usage (<<MESSAGE);
$new_mine_dir already exists
MESSAGE
}
sub process
{
my $orig_path = $_;
my $dest_path = $File::Find::name;
$dest_path =~ s:$STRUCTURE_DIR(.*):$new_mine_dir$1:;
if (-d $orig_path) {
mkpath($dest_path);
} else {
open my $orig, '<', $orig_path or die "can't open $orig_path: $!\n";
open my $dest, '>', $dest_path or die "can't open $dest_path: $!\n";
while (my $line = <$orig>) {
for my $subs_key (keys %substitutions) {
$line =~ s/\$\{$subs_key\}/$substitutions{$subs_key}/g;
}
print $dest $line;
}
close $orig or die "can't close $orig_path: $!\n";
close $dest or die "can't close $dest_path: $!\n";
# make the ./gradlew file executable
if ($_ eq "gradlew") {
chmod 0777, $dest_path;
}
}
}
sub preprocess
{
return grep {$_ !~ /^(\.svn|.*~)$/} @_;
}
find({
wanted => \&process,
preprocess => \&preprocess
},
$STRUCTURE_DIR);
warn "created $new_mine_dir directory for $mine_name\n";