#!/usr/bin/perl ########################################### # subsilvercp # 2006, Mike Schilli ########################################### use strict; use warnings; use Getopt::Std; use Pod::Usage; use Sysadm::Install qw(:all); use Log::Log4perl qw(:easy); use File::Find; use File::Spec; use File::Basename; use Cwd; my $VERSION = "1.0"; Log::Log4perl->easy_init({level => $DEBUG, file => "stdout"}); my($src_dir, $dst_dir) = @ARGV; if(!defined $dst_dir) { $src_dir = "subSilver"; $dst_dir = $ARGV[0]; } if(! defined $dst_dir) { pod2usage(); } if(! -d $src_dir) { pod2usage("Source directory doesn't exist"); } if(-d $dst_dir) { LOGDIE "Cowardly refusing to overwrite existing " . "destination dir $dst_dir"; } my $src_dir_rel = $src_dir; my $src_basename = basename $src_dir; my $dst_basename = basename $dst_dir; $src_dir = File::Spec->rel2abs($src_dir); $dst_dir = File::Spec->rel2abs($dst_dir); my $cwd = getcwd(); mkd $dst_dir; find(sub { if(-d $_) { INFO "mkdir $dst_dir/$File::Find::name"; mkd "$dst_dir/$File::Find::name"; return 1; } my $relname = $File::Find::name; $relname =~ s/.*?\///; if(-f $_) { my $src_file = "$src_dir/$relname"; my $dst_dir = dirname "$dst_dir/$relname"; my $dst_file = $_; if($dst_file =~ /^$src_basename\./) { $dst_file =~ s/$src_basename(?=\.)/$dst_basename/g; } mkd $dst_dir unless -d $dst_dir; INFO "cp $src_file $dst_dir/$dst_file"; cp $src_file, "$dst_dir/$dst_file"; } }, "$src_dir_rel"); # fix theme_info.cfg find(sub { return if ! -f or ! -T; pie(sub { s/\b$src_basename\b/$dst_basename/g; $_; }, $_); }, $dst_dir); __END__ =head1 NAME subsilvercp - Make a copy of phpbb template directory =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS $ cd templates # Create a new template dir named 'newName', # based on 'subSilver' $ subsilvercp newName =head1 DESCRIPTION C creates a new phpbb template directory parallel to the default 'subSilver' hierarchy. It not only copies everything to the new directory, but also renames a couple of files and replaces instances of the string 'subSilver' in various files: subSilver/ newName/ theme_info.cfg theme_info.cfg subSilver.cfg newName.cfg ... ... Be careful when choosing a new name, make sure it doesn't contain special characters, and it's long enough to not collide with some variable name in phpbb. When you're done, there's a new template directory under templates. To install it, go to phpbb's admin page, select "Style Add" and click "Install". Then, go to the "Configuration" panel, scroll down to "Default Style" and select the new style from the dropdown list. Also, check "Yes" on "Override user style" to make sure users get the new style. =head1 LEGALESE Copyright 2006 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR 2006, Mike Schilli