<commit_before>#!/usr/bin/perl
# makemoduledeb.pl
# Create a Debian package for a webmin or usermin module or theme

use POSIX;

$licence = "BSD";
$email = "<NAME> <<EMAIL>>";
$target_dir = "/tmp";

$tmp_dir = "/tmp/debian-module";
$debian_dir = "$tmp_dir/DEBIAN";
$control_file = "$debian_dir/control";
$preinstall_file = "$debian_dir/preinst";
$postinstall_file = "$debian_dir/postinst";
$preuninstall_file = "$debian_dir/prerm";
$postuninstall_file = "$debian_dir/postrm";
$copyright_file = "$debian_dir/copyright";
$changelog_file = "$debian_dir/changelog";
$files_file = "$debian_dir/files";

-r "/etc/debian_version" || die "makemoduledeb.pl must be run on Debian";

# Parse command-line args
while(@ARGV) {
	local $a = shift(@ARGV);
	if ($a eq "--force-theme") {
		$force_theme = 1;
		}
	elsif ($a eq "--licence" || $a eq "--license") {
		$licence = shift(@ARGV);
		}
	elsif ($a eq "--email") {
		$email = shift(@ARGV);
		}
	elsif ($a eq "--url") {
		$url = shift(@ARGV);
		}
	elsif ($a eq "--upstream") {
		$upstream = shift(@ARGV);
		}
	elsif ($a eq "--deb-depends") {
		$rpmdepends = 1;
		}
	elsif ($a eq "--no-prefix") {
		$no_prefix = 1;
		}
	elsif ($a eq "--usermin") {
		$force_usermin = 1;
		}
	elsif ($a eq "--target-dir") {
		$target_dir = shift(@ARGV);
		}
	elsif ($a eq "--dir") {
		$final_mod = shift(@ARGV);
		}
	elsif ($a eq "--allow-overwrite") {
		$allow_overwrite = 1;
		}
	elsif ($a eq "--dsc-file") {
		$dsc_file = shift(@ARGV);
		}
	elsif ($a =~ /^\-\-/) {
		print STDERR "Unknown option $a\n";
		exit(1);
		}
	else {
		if (!defined($dir)) {
			$dir = $a;
			}
		else {
			$ver = $a;
			}
		}
	}

# Validate args
if (!$dir) {
	print STDERR "usage: makemoduledeb.pl [--force-theme]\n";
	print STDERR "                        [--deb-depends]\n";
	print STDERR "                        [--no-prefix]\n";
	print STDERR "                        [--licence name]\n";
	print STDERR "                        [--email 'name <address>']\n";
	print STDERR "                        [--upstream 'name <address>']\n";
	print STDERR "                        [--provides provides]\n";
	print STDERR "                        [--usermin]\n";
	print STDERR "                        [--target-dir directory]\n";
	print STDERR "                        [--dir directory-in-package]\n";
	print STDERR "                        [--allow-overwrite]\n";
	print STDERR "                        [--dsc-file file.dsc]\n";
	print STDERR "                        <module> [version]\n";
	exit(1);
	}
chop($par = `dirname $dir`);
chop($source_mod = `basename $dir`);
$source_dir = "$par/$source_mod";
$mod = $final_mod || $source_mod;
if ($mod eq "." || $mod eq "..") {
	die "directory must be an actual directory (module) name, not \"$mod\"";
	}

