Compare commits
20 Commits
f11cea9528
...
main
Author | SHA1 | Date | |
---|---|---|---|
89b51b4406 | |||
274dfb7dba | |||
31986b3ea6 | |||
4f5cbb24be | |||
b816d85019 | |||
24e36b945a | |||
dd97a672aa | |||
6f3c6c2596 | |||
|
0fc70df8ac | ||
1dd1c8c100 | |||
|
b514cfa380 | ||
b84ff7a4c8 | |||
e8c203debf | |||
6150943cb3 | |||
946fb47508 | |||
d7bee0be56 | |||
35305a5c45 | |||
12d76f8a52 | |||
240ece066b | |||
62071280a5 |
62
Containerfile
Normal file
62
Containerfile
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
FROM perl:5.40.1 As base
|
||||||
|
|
||||||
|
LABEL author="sgoti" \
|
||||||
|
email="lyunpaw@gmail.com" \
|
||||||
|
project="Hacker Public Radio" \
|
||||||
|
forge="https://repo.anhonesthost.net/HPR"
|
||||||
|
|
||||||
|
ARG unprivilegedUser="janitor"
|
||||||
|
|
||||||
|
RUN apt update && apt upgrade --yes;
|
||||||
|
|
||||||
|
RUN apt install --no-install-recommends sqlite3 git --yes \
|
||||||
|
&& rm --recursive --force /var/lib/apt/lists/*;
|
||||||
|
|
||||||
|
RUN mkdir --verbose --parent /opt/hpr /tmp/hpr;
|
||||||
|
|
||||||
|
RUN groupadd --system ${unprivilegedUser} \
|
||||||
|
&& useradd --system --no-log-init --gid ${unprivilegedUser} ${unprivilegedUser};
|
||||||
|
|
||||||
|
RUN chown --recursive ${unprivilegedUser}:${unprivilegedUser} /opt/hpr \
|
||||||
|
&& chown --recursive ${unprivilegedUser}:${unprivilegedUser} /tmp/hpr;
|
||||||
|
|
||||||
|
#Bill of particulars.
|
||||||
|
|
||||||
|
##Meta::CPAN (Comprehensive Perl Archive Network)
|
||||||
|
RUN cpanm Config::General \
|
||||||
|
DBD::SQLite \
|
||||||
|
DBI \
|
||||||
|
Data::Dumper \
|
||||||
|
Date::Calc \
|
||||||
|
Date::Parse \
|
||||||
|
DateTime \
|
||||||
|
DateTime::Duration \
|
||||||
|
DateTime::Format::Duration \
|
||||||
|
DateTime::TimeZone \
|
||||||
|
HTML::Entities \
|
||||||
|
JSON \
|
||||||
|
Template \
|
||||||
|
Template::Filters;
|
||||||
|
|
||||||
|
##Included perl core modules (standard library).
|
||||||
|
##Carp
|
||||||
|
##Cwd
|
||||||
|
##Getopt::Long
|
||||||
|
##Pod::Usage
|
||||||
|
##File::Copy
|
||||||
|
|
||||||
|
USER ${unprivilegedUser}
|
||||||
|
|
||||||
|
WORKDIR /opt/hpr
|
||||||
|
|
||||||
|
RUN git clone https://repo.anhonesthost.net/HPR/hpr-tools.git \
|
||||||
|
&& git clone https://repo.anhonesthost.net/HPR/hpr_hub.git \
|
||||||
|
&& git clone https://repo.anhonesthost.net/HPR/hpr_generator.git \
|
||||||
|
&& git clone https://repo.anhonesthost.net/HPR/hpr_documentation.git;
|
||||||
|
|
||||||
|
WORKDIR /opt/hpr/hpr-tools/Community_News/
|
||||||
|
RUN ln --symbolic /opt/hpr/hpr_generator/utils/mysql2sqlite /opt/hpr/hpr-tools/Community_News/mysql2sqlite;
|
||||||
|
RUN ./collect_HPR_database;
|
||||||
|
|
||||||
|
CMD bash;
|
||||||
|
|
@@ -19,9 +19,9 @@
|
|||||||
# BUGS: ---
|
# BUGS: ---
|
||||||
# NOTES: ---
|
# NOTES: ---
|
||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.4
|
# VERSION: 0.0.5
|
||||||
# CREATED: 2015-07-11 15:53:01
|
# CREATED: 2015-07-11 15:53:01
|
||||||
# REVISION: 2025-05-09 14:13:17
|
# REVISION: 2025-05-25 18:26:13
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ use Data::Dumper;
|
|||||||
#
|
#
|
||||||
# Version number (manually incremented)
|
# Version number (manually incremented)
|
||||||
#
|
#
|
||||||
our $VERSION = '0.0.4';
|
our $VERSION = '0.0.5';
|
||||||
|
|
||||||
#
|
#
|
||||||
# Script name
|
# Script name
|
||||||
@@ -135,11 +135,16 @@ else {
|
|||||||
}
|
}
|
||||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip SQL comments
|
||||||
|
#
|
||||||
|
$query = strip_sql_comments($query);
|
||||||
|
|
||||||
#
|
#
|
||||||
# Count placeholders in the query and the arguments provided. First remove all
|
# Count placeholders in the query and the arguments provided. First remove all
|
||||||
# comments which may contain '?' characters, then count any that are left.
|
# comments which may contain '?' characters, then count any that are left.
|
||||||
#
|
#
|
||||||
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
#$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
||||||
$pcount = grep {/\?/} split( '', $query );
|
$pcount = grep {/\?/} split( '', $query );
|
||||||
$acount = scalar(@dbargs);
|
$acount = scalar(@dbargs);
|
||||||
|
|
||||||
@@ -173,7 +178,7 @@ else {
|
|||||||
# Load database configuration data; allow environment variables
|
# Load database configuration data; allow environment variables
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
my $conf = Config::General->new(
|
my $conf = Config::General->new(
|
||||||
-ConfigFile => $configfile,
|
-ConfigFile => $cfgfile,
|
||||||
-InterPolateVars => 1,
|
-InterPolateVars => 1,
|
||||||
-InterPolateEnv => 1,
|
-InterPolateEnv => 1,
|
||||||
-ExtendedAccess => 1
|
-ExtendedAccess => 1
|
||||||
@@ -181,7 +186,7 @@ my $conf = Config::General->new(
|
|||||||
my %config = $conf->getall();
|
my %config = $conf->getall();
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set defaults
|
# Set defaults in case values have been omitted
|
||||||
#
|
#
|
||||||
$config{database}->{dbtype} //= 'SQLite';
|
$config{database}->{dbtype} //= 'SQLite';
|
||||||
$config{database}->{host} //= '127.0.0.1';
|
$config{database}->{host} //= '127.0.0.1';
|
||||||
@@ -263,13 +268,13 @@ exit;
|
|||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub db_connect {
|
sub db_connect { #{{{
|
||||||
my ($cfg) = @_;
|
my ($cfg) = @_;
|
||||||
|
|
||||||
my ( $dbh, $dbtype, $dbname );
|
my ( $dbh, $dbtype, $dbname );
|
||||||
|
|
||||||
$dbtype = $config{database}->{dbtype};
|
$dbtype = $cfg->{database}->{dbtype};
|
||||||
$dbname = $config{database}->{name};
|
$dbname = $cfg->{database}->{name};
|
||||||
die "Database name is mandatory\n" unless $dbname;
|
die "Database name is mandatory\n" unless $dbname;
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -280,6 +285,7 @@ sub db_connect {
|
|||||||
# The name for the SQLite driver is 'DBD:SQLite'
|
# The name for the SQLite driver is 'DBD:SQLite'
|
||||||
#
|
#
|
||||||
$dbtype = 'SQLite';
|
$dbtype = 'SQLite';
|
||||||
|
_debug( $DEBUG >= 3, '$dbtype: ' . $dbtype, '$dbname: ' . $dbname );
|
||||||
|
|
||||||
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
||||||
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
||||||
@@ -291,10 +297,10 @@ sub db_connect {
|
|||||||
#
|
#
|
||||||
$dbtype = 'mysql';
|
$dbtype = 'mysql';
|
||||||
|
|
||||||
my $dbhost = $config{database}->{host};
|
my $dbhost = $cfg->{database}->{host};
|
||||||
my $dbport = $config{database}->{port};
|
my $dbport = $cfg->{database}->{port};
|
||||||
my $dbuser = $config{database}->{user};
|
my $dbuser = $cfg->{database}->{user};
|
||||||
my $dbpwd = $config{database}->{password};
|
my $dbpwd = $cfg->{database}->{password};
|
||||||
|
|
||||||
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
||||||
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
||||||
@@ -320,28 +326,68 @@ sub db_connect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $dbh;
|
return $dbh;
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
|
#=== FUNCTION ================================================================
|
||||||
|
# NAME: strip_sql_comments
|
||||||
|
# PURPOSE: Given a query as a scalar, strips all SQL comments
|
||||||
|
# PARAMETERS: $query string containing a query
|
||||||
|
# RETURNS: Stripped string
|
||||||
|
# DESCRIPTION: Two types of comments might exist in the query: the C-style
|
||||||
|
# and the SQL style. The string is treated as a single string
|
||||||
|
# even though it's multi-line, and any C-style comments are
|
||||||
|
# removed. Then the string is treated as multi-line and each
|
||||||
|
# line is scanned for SQL comments (which end at the end of the
|
||||||
|
# line), and these are stripped. Blank lines are skipped too to
|
||||||
|
# compress the output a little.
|
||||||
|
# THROWS: No exceptions
|
||||||
|
# COMMENTS: None
|
||||||
|
# SEE ALSO: N/A
|
||||||
|
#===============================================================================
|
||||||
|
sub strip_sql_comments { #{{{
|
||||||
|
my ($query) = @_;
|
||||||
|
|
||||||
|
my $result;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip C-style comments
|
||||||
|
#
|
||||||
|
$query =~ s/\/\*.*?\*\///sg;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip SQL line-oriented comments
|
||||||
|
#
|
||||||
|
foreach my $line (split(/\n/,$query)) {
|
||||||
|
next if $line =~ /^\s*$/;
|
||||||
|
$line =~ s/--.*$//;
|
||||||
|
$result .= "$line\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _debug
|
# NAME: _debug
|
||||||
# PURPOSE: Prints debug reports
|
# PURPOSE: Prints debug reports
|
||||||
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
||||||
# $message Message to print
|
# @messages Messages to print
|
||||||
# RETURNS: Nothing
|
# RETURNS: Nothing
|
||||||
# DESCRIPTION: Outputs a message if $active is true. It removes any trailing
|
# DESCRIPTION: Outputs messages if $active is true. It removes any trailing
|
||||||
# newline and then adds one in the 'print' to the caller doesn't
|
# newlines and then adds one to each line so the caller doesn't
|
||||||
# have to bother. Prepends the message with 'D> ' to show it's
|
# have to bother. Prepends 'D> ' to each message to show it's
|
||||||
# a debug message.
|
# a debug message.
|
||||||
# THROWS: No exceptions
|
# THROWS: No exceptions
|
||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub _debug {
|
sub _debug { #{{{
|
||||||
my ( $active, $message ) = @_;
|
my ( $active, @messages ) = @_;
|
||||||
|
|
||||||
chomp($message);
|
if ($active) {
|
||||||
print STDERR "D> $message\n" if $active;
|
chomp(@messages);
|
||||||
}
|
say STDERR "D> ", join( "\nD> ", @messages );
|
||||||
|
}
|
||||||
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _dbargs
|
# NAME: _dbargs
|
||||||
@@ -354,7 +400,7 @@ sub _debug {
|
|||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub _dbargs {
|
sub _dbargs { #{{{
|
||||||
my ($opts) = @_;
|
my ($opts) = @_;
|
||||||
|
|
||||||
my @args;
|
my @args;
|
||||||
@@ -364,7 +410,7 @@ sub _dbargs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (@args);
|
return (@args);
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: Options
|
# NAME: Options
|
||||||
@@ -376,7 +422,7 @@ sub _dbargs {
|
|||||||
# COMMENTS: none
|
# COMMENTS: none
|
||||||
# SEE ALSO: n/a
|
# SEE ALSO: n/a
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub Options {
|
sub Options { #{{{
|
||||||
my ($optref) = @_;
|
my ($optref) = @_;
|
||||||
|
|
||||||
my @options = (
|
my @options = (
|
||||||
@@ -389,7 +435,7 @@ sub Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|
||||||
@@ -404,7 +450,7 @@ query2csv - A script for generating CSV from database query
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
This documentation refers to query2csv version 0.0.4
|
This documentation refers to query2csv version 0.0.5
|
||||||
|
|
||||||
=head1 USAGE
|
=head1 USAGE
|
||||||
|
|
||||||
|
@@ -18,9 +18,9 @@
|
|||||||
# BUGS: ---
|
# BUGS: ---
|
||||||
# NOTES: ---
|
# NOTES: ---
|
||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.3
|
# VERSION: 0.0.4
|
||||||
# CREATED: 2021-06-18 13:24:49
|
# CREATED: 2021-06-18 13:24:49
|
||||||
# REVISION: 2025-05-09 14:13:27
|
# REVISION: 2025-05-25 18:48:59
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ use Data::Dumper;
|
|||||||
#
|
#
|
||||||
# Version number (manually incremented)
|
# Version number (manually incremented)
|
||||||
#
|
#
|
||||||
our $VERSION = '0.0.3';
|
our $VERSION = '0.0.4';
|
||||||
|
|
||||||
#
|
#
|
||||||
# Script name
|
# Script name
|
||||||
@@ -131,11 +131,16 @@ else {
|
|||||||
}
|
}
|
||||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip SQL comments
|
||||||
|
#
|
||||||
|
$query = strip_sql_comments($query);
|
||||||
|
|
||||||
#
|
#
|
||||||
# Count placeholders in the query and the arguments provided. First remove all
|
# Count placeholders in the query and the arguments provided. First remove all
|
||||||
# comments which may contain '?' characters, then count any that are left.
|
# comments which may contain '?' characters, then count any that are left.
|
||||||
#
|
#
|
||||||
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
#$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
||||||
$pcount = grep {/\?/} split( '', $query );
|
$pcount = grep {/\?/} split( '', $query );
|
||||||
$acount = scalar(@dbargs);
|
$acount = scalar(@dbargs);
|
||||||
|
|
||||||
@@ -177,7 +182,7 @@ my $conf = Config::General->new(
|
|||||||
my %config = $conf->getall();
|
my %config = $conf->getall();
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set defaults
|
# Set defaults in case values have been omitted
|
||||||
#
|
#
|
||||||
$config{database}->{dbtype} //= 'SQLite';
|
$config{database}->{dbtype} //= 'SQLite';
|
||||||
$config{database}->{host} //= '127.0.0.1';
|
$config{database}->{host} //= '127.0.0.1';
|
||||||
@@ -247,13 +252,13 @@ exit;
|
|||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub db_connect {
|
sub db_connect { #{{{
|
||||||
my ($cfg) = @_;
|
my ($cfg) = @_;
|
||||||
|
|
||||||
my ( $dbh, $dbtype, $dbname );
|
my ( $dbh, $dbtype, $dbname );
|
||||||
|
|
||||||
$dbtype = $config{database}->{dbtype};
|
$dbtype = $cfg->{database}->{dbtype};
|
||||||
$dbname = $config{database}->{name};
|
$dbname = $cfg->{database}->{name};
|
||||||
die "Database name is mandatory\n" unless $dbname;
|
die "Database name is mandatory\n" unless $dbname;
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -264,6 +269,7 @@ sub db_connect {
|
|||||||
# The name for the SQLite driver is 'DBD:SQLite'
|
# The name for the SQLite driver is 'DBD:SQLite'
|
||||||
#
|
#
|
||||||
$dbtype = 'SQLite';
|
$dbtype = 'SQLite';
|
||||||
|
_debug( $DEBUG >= 3, '$dbtype: ' . $dbtype, '$dbname: ' . $dbname );
|
||||||
|
|
||||||
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
||||||
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
||||||
@@ -275,10 +281,10 @@ sub db_connect {
|
|||||||
#
|
#
|
||||||
$dbtype = 'mysql';
|
$dbtype = 'mysql';
|
||||||
|
|
||||||
my $dbhost = $config{database}->{host};
|
my $dbhost = $cfg->{database}->{host};
|
||||||
my $dbport = $config{database}->{port};
|
my $dbport = $cfg->{database}->{port};
|
||||||
my $dbuser = $config{database}->{user};
|
my $dbuser = $cfg->{database}->{user};
|
||||||
my $dbpwd = $config{database}->{password};
|
my $dbpwd = $cfg->{database}->{password};
|
||||||
|
|
||||||
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
||||||
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
||||||
@@ -304,28 +310,68 @@ sub db_connect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $dbh;
|
return $dbh;
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
|
#=== FUNCTION ================================================================
|
||||||
|
# NAME: strip_sql_comments
|
||||||
|
# PURPOSE: Given a query as a scalar, strips all SQL comments
|
||||||
|
# PARAMETERS: $query string containing a query
|
||||||
|
# RETURNS: Stripped string
|
||||||
|
# DESCRIPTION: Two types of comments might exist in the query: the C-style
|
||||||
|
# and the SQL style. The string is treated as a single string
|
||||||
|
# even though it's multi-line, and any C-style comments are
|
||||||
|
# removed. Then the string is treated as multi-line and each
|
||||||
|
# line is scanned for SQL comments (which end at the end of the
|
||||||
|
# line), and these are stripped. Blank lines are skipped too to
|
||||||
|
# compress the output a little.
|
||||||
|
# THROWS: No exceptions
|
||||||
|
# COMMENTS: None
|
||||||
|
# SEE ALSO: N/A
|
||||||
|
#===============================================================================
|
||||||
|
sub strip_sql_comments { #{{{
|
||||||
|
my ($query) = @_;
|
||||||
|
|
||||||
|
my $result;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip C-style comments
|
||||||
|
#
|
||||||
|
$query =~ s/\/\*.*?\*\///sg;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip SQL line-oriented comments
|
||||||
|
#
|
||||||
|
foreach my $line (split(/\n/,$query)) {
|
||||||
|
next if $line =~ /^\s*$/;
|
||||||
|
$line =~ s/--.*$//;
|
||||||
|
$result .= "$line\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _debug
|
# NAME: _debug
|
||||||
# PURPOSE: Prints debug reports
|
# PURPOSE: Prints debug reports
|
||||||
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
||||||
# $message Message to print
|
# @messages Messages to print
|
||||||
# RETURNS: Nothing
|
# RETURNS: Nothing
|
||||||
# DESCRIPTION: Outputs a message if $active is true. It removes any trailing
|
# DESCRIPTION: Outputs messages if $active is true. It removes any trailing
|
||||||
# newline and then adds one in the 'print' to the caller doesn't
|
# newlines and then adds one to each line so the caller doesn't
|
||||||
# have to bother. Prepends the message with 'D> ' to show it's
|
# have to bother. Prepends 'D> ' to each message to show it's
|
||||||
# a debug message.
|
# a debug message.
|
||||||
# THROWS: No exceptions
|
# THROWS: No exceptions
|
||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub _debug {
|
sub _debug { #{{{
|
||||||
my ( $active, $message ) = @_;
|
my ( $active, @messages ) = @_;
|
||||||
|
|
||||||
chomp($message);
|
if ($active) {
|
||||||
print STDERR "D> $message\n" if $active;
|
chomp(@messages);
|
||||||
}
|
say STDERR "D> ", join( "\nD> ", @messages );
|
||||||
|
}
|
||||||
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _dbargs
|
# NAME: _dbargs
|
||||||
@@ -338,7 +384,7 @@ sub _debug {
|
|||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub _dbargs {
|
sub _dbargs { #{{{
|
||||||
my ($opts) = @_;
|
my ($opts) = @_;
|
||||||
|
|
||||||
my @args;
|
my @args;
|
||||||
@@ -348,7 +394,7 @@ sub _dbargs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (@args);
|
return (@args);
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: Options
|
# NAME: Options
|
||||||
@@ -360,7 +406,7 @@ sub _dbargs {
|
|||||||
# COMMENTS: none
|
# COMMENTS: none
|
||||||
# SEE ALSO: n/a
|
# SEE ALSO: n/a
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub Options {
|
sub Options { #{{{
|
||||||
my ($optref) = @_;
|
my ($optref) = @_;
|
||||||
|
|
||||||
my @options = (
|
my @options = (
|
||||||
@@ -373,7 +419,7 @@ sub Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|
||||||
@@ -388,7 +434,7 @@ query2json - A script for generating CSV from database query
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
This documentation refers to query2json version 0.0.3
|
This documentation refers to query2json version 0.0.4
|
||||||
|
|
||||||
=head1 USAGE
|
=head1 USAGE
|
||||||
|
|
||||||
|
@@ -26,9 +26,9 @@
|
|||||||
# BUGS: ---
|
# BUGS: ---
|
||||||
# NOTES: ---
|
# NOTES: ---
|
||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.8
|
# VERSION: 0.0.9
|
||||||
# CREATED: 2021-06-18 13:24:49
|
# CREATED: 2021-06-18 13:24:49
|
||||||
# REVISION: 2025-05-09 14:13:04
|
# REVISION: 2025-05-25 18:41:09
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ use Data::Dumper;
|
|||||||
#
|
#
|
||||||
# Version number (manually incremented)
|
# Version number (manually incremented)
|
||||||
#
|
#
|
||||||
our $VERSION = '0.0.8';
|
our $VERSION = '0.0.9';
|
||||||
|
|
||||||
#
|
#
|
||||||
# Script and directory names
|
# Script and directory names
|
||||||
@@ -162,11 +162,16 @@ else {
|
|||||||
}
|
}
|
||||||
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip SQL comments
|
||||||
|
#
|
||||||
|
$query = strip_sql_comments($query);
|
||||||
|
|
||||||
#
|
#
|
||||||
# Count placeholders in the query and the arguments provided. First remove all
|
# Count placeholders in the query and the arguments provided. First remove all
|
||||||
# comments which may contain '?' characters, then count any that are left.
|
# comments which may contain '?' characters, then count any that are left.
|
||||||
#
|
#
|
||||||
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
#$query = join("\n", grep {!/^--/} split( "\n", $query ) );
|
||||||
$pcount = grep {/\?/} split( '', $query );
|
$pcount = grep {/\?/} split( '', $query );
|
||||||
$acount = scalar(@dbargs);
|
$acount = scalar(@dbargs);
|
||||||
|
|
||||||
@@ -323,13 +328,13 @@ exit;
|
|||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub db_connect {
|
sub db_connect { #{{{
|
||||||
my ($cfg) = @_;
|
my ($cfg) = @_;
|
||||||
|
|
||||||
my ( $dbh, $dbtype, $dbname );
|
my ( $dbh, $dbtype, $dbname );
|
||||||
|
|
||||||
$dbtype = $config{database}->{dbtype};
|
$dbtype = $cfg->{database}->{dbtype};
|
||||||
$dbname = $config{database}->{name};
|
$dbname = $cfg->{database}->{name};
|
||||||
die "Database name is mandatory\n" unless $dbname;
|
die "Database name is mandatory\n" unless $dbname;
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -340,6 +345,7 @@ sub db_connect {
|
|||||||
# The name for the SQLite driver is 'DBD:SQLite'
|
# The name for the SQLite driver is 'DBD:SQLite'
|
||||||
#
|
#
|
||||||
$dbtype = 'SQLite';
|
$dbtype = 'SQLite';
|
||||||
|
_debug( $DEBUG >= 3, '$dbtype: ' . $dbtype, '$dbname: ' . $dbname );
|
||||||
|
|
||||||
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
$dbh = DBI->connect( "DBI:$dbtype:dbname=$dbname",
|
||||||
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
"", "", { AutoCommit => 1, sqlite_unicode => 1, } )
|
||||||
@@ -351,10 +357,10 @@ sub db_connect {
|
|||||||
#
|
#
|
||||||
$dbtype = 'mysql';
|
$dbtype = 'mysql';
|
||||||
|
|
||||||
my $dbhost = $config{database}->{host};
|
my $dbhost = $cfg->{database}->{host};
|
||||||
my $dbport = $config{database}->{port};
|
my $dbport = $cfg->{database}->{port};
|
||||||
my $dbuser = $config{database}->{user};
|
my $dbuser = $cfg->{database}->{user};
|
||||||
my $dbpwd = $config{database}->{password};
|
my $dbpwd = $cfg->{database}->{password};
|
||||||
|
|
||||||
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
$dbh = DBI->connect( "DBI:$dbtype:host=$dbhost;port=$dbport;database=$dbname",
|
||||||
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
$dbuser, $dbpwd, { AutoCommit => 1 } )
|
||||||
@@ -380,28 +386,68 @@ sub db_connect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $dbh;
|
return $dbh;
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
|
#=== FUNCTION ================================================================
|
||||||
|
# NAME: strip_sql_comments
|
||||||
|
# PURPOSE: Given a query as a scalar, strips all SQL comments
|
||||||
|
# PARAMETERS: $query string containing a query
|
||||||
|
# RETURNS: Stripped string
|
||||||
|
# DESCRIPTION: Two types of comments might exist in the query: the C-style
|
||||||
|
# and the SQL style. The string is treated as a single string
|
||||||
|
# even though it's multi-line, and any C-style comments are
|
||||||
|
# removed. Then the string is treated as multi-line and each
|
||||||
|
# line is scanned for SQL comments (which end at the end of the
|
||||||
|
# line), and these are stripped. Blank lines are skipped too to
|
||||||
|
# compress the output a little.
|
||||||
|
# THROWS: No exceptions
|
||||||
|
# COMMENTS: None
|
||||||
|
# SEE ALSO: N/A
|
||||||
|
#===============================================================================
|
||||||
|
sub strip_sql_comments { #{{{
|
||||||
|
my ($query) = @_;
|
||||||
|
|
||||||
|
my $result;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip C-style comments
|
||||||
|
#
|
||||||
|
$query =~ s/\/\*.*?\*\///sg;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Strip SQL line-oriented comments
|
||||||
|
#
|
||||||
|
foreach my $line (split(/\n/,$query)) {
|
||||||
|
next if $line =~ /^\s*$/;
|
||||||
|
$line =~ s/--.*$//;
|
||||||
|
$result .= "$line\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _debug
|
# NAME: _debug
|
||||||
# PURPOSE: Prints debug reports
|
# PURPOSE: Prints debug reports
|
||||||
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
# PARAMETERS: $active Boolean: 1 for print, 0 for no print
|
||||||
# $message Message to print
|
# @messages Messages to print
|
||||||
# RETURNS: Nothing
|
# RETURNS: Nothing
|
||||||
# DESCRIPTION: Outputs a message if $active is true. It removes any trailing
|
# DESCRIPTION: Outputs messages if $active is true. It removes any trailing
|
||||||
# newline and then adds one in the 'print' to the caller doesn't
|
# newlines and then adds one to each line so the caller doesn't
|
||||||
# have to bother. Prepends the message with 'D> ' to show it's
|
# have to bother. Prepends 'D> ' to each message to show it's
|
||||||
# a debug message.
|
# a debug message.
|
||||||
# THROWS: No exceptions
|
# THROWS: No exceptions
|
||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub _debug {
|
sub _debug { #{{{
|
||||||
my ( $active, $message ) = @_;
|
my ( $active, @messages ) = @_;
|
||||||
|
|
||||||
chomp($message);
|
if ($active) {
|
||||||
print STDERR "D> $message\n" if $active;
|
chomp(@messages);
|
||||||
}
|
say STDERR "D> ", join( "\nD> ", @messages );
|
||||||
|
}
|
||||||
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _dbargs
|
# NAME: _dbargs
|
||||||
@@ -414,7 +460,7 @@ sub _debug {
|
|||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO: N/A
|
# SEE ALSO: N/A
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub _dbargs {
|
sub _dbargs { #{{{
|
||||||
my ($opts) = @_;
|
my ($opts) = @_;
|
||||||
|
|
||||||
my @args;
|
my @args;
|
||||||
@@ -424,7 +470,7 @@ sub _dbargs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (@args);
|
return (@args);
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _define
|
# NAME: _define
|
||||||
@@ -439,7 +485,7 @@ sub _dbargs {
|
|||||||
# COMMENTS: None
|
# COMMENTS: None
|
||||||
# SEE ALSO:
|
# SEE ALSO:
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub _define {
|
sub _define { #{{{
|
||||||
my ($opts) = @_;
|
my ($opts) = @_;
|
||||||
|
|
||||||
my %defs;
|
my %defs;
|
||||||
@@ -449,7 +495,7 @@ sub _define {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (%defs);
|
return (%defs);
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: Options
|
# NAME: Options
|
||||||
@@ -461,7 +507,7 @@ sub _define {
|
|||||||
# COMMENTS: none
|
# COMMENTS: none
|
||||||
# SEE ALSO: n/a
|
# SEE ALSO: n/a
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
sub Options {
|
sub Options { #{{{
|
||||||
my ($optref) = @_;
|
my ($optref) = @_;
|
||||||
|
|
||||||
my @options = (
|
my @options = (
|
||||||
@@ -477,7 +523,7 @@ sub Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} #}}}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|
||||||
@@ -492,7 +538,7 @@ query2tt2 - A script for formatting a report from database query using a templat
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
This documentation refers to query2tt2 version 0.0.8
|
This documentation refers to query2tt2 version 0.0.9
|
||||||
|
|
||||||
=head1 USAGE
|
=head1 USAGE
|
||||||
|
|
||||||
|
135
hpr_container_email_shownotes.sh
Executable file
135
hpr_container_email_shownotes.sh
Executable file
@@ -0,0 +1,135 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#License: GPL v3
|
||||||
|
#see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#Name: button_hpr_container.sh
|
||||||
|
#Purpose: build/run HPR Container.
|
||||||
|
#Version: beta 0.01
|
||||||
|
#Author: SGOTI (Some Guy On The Internet)
|
||||||
|
#Email: Lyunpaw@gmail.com
|
||||||
|
#Date: 2025-04-19
|
||||||
|
|
||||||
|
#declaration:
|
||||||
|
declare bindir="/usr/bin/"
|
||||||
|
declare podman="${bindir}podman"
|
||||||
|
declare echo="builtin echo -e"
|
||||||
|
declare unprivilegedUser="janitor"
|
||||||
|
declare date="${bindir}date"
|
||||||
|
declare flags
|
||||||
|
declare OPTIND
|
||||||
|
declare -A containerBulidProperties
|
||||||
|
|
||||||
|
declare currentMonth
|
||||||
|
declare nextMonth
|
||||||
|
declare currentYear
|
||||||
|
|
||||||
|
#start:
|
||||||
|
currentMonth=$(${date} +%m)
|
||||||
|
currentYear=$(${date} +%Y)
|
||||||
|
|
||||||
|
if [[ ${currentmonth} -gt 0 ]] && [[ ${currentmonth} -le 11 ]]; then
|
||||||
|
nextMonth="(($(${date} +%m)+01))" #Incomplete: Can return single-digit integer; must be a double-digit integer.
|
||||||
|
else
|
||||||
|
nextMonth="01"
|
||||||
|
fi
|
||||||
|
|
||||||
|
containerBulidProperties=(
|
||||||
|
"containerFile" "/path/to/Containerfile"
|
||||||
|
"hostMountDir01" "/path/to/project/directory"
|
||||||
|
"hostMountDir02" "/tmp/"
|
||||||
|
"containerMountDir01" "/opt/hpr/"
|
||||||
|
"containerMountDir02" "/tmp/hpr/"
|
||||||
|
"containerImageTag" "hpr_image:5.40.1"
|
||||||
|
"pullNewImage" "podman pull docker.io/library/perl"
|
||||||
|
"recordingDate" "$(${date} -d "${currentYear}/${currentMonth}/01")"
|
||||||
|
"recordingTimeStart" "15:00" #TZ: UTC
|
||||||
|
"recordingTimeEnd" "17:00" #TZ: UTC
|
||||||
|
)
|
||||||
|
|
||||||
|
function runHPRContainer () {
|
||||||
|
local makeEmail #Incomplete:
|
||||||
|
makeEmail="./make_email -month=${containerBulidProperties[recordingDate]} -start=15:00 -end=17:00 -out=/tmp/hpr/%semail.txt"
|
||||||
|
local makeShownotes #Incomplete:
|
||||||
|
makeShownotes="/opt/hpr/src/hpr-tools/Community_News/make_shownotes -from=${containerBulidProperties[recordingDate]} -full=/tmp/hpr/%sfull_shownotes.html -mail -comments"
|
||||||
|
|
||||||
|
${podman} run \
|
||||||
|
--mount type=bind,src=${containerBulidProperties[hostMountDir02]},dst=${containerBulidProperties[containerMountDir02]},rw=true \
|
||||||
|
--label="Project"="HPR" \
|
||||||
|
--label="Forge"="https://repo.anhonesthost.net/HPR/" \
|
||||||
|
--interactive \
|
||||||
|
--tty \
|
||||||
|
--rm=true \
|
||||||
|
--privileged=false \
|
||||||
|
--pull="never" \
|
||||||
|
--cgroups=enabled \
|
||||||
|
--cgroupns=private \
|
||||||
|
--uts=private \
|
||||||
|
--pid=private \
|
||||||
|
--memory="32m" \
|
||||||
|
--memory-reservation="16m" \
|
||||||
|
--hostname="hpr" \
|
||||||
|
--name="hpr_project" \
|
||||||
|
--user="${unprivilegedUser}" \
|
||||||
|
${containerBulidProperties[containerImageTag]} bash;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildNewContainerImage () {
|
||||||
|
if [[ -f "${containerBulidProperties[containerFile]}" ]]; then
|
||||||
|
${echo} "Building new container image...\nThis may take several minutes.\
|
||||||
|
\nThis is a non interactive build process, so you can return when \
|
||||||
|
it's completed.";
|
||||||
|
${podman} build --file="${containerBulidProperties[containerFile]}" --tag="${containerBulidProperties[containerImageTag]}";
|
||||||
|
else
|
||||||
|
${echo} 'Dont forget to assign the ${containerBulidProperties[containerFile]} ;). The Containerfile is needed to build the container image.'
|
||||||
|
fi
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function help () {
|
||||||
|
${echo} "$0 [-hbpq]\n\t[-h] help\n\t[-b] build new container\n\t[-p] pull new perl image\n\t[-q] quit";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts 'hbpq' flags; do
|
||||||
|
case "${flags}" in
|
||||||
|
h) help; exit 0;
|
||||||
|
;;
|
||||||
|
|
||||||
|
i) ${echo} "Work in progress... :D"; break;
|
||||||
|
;;
|
||||||
|
|
||||||
|
b) buildNewContainerImage;
|
||||||
|
;;
|
||||||
|
|
||||||
|
p) ${containerBulidProperties[pullNewImage]}; exit 0;
|
||||||
|
;;
|
||||||
|
|
||||||
|
e) ${echo} "Work in progress... :D"; break;
|
||||||
|
;;
|
||||||
|
|
||||||
|
s) ${echo} "Work in progress... :D"; break;
|
||||||
|
;;
|
||||||
|
|
||||||
|
q)
|
||||||
|
${echo} "Quitting script."; break;
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
${echo} "Good Heavens! Wrong input."; help; exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
if [[ -z ${1} ]]; then help; runHPRContainer; fi;
|
||||||
|
|
||||||
|
unset echo
|
||||||
|
unset flags
|
||||||
|
unset podman
|
||||||
|
unset OPTIND
|
||||||
|
unset currentMonth
|
||||||
|
unset currentYear
|
||||||
|
unset containerBulidProperties
|
||||||
|
exit 0
|
||||||
|
|
@@ -2,7 +2,14 @@
|
|||||||
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/
|
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/
|
||||||
#============================================================
|
#============================================================
|
||||||
|
|
||||||
find ${HOME}/processing/ -type f | egrep -v '/sponsor-anhonesthost.com-hpr15.flac|/outro.flac|/intro.flac|/sponsor-archive.org.flac' | while read mediafile
|
search_dir="${HOME}/processing/"
|
||||||
|
|
||||||
|
if [ -d "${1}" ]
|
||||||
|
then
|
||||||
|
search_dir="${1}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
find ${search_dir} -type f | grep -vP '/sponsor-anhonesthost.com-hpr15.flac|/outro.flac|/intro.flac|/sponsor-archive.org.flac' | while read mediafile
|
||||||
do
|
do
|
||||||
duration=$( mediainfo --full --Output=XML "${mediafile}" | xmlstarlet sel -T -t -m "_:MediaInfo/_:media/_:track[@type='Audio']/_:Duration[1]" -v "." -n - | awk -F '.' '{print $1}' )
|
duration=$( mediainfo --full --Output=XML "${mediafile}" | xmlstarlet sel -T -t -m "_:MediaInfo/_:media/_:track[@type='Audio']/_:Duration[1]" -v "." -n - | awk -F '.' '{print $1}' )
|
||||||
if [ "${duration}" != "" ]
|
if [ "${duration}" != "" ]
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user