2007-04-12 20:24:50 +00:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
# create-module.pl
|
|
|
|
# Creates a single .wbm file containing multiple modules, possibly with
|
|
|
|
# forced versions
|
|
|
|
|
|
|
|
@ARGV >= 2 || die "usage: create-module.pl [--dir name] <file.wbm> <module>[/version] ..";
|
|
|
|
|
2017-05-15 18:21:59 -07:00
|
|
|
my $pwd;
|
2007-04-12 20:24:50 +00:00
|
|
|
chop($pwd = `pwd`);
|
|
|
|
|
|
|
|
# Parse command-line options
|
2017-05-15 18:21:59 -07:00
|
|
|
my @exclude;
|
2009-07-20 18:56:26 +00:00
|
|
|
while(@ARGV) {
|
|
|
|
if ($ARGV[0] eq "--dir") {
|
|
|
|
shift(@ARGV);
|
|
|
|
$forcedir = shift(@ARGV);
|
|
|
|
}
|
|
|
|
elsif ($ARGV[0] eq "--sign") {
|
|
|
|
shift(@ARGV);
|
|
|
|
$createsig = 1;
|
|
|
|
}
|
2023-08-30 20:10:01 -07:00
|
|
|
elsif ($ARGV[0] eq "--key") {
|
|
|
|
shift(@ARGV);
|
|
|
|
$keyname = shift(@ARGV);
|
|
|
|
}
|
2017-05-15 18:21:59 -07:00
|
|
|
elsif ($ARGV[0] eq "--exclude") {
|
|
|
|
shift(@ARGV);
|
|
|
|
push(@exclude, shift(@ARGV));
|
|
|
|
}
|
2009-07-20 18:56:26 +00:00
|
|
|
else {
|
|
|
|
last;
|
|
|
|
}
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-15 18:21:59 -07:00
|
|
|
my $file = shift(@ARGV);
|
2007-04-12 20:24:50 +00:00
|
|
|
if ($file !~ /^\//) {
|
|
|
|
$file = "$pwd/$file";
|
|
|
|
}
|
|
|
|
unlink($file);
|
2017-05-15 18:21:59 -07:00
|
|
|
foreach my $m (@ARGV) {
|
2007-04-12 20:24:50 +00:00
|
|
|
# Parse module and forced version
|
|
|
|
$m =~ s/\/$//;
|
|
|
|
if ($m =~ /^(.*)\/(.*)$/) {
|
|
|
|
$mod = $1;
|
|
|
|
$ver = $2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$mod = $m;
|
|
|
|
$ver = undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy module to temp dir
|
|
|
|
system("rm -rf /tmp/create-module");
|
|
|
|
mkdir("/tmp/create-module", 0755);
|
|
|
|
$subdir = $forcedir || $mod;
|
|
|
|
$copydir = "/tmp/create-module/$subdir";
|
|
|
|
system("rm -rf $copydir");
|
2010-11-28 13:24:42 -08:00
|
|
|
system("cp -r -L $mod $copydir 2>/dev/null || cp -R -L $mod $copydir");
|
2017-05-15 18:21:59 -07:00
|
|
|
foreach my $e (@exclude) {
|
|
|
|
system("find $copydir -name ".quotemeta($e)." | xargs rm -rf");
|
|
|
|
}
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
# Find type from .info file
|
|
|
|
undef(%minfo);
|
|
|
|
if (&read_file($ifile = "$copydir/module.info", \%minfo)) {
|
|
|
|
$type = 0;
|
|
|
|
}
|
|
|
|
elsif (&read_file($ifile = "$copydir/theme.info", \%minfo)) {
|
|
|
|
$type = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "Module or theme $mod not found";
|
|
|
|
}
|
|
|
|
if ($ver) {
|
|
|
|
$minfo{'version'} = $ver;
|
|
|
|
&write_file($ifile, \%minfo);
|
|
|
|
}
|
|
|
|
$flags = !-r $file ? "chf" : "rhf";
|
|
|
|
system("cd /tmp/create-module && find . -name .svn | xargs rm -rf");
|
2016-01-21 22:40:09 -08:00
|
|
|
system("cd /tmp/create-module && find . -name .git | xargs rm -rf");
|
|
|
|
system("cd /tmp/create-module && find . -name .build | xargs rm -rf");
|
2016-01-21 23:00:47 -08:00
|
|
|
system("cd /tmp/create-module && find . -name .pyc | xargs rm -rf");
|
2015-08-15 12:22:07 -07:00
|
|
|
system("cd /tmp/create-module && find . -name \\*.svn-work | xargs rm -rf");
|
|
|
|
system("cd /tmp/create-module && find . -name \\*.svn-base | xargs rm -rf");
|
2007-04-12 20:24:50 +00:00
|
|
|
system("cd /tmp/create-module && find . -name '*~' -o -name '*.rej' -o -name '*.orig' -o -name '.*.swp' | xargs rm -rf");
|
2015-08-02 13:30:02 -07:00
|
|
|
system("cd /tmp/create-module && find . -name RELEASE -o -name RELEASE.sh | xargs rm -rf");
|
2015-08-15 12:22:07 -07:00
|
|
|
system("cd /tmp/create-module && find . -name linux.sh -o -name freebsd.sh -o -name LICENCE -o -name README.md -o -name distrib | xargs rm -rf");
|
2015-08-02 13:30:02 -07:00
|
|
|
system("cd /tmp/create-module && find . -name 'makemodule*.pl' | xargs rm -rf");
|
2016-02-29 16:19:32 -08:00
|
|
|
if (-r "/tmp/create-module/$subdir/EXCLUDE") {
|
2016-06-04 16:36:51 -07:00
|
|
|
system("cd /tmp/create-module/$subdir && cat EXCLUDE | xargs rm -rf");
|
2016-02-29 16:19:32 -08:00
|
|
|
unlink("/tmp/create-module/$subdir/EXCLUDE");
|
|
|
|
}
|
2007-04-12 20:24:50 +00:00
|
|
|
unlink("/tmp/create-module/$subdir/IDEAS");
|
2010-11-28 13:24:42 -08:00
|
|
|
system("cd /tmp/create-module && find . -name \\*.cgi | xargs chmod +x");
|
|
|
|
system("cd /tmp/create-module && find . -name \\*.pl | xargs chmod +x");
|
2007-04-12 20:24:50 +00:00
|
|
|
system("cd /tmp/create-module && tar $flags $file $subdir") && die "Failed to create tar file";
|
|
|
|
}
|
|
|
|
if ($file =~ /^(.*)\.gz$/i) {
|
|
|
|
system("mv $file $1");
|
|
|
|
system("gzip -c $1 >$file");
|
|
|
|
unlink("$1");
|
|
|
|
}
|
2009-07-20 18:56:26 +00:00
|
|
|
if ($createsig) {
|
|
|
|
system("rm -f $file-sig.asc");
|
2023-08-30 20:10:01 -07:00
|
|
|
system("gpg ".($keyname ? " --default-key $keyname" : "").
|
|
|
|
" --armor --output $file-sig.asc --detach-sig $file");
|
2009-07-20 18:56:26 +00:00
|
|
|
}
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
# read_file(file, &assoc, [&order], [lowercase])
|
|
|
|
# Fill an associative array with name=value pairs from a file
|
|
|
|
sub read_file
|
|
|
|
{
|
2020-03-14 17:20:54 -07:00
|
|
|
open(ARFILE, "<".$_[0]) || return 0;
|
2007-04-12 20:24:50 +00:00
|
|
|
while(<ARFILE>) {
|
|
|
|
s/\r|\n//g;
|
|
|
|
if (!/^#/ && /^([^=]*)=(.*)$/) {
|
|
|
|
$_[1]->{$_[3] ? lc($1) : $1} = $2;
|
|
|
|
push(@{$_[2]}, $1) if ($_[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(ARFILE);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# write_file(file, array)
|
|
|
|
# Write out the contents of an associative array as name=value lines
|
|
|
|
sub write_file
|
|
|
|
{
|
|
|
|
local(%old, @order);
|
|
|
|
&read_file($_[0], \%old, \@order);
|
2020-03-14 17:20:54 -07:00
|
|
|
open(ARFILE, ">".$_[0]);
|
2007-04-12 20:24:50 +00:00
|
|
|
foreach $k (@order) {
|
|
|
|
print ARFILE $k,"=",$_[1]->{$k},"\n" if (exists($_[1]->{$k}));
|
|
|
|
}
|
|
|
|
foreach $k (keys %{$_[1]}) {
|
|
|
|
print ARFILE $k,"=",$_[1]->{$k},"\n" if (!exists($old{$k}));
|
|
|
|
}
|
|
|
|
close(ARFILE);
|
|
|
|
}
|