# Is this actually a module or theme directory?
-d $source_dir || die "$source_dir is not a directory";
if (&read_file("$source_dir/module.info", \%minfo) && $minfo{'desc'}) {
	$depends = join(" ", map { s/\/[0-9\.]+//; $_ }
				grep { !/^[0-9\.]+$/ }
				  split(/\s+/, $minfo{'depends'}));
	if ($minfo{'usermin'} && (!$minfo{'webmin'} || $force_usermin)) {
		$prefix = "usermin-";
		$desc = "Usermin module for '$minfo{'desc'}'";
		$product = "usermin";
		}
	else {
		$prefix = "webmin-";
		$desc = "Webmin module for '$minfo{'desc'}'";
		$product = "webmin";
		}
	$iver = $minfo{'version'};
	$post_config = 1;
	}
elsif (&read_file("$source_dir/theme.info", \%tinfo) && $tinfo{'desc'}) {
	if ($tinfo{'usermin'} && (!$tinfo{'usermin'} || $force_usermin)) {
		$prefix = "usermin-";
		$desc = "Usermin theme '$tinfo{'desc'}'";
		$product = "usermin";
		}
	else {
		$prefix = "webmin-";
		$desc = "Webmin theme '$tinfo{'desc'}'";
		$product = "webmin";
		}
	$iver = $tinfo{'version'};
	$istheme = 1;
	$post_config = 0;
	}
else {
	die "$source_dir does not appear to be a webmin module or theme";
	}
$prefix = "" if ($no_prefix);
$usr_dir = "$tmp_dir/usr/share/$product";
$ucproduct = ucfirst($product);
$ver ||= $iver;		# Use module.info version, or 1
$ver ||= 1;
$upstream ||= $email;<commit_msg>Support easier to use release flag<commit_after>#!/usr/bin/perl
# makemoduledeb.pl
# Create a Debian package for a webmin or usermin module or theme

use POSIX;

$licence = "BSD";
$email = "<NAME> <<EMAIL>>";
$target_dir = "/tmp";

$tmp_dir = "/tmp/debian-module";
$debian_dir = "$tmp_dir/DEBIAN";
$control_file = "$debian_dir/control";
$preinstall_file = "$debian_dir/preinst";
$postinstall_file = "$debian_dir/postinst";
$preuninstall_file = "$debian_dir/prerm";
$postuninstall_file = "$debian_dir/postrm";
$copyright_file = "$debian_dir/copyright";
$changelog_file = "$debian_dir/changelog";
$files_file = "$debian_dir/files";

-r "/etc/debian_version" || die "makemoduledeb.pl must be run on Debian";

# Parse command-line args
while(@ARGV) {
	local $a = shift(@ARGV);
	if ($a eq "--force-theme") {
		$force_theme = 1;
		}
	elsif ($a eq "--licence" || $a eq "--license") {
		$licence = shift(@ARGV);
		}
	elsif ($a eq "--email") {
		$email = shift(@ARGV);
		}
	elsif ($a eq "--url") {
		$url = shift(@ARGV);
		}
	elsif ($a eq "--upstream") {
		$upstream = shift(@ARGV);
		}
	elsif ($a eq "--deb-depends") {
		$rpmdepends = 1;
		}
	elsif ($a eq "--no-prefix") {
		$no_prefix = 1;
		}
	elsif ($a eq "--usermin") {
		$force_usermin = 1;
		}
	elsif ($a eq "--target-dir") {
		$target_dir = shift(@ARGV);
		}
	elsif ($a eq "--dir") {
		$final_mod = shift(@ARGV);
		}
	elsif ($a eq "--release") {
		$release = shift(@ARGV);
		}
	elsif ($a eq "--allow-overwrite") {
		$allow_overwrite = 1;
		}
	elsif ($a eq "--dsc-file") {
		$dsc_file = shift(@ARGV);
		}
	elsif ($a =~ /^\-\-/) {
		print STDERR "Unknown option $a\n";
		exit(1);
		}
	else {
		if (!defined($dir)) {
			$dir = $a;
			}
		else {
			$ver = $a;
			}
		}
	}

# Validate args
if (!$dir) {
	print STDERR "usage: makemoduledeb.pl [--force-theme]\n";
	print STDERR "                        [--deb-depends]\n";
	print STDERR "                        [--no-prefix]\n";
	print STDERR "                        [--licence name]\n";
	print STDERR "                        [--email 'name <address>']\n";
	print STDERR "                        [--upstream 'name <address>']\n";
	print STDERR "                        [--provides provides]\n";
	print STDERR "                        [--usermin]\n";
	print STDERR "                        [--target-dir directory]\n";
	print STDERR "                        [--dir directory-in-package]\n";
	print STDERR "                        [--allow-overwrite]\n";
	print STDERR "                        [--dsc-file file.dsc]\n";
	print STDERR "                        <module> [version]\n";
	exit(1);
	}
chop($par = `dirname $dir`);
chop($source_mod = `basename $dir`);
$source_dir = "$par/$source_mod";
$mod = $final_mod || $source_mod;
if ($mod eq "." || $mod eq "..") {
	die "directory must be an actual directory (module) name, not \"$mod\"";
	}

# Is this actually a module or theme directory?
-d $source_dir || die "$source_dir is not a directory";
if (&read_file("$source_dir/module.info", \%minfo) && $minfo{'desc'}) {
	$depends = join(" ", map { s/\/[0-9\.]+//; $_ }
				grep { !/^[0-9\.]+$/ }
				  split(/\s+/, $minfo{'depends'}));
	if ($minfo{'usermin'} && (!$minfo{'webmin'} || $force_usermin)) {
		$prefix = "usermin-";
		$desc = "Usermin module for '$minfo{'desc'}'";
		$product = "usermin";
		}
	else {
		$prefix = "webmin-";
		$desc = "Webmin module for '$minfo{'desc'}'";
		$product = "webmin";
		}
	$iver = $minfo{'version'};
	$post_config = 1;
	}
elsif (&read_file("$source_dir/theme.info", \%tinfo) && $tinfo{'desc'}) {
	if ($tinfo{'usermin'} && (!$tinfo{'usermin'} || $force_usermin)) {
		$prefix = "usermin-";
		$desc = "Usermin theme '$tinfo{'desc'}'";
		$product = "usermin";
		}
	else {
		$prefix = "webmin-";
		$desc = "Webmin theme '$tinfo{'desc'}'";
		$product = "webmin";
		}
	$iver = $tinfo{'version'};
	$istheme = 1;
	$post_config = 0;
	}
else {
	die "$source_dir does not appear to be a webmin module or theme";
	}
$prefix = "" if ($no_prefix);
$usr_dir = "$tmp_dir/usr/share/$product";
$ucproduct = ucfirst($product);
$ver ||= $iver;		# Use module.info version, or 1
$ver ||= 1;
$ver .= "-".$release if ($release);
$upstream ||= $email;
{'fraction_non_alphanumeric': 0.21230618972042486, 'fraction_numerical': 0.00390672689537297, 'mean_word_length': 2.716878402903811, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4464360', 'n_tokens_mistral': 3378, 'n_tokens_neox': 3160, 'n_words': 714}