#!/usr/bin/perl -w use strict; use 5.010; use utf8; use open qw/:std :utf8/; use Path::Tiny; # This script clones the template directory in $1 to $2. # Some names need munging. # $from is a populated child directory; $to is child dir to be created. $pop is the folder with the data. my ( $from, $to, $pop ) = @ARGV; my $ts = "template_stuff"; my $current = Path::Tiny->cwd; #say "current is $current"; say "-------------"; say "making directories"; # define the paths within the target directory: my $abs_to = path( $current, $to, $ts ); $abs_to->mkpath; say "abs to template is $abs_to"; # $from template directory: my $abs_from = path( $current, $from, $ts ); say "string abs from is $abs_from"; say "-------------"; say "copying files"; foreach my $child ( $abs_from->children(qr/\.(txt|pm|css|tmpl|pl|sh)$/)) { next unless $child->is_file; my $base = $child->basename; #syntax is from to to my $return = path($child)->copy( $abs_to, $base ); if ($base =~ m/\.(pl|sh)$/) { $return->chmod(0755); } say "return is $return"; } say "-------------"; # copy css file to template with munged name foreach my $child ( $abs_from->children ) { my $base = $child->basename; if ( $base =~ m/^$from(\d*)\.css$/ ) { #say "matching is $base"; say "dollar one is $1"; my $munge = $to . "1" . ".css"; say "munge is $munge"; my $name = path( $abs_to, $munge ); say "name is $name"; #syntax is from to to my $return = path( $abs_from, $base )->copy($name); say "return2 is $return"; } } ## munge and copy executable, change permissions say "-------------"; my $d = path( $current, $from ); # @matching will be an array of Path::Tiny objects my @matching = $d->children(qr/$from(\d*)\.pl$/i); @matching = sort @matching; say "matched is @matching"; my $winner = pop @matching; my $newfile = "${to}1.pl"; my $b = path( $current, $to, $newfile ); print "b is $b\n"; # $winner will already be a Path::Tiny object my $return3 = $winner->copy("$b"); say "return3 is $return3"; $return3->chmod(0755); say "end of clone"; my $abs_pop = path( $current, $pop, $ts ); say "string abs pop is $abs_pop"; my $string_pop = "$abs_pop"; foreach my $child ( $abs_pop->children ) { next unless $child->is_dir; say "e is $child"; my $base_dir = $child->basename; say "base dir is $base_dir"; my $folder = path( $current, $to, $ts, $base_dir )->mkpath; say "folder is $folder"; my $string_folder = path( $current, $to, $ts, $base_dir )->stringify; say "string folder is $string_folder"; my $pop_from = $child; next if( $child =~ m/logs/); foreach my $pchild ( $pop_from->children ) { say "default is $pchild\n"; my $base = $pchild->basename; say "base is $base"; my $to_name = path( $string_folder, $base ); say "to name is $to_name"; my $return4 = path($pchild)->copy($to_name); say "return4 is $return4"; } } my $exec_path = path( $current, $to ); my $return5 = chdir($exec_path); say "return5 is $return5"; system("pwd "); system("ls "); system ("./$newfile "); #### $ ./10.clone.pl 2.med 1.qy 1.pop ------------- making directories abs to template is /home/bob/1.scripts/pages/1.qy/template_stuff string abs from is /home/bob/1.scripts/pages/2.med/template_stuff ------------- copying files return is /home/bob/1.scripts/pages/1.qy/template_stuff/5.unicode1.css ... return is /home/bob/1.scripts/pages/1.qy/template_stuff/code1.tmpl ------------- dollar one is 1 munge is 1.qy1.css name is /home/bob/1.scripts/pages/1.qy/template_stuff/1.qy1.css return2 is /home/bob/1.scripts/pages/1.qy/template_stuff/1.qy1.css ------------- matched is /home/bob/1.scripts/pages/2.med/2.med1.pl b is /home/bob/1.scripts/pages/1.qy/1.qy1.pl return3 is /home/bob/1.scripts/pages/1.qy/1.qy1.pl end of clone string abs pop is /home/bob/1.scripts/pages/1.pop/template_stuff e is /home/bob/1.scripts/pages/1.pop/template_stuff/ruscaptions base dir is ruscaptions folder is 1 string folder is /home/bob/1.scripts/pages/1.qy/template_stuff/ruscaptions default is /home/bob/1.scripts/pages/1.pop/template_stuff/ruscaptions/a.txt base is a.txt to name is /home/bob/1.scripts/pages/1.qy/template_stuff/ruscaptions/a.txt return4 is /home/bob/1.scripts/pages/1.qy/template_stuff/ruscaptions/a.txt default is /home/bob/1.scripts/pages/1.pop/template_stuff/ruscaptions/b.txt base is b.txt to name is /home/bob/1.scripts/pages/1.qy/template_stuff/ruscaptions/b.txt return4 is /home/bob/1.scripts/pages/1.qy/template_stuff/ruscaptions/b.txt e is /home/bob/1.scripts/pages/1.pop/template_stuff/logs base dir is logs folder is 1 string folder is /home/bob/1.scripts/pages/1.qy/template_stuff/logs e is /home/bob/1.scripts/pages/1.pop/template_stuff/aimages base dir is aimages folder is 1 string folder is /home/bob/1.scripts/pages/1.qy/template_stuff/aimages default is /home/bob/1.scripts/pages/1.pop/template_stuff/aimages/b.png base is b.png to name is /home/bob/1.scripts/pages/1.qy/template_stuff/aimages/b.png return4 is /home/bob/1.scripts/pages/1.qy/template_stuff/aimages/b.png default is /home/bob/1.scripts/pages/1.pop/template_stuff/aimages/a.png base is a.png to name is /home/bob/1.scripts/pages/1.qy/template_stuff/aimages/a.png return4 is /home/bob/1.scripts/pages/1.qy/template_stuff/aimages/a.png e is /home/bob/1.scripts/pages/1.pop/template_stuff/captions base dir is captions folder is 1 string folder is /home/bob/1.scripts/pages/1.qy/template_stuff/captions default is /home/bob/1.scripts/pages/1.pop/template_stuff/captions/a.txt base is a.txt to name is /home/bob/1.scripts/pages/1.qy/template_stuff/captions/a.txt return4 is /home/bob/1.scripts/pages/1.qy/template_stuff/captions/a.txt default is /home/bob/1.scripts/pages/1.pop/template_stuff/captions/b.txt base is b.txt to name is /home/bob/1.scripts/pages/1.qy/template_stuff/captions/b.txt return4 is /home/bob/1.scripts/pages/1.qy/template_stuff/captions/b.txt return5 is 1 /home/bob/1.scripts/pages/1.qy 1.qy1.pl template_stuff path1 is /home/bob/1.scripts/pages/1.qy base is 1.qy values are home349337426.1and1-data.host redacted redacted object created, back in main word is 1.qy dir2 is perlmonks files are old num is 0 remote_dir is 1.qy1 dir is /home/bob/1.scripts/pages/1.qy/template_stuff/captions dir is /home/bob/1.scripts/pages/1.qy/template_stuff/ruscaptions tmpl is /home/bob/1.scripts/pages/1.qy/template_stuff/code2.tmpl tmpl is /home/bob/1.scripts/pages/1.qy/template_stuff/code3.tmpl mkdir1 failed path3 is /home/bob/1.scripts/pages/1.qy/template_stuff/1.qy1.css mkdir2 failed /pmimage/1.qy1 a is /home/bob/1.scripts/pages/1.qy/template_stuff/aimages/a.png b is a.png a is /home/bob/1.scripts/pages/1.qy/template_stuff/aimages/b.png b is b.png new file is 1.qy1.html $