Archived
4
2

56 Commits

Author SHA1 Message Date
Roan Horning
4fa79187a9 Update 'README.md'
Add Ken Fallon
2023-03-31 21:00:50 +00:00
Roan Horning
d5406f3cce Merge pull request '[I101] This reflects the change to move the "play" button to the top of the episode' (#102) from I101_Move_play_button_to_the_top into main
Reviewed-on: #102
2023-03-31 20:56:32 +00:00
Ken Fallon
5369bea657 This reflects the change to move the "play" button to the top of the episode 2023-03-31 14:02:49 +02:00
Roan Horning
0e9ad6ba65 Merge pull request 'Added lazy loading attribute to images in show notes.' (#100) from I99_Lazy_load_notes_images into main
Reviewed-on: #100
2023-03-28 02:19:47 +00:00
Gordon Stanton
610e91ea9f Added lazy loading attribute to images in show notes. 2023-03-19 22:51:21 +11:00
Roan Horning
860ce671f8 Merge pull request 'Moved thumbnail image tag to Block with conditional lazy load.' (#95) from I90_Lazy_load_host_avatars into main
Reviewed-on: #95
2023-03-16 16:13:48 +00:00
Roan Horning
51d6188542 Merge branch 'main' into I90_Lazy_load_host_avatars 2023-03-14 03:20:35 +00:00
c9278c0dd6 Remove unused PROCESS directive 2023-03-13 23:16:37 -04:00
aabeca44f5 Refactor templates to use show_avatar MACRO 2023-03-13 23:15:46 -04:00
3a8b6db348 Add show_avatar MACRO 2023-03-13 23:14:35 -04:00
7a6ace156f Refactor template to use get_avatar MACRO 2023-03-13 23:13:25 -04:00
dee924e6a8 Rename MACRO host_thumb to get_avatar
Update to use lazy_load MACRO and minimize number of
arguments needed.
2023-03-13 23:10:36 -04:00
5b4421071f Add MACRO lazy_load
Macro which allows programatically setting the HTML5 img
loading attribute.
2023-03-13 23:03:15 -04:00
Roan Horning
61311b30dd Merge pull request '[I96] Add acknowledgement of gordons' (#98) from I96-updated_list_of_acknowledgements into main
Reviewed-on: #98
2023-03-14 00:50:52 +00:00
7406a9baa4 Add acknowledgement of gordons 2023-03-13 20:47:59 -04:00
Gordon Stanton
ce4aefe828 Renamed macro get_avatar to get_avatar_src as per suggestion.
Moved host_thumb macro into shared avatar template file.
Made condition of lazy loading a parameter.
2023-03-12 18:48:51 +11:00
Gordon Stanton
ebcd906300 Moved thumbnail image tag to Block with conditional lazy load. 2023-03-11 01:57:51 +11:00
Roan Horning
3b144ecaf5 Merge pull request '[I87] Getting Started tutorial' (#89) from I87-Getting_Started_tutorial into main
Reviewed-on: #89
2023-03-10 02:44:53 +00:00
fc7975379e Fix grammer issues 2023-03-09 21:42:36 -05:00
207eabec86 Add reference to the file GETTING_STARTED.md
Update the Installation instructions to include reference
to the Getting Started tutorial.
2023-03-09 21:39:53 -05:00
c9af4fbde8 Merge branch 'main' into I87-Getting_Started_tutorial 2023-03-09 21:04:02 -05:00
Roan Horning
e557f103b9 Merge pull request '[I91] Fix link to comments viewer in about navigation menu' (#94) from I91-Fix_comments_viewer_link into main
Reviewed-on: #94
2023-03-10 02:02:00 +00:00
ea8403c7b6 Fix link to comments viewer in about navigation menu 2023-03-09 20:59:26 -05:00
b16a1c3a5f Merge branch 'main' into I87-Getting_Started_tutorial 2023-03-09 20:38:48 -05:00
Roan Horning
8783ca5099 Merge pull request '[I92] paramertize paths for configuration, templates, and HTML files' (#93) from I92-templates_and_output_directory_options into main
Reviewed-on: #93
2023-03-10 01:34:21 +00:00
f65e892182 Add template and HTML folder configuration options
Allow user to set the path for the website templates and
output folders in the site.cfg file.
2023-03-09 20:25:25 -05:00
14bafbc3ab Add command line option for path to configuration file
Allow user to pass the path to the configuration file into the
site-generator.
2023-03-08 22:23:56 -05:00
231a50957f Fix clone command of repositories 2023-03-07 19:33:09 -05:00
Roan Horning
bdc28d21c4 Merge branch 'main' into I87-Getting_Started_tutorial 2023-03-08 00:22:37 +00:00
9310a8642d Add instructions for running the site-configurator 2023-03-07 19:11:19 -05:00
97a5d4ebbd Add instructions for configuring the site-generator 2023-03-07 19:09:33 -05:00
b420453abd Add instructions for creating HPR SQLite file 2023-03-07 19:06:29 -05:00
7feae31e11 Add helper script that creates the HPR SQLite file 2023-03-07 19:03:08 -05:00
d6068778ab Add instructions for installing Perl modules 2023-03-07 18:55:08 -05:00
82d761bf68 Update Clone the Repository section
Add reference to the gitlab.com mirror repository.
2023-03-07 18:53:03 -05:00
Roan Horning
0f4fdc2d46 Merge pull request 'Add lazy loading to host image' (#88) from I83_Lazy_load_host_images into main
Reviewed-on: #88
2023-03-04 22:00:52 +00:00
Roan Horning
d3c2401e28 Merge branch 'main' into I83_Lazy_load_host_images 2023-03-04 22:00:21 +00:00
Gordon Stanton
c744bdf175 Moved host thumbnail image tag to separate template file.
Added loading="lazy" to image tag.
Changed alt text to show host username.
2023-03-05 02:07:03 +11:00
16d6cf99aa Add instructions for cloning the repository 2023-03-04 09:27:56 -05:00
add4f338be Add Getting Started tutorial
Currently a very high level outline of the document.
2023-03-04 09:10:06 -05:00
Roan Horning
444c05f8f9 Merge pull request '[I82] creating sqlite db from hpr.sql' (#86) from I82_creating-sqlite-db-from-hpr.sql into main
Reviewed-on: #86
2023-03-04 05:00:40 +00:00
24a12a5af3 Update instructions for creating SQLite db
Update the main README file and the POD Installation section
of the site-configuration program.
2023-03-03 23:53:21 -05:00
add92ef20d Add utility script to refresh the local website
This script  will download latest MySQL dump file from
hacckerpublicradio.org. Generate a new hpr.db SQLite file,
and then regenerate all of the website files.
2023-03-03 23:32:35 -05:00
f8e397d0bd Add required script mysql2sqlite to repository
Converts MySQL dump to SQLite3 compatible dump
    (including MySQL KEY xxxxx statements from the CREATE block).

    Website: https://github.com/dumblob/mysql2sqlite
    The MIT License (MIT)
    Copyright (c) 2015 esperlu, 2016 dumblob
2023-03-03 23:00:50 -05:00
6d588dc558 Merge branch 'main' into I82_creating-sqlite-db-from-hpr.sql 2023-03-03 22:52:21 -05:00
Roan Horning
f0b0b5ea59 Merge pull request 'Fix database instructions in configuration file' (#85) from Fix_db_sqlite_settings into main
Reviewed-on: #85
2023-03-04 03:49:09 +00:00
a33fa197df Fix database instructions in configuration file
Add back instructions for SQLite
2023-03-03 22:44:05 -05:00
e7e752f1e8 Improve function messages 2023-03-03 21:47:29 -05:00
094287837c Put variables into local scope of the function
Forgot to use the local keyword when declaring the variables.
2023-03-03 21:44:35 -05:00
a53f201842 Code formatting with no functional changes 2023-03-03 20:46:34 -05:00
2ce1280cc0 Make functional stub function copy_to_public_dir 2023-03-03 20:45:16 -05:00
d45ca0de96 Make functional stub function make_hpr_sqlite_db 2023-03-03 20:42:42 -05:00
13aeb647ad Make functional stub function download_hpr_sql 2023-03-03 20:41:29 -05:00
ee6a4e601d Fill out function clean_working_dir 2023-02-27 23:30:24 -05:00
b544687f0f Fill out stub of make_working_dir function 2023-02-27 23:27:26 -05:00
0ed7efe93b Initial add of bash library for update utils
Stubs for functions to be used in update scripts.
2023-02-27 21:07:01 -05:00
16 changed files with 915 additions and 54 deletions

202
GETTING_STARTED.md Normal file
View File

@@ -0,0 +1,202 @@
# Clone the repository
If git is not installed on the operating system, please install it now
(see the git documentation for [instructions on installing git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)).
To retrieve the code from the repository on anhonesthost.net (a username and
password are required), run:
`git clone https://repo.anhonesthost.net/rho_n/hpr_generator.git`
To retrieve the code from the repository on gitlab.com, run:
`git clone https://gitlab.com/roan.horning/hpr_generator.git`
On success, an "hpr_generator" directory will be created in the folder from
which the clone command was executed containing a local copy of the git repository.
# Install required Perl modules
Installing the Perl modules is the most finicky part of the installation process.
The needed Perl modules can be found using the operating system's package
manager or using the modules found in the
[Comprehensive Perl Archive Network (CPAN)](https://www.cpan.org/).
## Installing modules on Debian based Linux distributions
Run command (tested on Debian 11):
```
apt install libconfig-std-perl \
libtemplate-perl \
libtemplate-plugin-dbi-perl \
libdbd-sqlite3-perl libdate-calc-perl \
libtie-dbi-perl
```
## Using CPAN to install the modules
A cross platform method to install the needed modules is the Perl CPAN application.
Make sure both the [make](https://www.gnu.org/software/make/manual/make.html)
command and the [cpan](https://perldoc.perl.org/CPAN) command are available.
Install them using the operating system's package manager, or from source.
Run commands:
```
cpan Config::Std
cpan Template
cpan Template::Plugin::DBI
cpan DBD::SQLite
cpan Date::Calc
cpan Tie::DBI
```
# Create the HPR database
The hpr_generator relies on information from a database to generate many of the
files for the website (for example: index.html, series/index.html,
hpr_mp3.rss, etc). This data is available from a MySQL dump file found on
hackerpublicradio.org at URL "https://www.hackerpublicradio.org/hpr.sql".
The first step is to download the hpr.sql file. This can be done using your
browser, or by running one of the following commands:
`curl https://www.hackerpublicradio.org/hpr.sql --output ./hpr.sql`
or
`wget --directory-prefix=./ https://www.hackerpublicradio.org/hpr.sql`
## Creating an SQLite database file
The SQL of the hpr.sql file must be converted from MySQL specific statements to
SQLite specific statements. The mysql2sqlite script found in the utils directory
is used for this conversion. First remove the lines from hpr.sql that
mysql2sqlite can't handle:
`sed '/^DELIMITER ;;/,/^DELIMITER ;/d' < ./hpr.sql > ./hpr-sqlite.sql`
Next run the mysql2sqlite script piping its output into the sqlite3
program which creates the hpr.db file:
`./utils/mysql2sqlite ./hpr-sqlite.sql | sqlite3 ./hpr.db`
For convenience, the update-sqlite-db.sh script in the utils directory
automates the above steps (including downloading the hpr.sql file).
From the root of the local hpr_generator repository run:
`./utils/update-sqlite-db.sh`
# Configure the site-generator
In your favorite text editor, open the site.cfg file found in the root of the
"hpr_generator" folder. Full details about options for configuring the site.cfg
file are found in the comments within the file.
## Configuring the database connection
Any database supported by the Perl:DBI and Perl::DBD modules can be used with
the site-generator program. Currently the hpr_generator project works with
a MySQL or SQLite database.
Find the [DBI] section of the file. It should look like the following
```
[DBI]
# Configuration settings for SQLite
#database: sqlite
#driver: dbi:SQLite:hpr.db
#user: (not used - leave blank)
#password: (not used - leave blank)
# Configuration settings for MySQL
#database: mysql
#driver: dbi:mysql:database=hpr_hpr:hostname=localhost
#user: hpr-generator (Suggested user with read-only privileges)
#password: ********* (Password for user)
```
### SQLite
Remove the comment character from the start of the database and driver
option lines:
```
# Configuration settings for SQLite
database: sqlite
driver: dbi:SQLite:hpr.db
#user: (not used - leave blank)
#password: (not used - leave blank)
```
The hpr.db section of the driver option `dbi:SQLite:hpr.db` is the path
to the sqlite file. The default assumes the hpr.db file is located in the same
directory as the site-generator.
### MySQL
Remove the comment character from the start of the database, driver,
user, and password option lines:
```
# Configuration settings for MySQL
database: mysql
driver: dbi:mysql:database=hpr_hpr:hostname=localhost
user: hpr-generator
password: *********
```
This assumes that the MySQL database service is available at the localhost
hostname, that the database name (hpr_hpr) is the database created from
the hpr.sql dump file or manually created by you, that the user (hpr-generator)
was added by you and has read rights to the hpr_hpr database, and that the
password (replace ********* with the actual password) matches the password set
for the hpr-generator database user.
## Configuring the website for viewing locally
For HTML links to work when viewing the files on your local machine using the
"file://" protocal (i.e. using the "Open..." command in your browser, each HTML
file must include a \<base\> meta-data tag in the \<head\> section of its
contents. To configure this in the site.cfg file, find the [root_template]
section. It should look like the following:
```
[root_template]
content: page.tpl.html
#baseurl: OPTIONAL [i.e. file://<full path to local website directory>]
```
Below the #baseurl comment line add:
```
baseurl: file://</path/to>/hpr_generator/public_html
```
Replace \<path/to\> with the full path to the hpr_generator directory. For
example: `file:///home/rho_n/development/hpr_generator/public_html`
## Configuring the website media file links
If you do not want to host all the media files (currently, audio files and
transcription files), you can configure the `media_baseurl` option. This can
be added to the [root_template] section of the site.cfg file. Suggested
external site is archive.org. To use this site add:
```
media_baseurl: https://archive.org/download/hpr$eps_id/
```
# Run the site-generator
Run the site generator form the hpr_generator directory:
```
./site-generator --all
```
This will generate all the files for the website. For more examples and to see
all available options run:
```
./site-generator --help
```

View File

@@ -4,10 +4,15 @@ Static web page generator for the Hacker Public Radio website.
## Installation ## Installation
* Clone or download this repository * Clone or download this repository
* With SQLite * With SQLite
* Create the sqlite3 database from the files in the _sql directory. The default name for the database file is "hpr.db" and should be located in the root of the project directory. The name and location can be set in the site.cfg file. * Create the sqlite3 database from the hpr.sql MySQL dump file available on
* Two sql helper scripts are available to generate an empty database or a database filled with test data. hackerpublicradio.org. The default name for the database file is "hpr.db"
- For an empty database: `cat Create_Database_Empty.sql | sqlite3 hpr.db` and should be located in the root of the project directory. The name and
- For a database with test data: `cat Create_Database_Test.sql | sqlite3 hpr.db` location can be set in the site.cfg file.
* An "update-hpr.sh" helper script is available in the utils directory. This
script will download the hpr.sql file, convert it to the SQLite hpr.db file,
and regenerate the website using the site-generator.
1. `cd` into the root of the project directory
2. Run `./utils/update-hpr.sh`
* SQLite v3.8.3 or greater is recommended. CTE WITH clauses are used in some template queries. Must convert WITH * SQLite v3.8.3 or greater is recommended. CTE WITH clauses are used in some template queries. Must convert WITH
clauses to sub-queries when using earlier versions of SQLite. clauses to sub-queries when using earlier versions of SQLite.
* With MySQL * With MySQL
@@ -30,7 +35,8 @@ Static web page generator for the Hacker Public Radio website.
* Tie::DBI * Tie::DBI
* DBD::SQLite or DBD:mysql * DBD::SQLite or DBD:mysql
* Date::Calc * Date::Calc
* See the Getting Started tutorial (GETTING_STARTED.md) for more details on
installing the HPR generator.
## Usage ## Usage
Generate two specific pages: Generate two specific pages:
`site-generator index about` `site-generator index about`
@@ -60,3 +66,5 @@ and add the label "**Feature Request**".
## Authors and acknowledgment ## Authors and acknowledgment
* Roan "Rho`n" Horning * Roan "Rho`n" Horning
* gordons
* Ken Fallon

View File

@@ -8,12 +8,13 @@
site-generator [OPTION]... PAGE|PAGE=<comma separated list of ids>... site-generator [OPTION]... PAGE|PAGE=<comma separated list of ids>...
-a, --all generate all pages defined in configuration file -a, --all generate all pages defined in configuration file
-l, --list print list of configured pages -c, --configure path to configuration file
-p, --preview print generated pages to standard out -l, --list print list of configured pages
-q, --quiet suppress progress information while generating pages -p, --preview print generated pages to standard out
-v, --verbose print extended progress information while generating pages -q, --quiet suppress progress information while generating pages
--help print this help message -v, --verbose print extended progress information while generating pages
--help print this help message
Where I<PAGE> is a file name of a web page Where I<PAGE> is a file name of a web page
or the special I<ALL> (to generate all pages). or the special I<ALL> (to generate all pages).
@@ -36,12 +37,15 @@ This is a site generator for the Hacker Public Radio website based upon the Perl
=head1 INSTALLATION =head1 INSTALLATION
With SQLite With SQLite
* Create the sqlite3 database from the files in the _sql directory. The default name for the * Create the sqlite3 database from the hpr.sql MySQL dump file available on
database file is "hpr.db" and should be located in the root of the project directory. The hackerpublicradio.org. The default name for the database file is "hpr.db"
name and location can be set in the site.cfg file. and should be located in the root of the project directory. The name and
* Two sql helper scripts are available to generate an empty database or a database filled with test data. location can be set in the site.cfg file.
- For an empty database: cat Create_Database_Empty.sql | sqlite3 hpr.db * An "update-hpr.sh" helper script is available in the utils directory. This
- For a database with test data: cat Create_Database_Test.sql | sqlite3 hpr.db script will download the hpr.sql file, convert it to the SQLite hpr.db file,
and regenerate the website using the site-generator.
1. `cd` into the root of the project directory
2. Run `./utils/update-hpr.sh`
* SQLite v3.8.3 or greater is recommended. CTE WITH clauses are used in some template queries. * SQLite v3.8.3 or greater is recommended. CTE WITH clauses are used in some template queries.
Must convert WITH clauses to sub-queries when using earlier versions of SQLite. Must convert WITH clauses to sub-queries when using earlier versions of SQLite.
@@ -106,15 +110,17 @@ sub main {
# Argument parsing # Argument parsing
my $all; my $all;
my $configuration_path;
my $preview; my $preview;
my $verbose; my $verbose;
my $quiet; my $quiet;
GetOptions( GetOptions(
'all' => \$all, 'all' => \$all,
'list' => \&print_available_pages, 'configuration=s' => \$configuration_path,
'preview' => \$preview, 'list' => \&print_available_pages,
'verbose' => \$verbose, 'preview' => \$preview,
'quiet' => \$quiet, 'verbose' => \$verbose,
'quiet' => \$quiet,
) or pod2usage(1); ) or pod2usage(1);
pod2usage(1) unless @ARGV || $all; pod2usage(1) unless @ARGV || $all;
my (@page_args) = @ARGV; my (@page_args) = @ARGV;
@@ -123,10 +129,21 @@ sub main {
$verbose = 'quiet'; $verbose = 'quiet';
}; };
# Load config file if (!$configuration_path) {
read_config "site.cfg" => my %config; $configuration_path = "site.cfg";
}
my $tt = get_template_html($config{DBI}); my %config;
if ( -f $configuration_path ) {
# Load config file
read_config $configuration_path => %config;
}
else {
print STDOUT "Could not read configuration file: $configuration_path\n";
exit 1;
}
my $tt = get_template_html($config{DBI}, $config{app_paths});
# If command line option all is set, parse configuration file # If command line option all is set, parse configuration file
# for all pages # for all pages
@@ -137,7 +154,7 @@ sub main {
# from the generated list of pages. # from the generated list of pages.
@page_args= grep { $_ ne 'DBI' } @page_args; @page_args= grep { $_ ne 'DBI' } @page_args;
@page_args= grep { $_ ne 'root_template' } @page_args; @page_args= grep { $_ ne 'root_template' } @page_args;
@page_args= grep { $_ ne 'media_hostname' } @page_args; @page_args= grep { $_ ne 'app_paths' } @page_args;
}; };
foreach my $page_arg (@page_args) { foreach my $page_arg (@page_args) {
@@ -190,8 +207,8 @@ sub get_template_html (\%@) {
# HTML comments to make the template file valid HTML. # HTML comments to make the template file valid HTML.
# #
return Template->new({ return Template->new({
INCLUDE_PATH => './templates', INCLUDE_PATH => $_[1]{templates_path},
OUTPUT_PATH => './public_html', OUTPUT_PATH => $_[1]{output_path},
EVAL_PERL => 1, EVAL_PERL => 1,
START_TAG => '<!--%', START_TAG => '<!--%',
END_TAG => '%-->', END_TAG => '%-->',

View File

@@ -2,10 +2,21 @@
# with the database. # with the database.
# dbi:<driver name [SQLite, CSV, ADO, mSQL, etc.]>:<database name> # dbi:<driver name [SQLite, CSV, ADO, mSQL, etc.]>:<database name>
[DBI] [DBI]
database: mysql # Configuration settings for SQLite
driver: dbi:mysql:database=hpr_hpr:hostname=localhost #database: sqlite
user: hpr-generator #driver: dbi:SQLite:hpr.db
password: zBozqN-Z2zNAz #user: (not used - leave blank)
#password: (not used - leave blank)
# Configuration settings for MySQL
#database: mysql
#driver: dbi:mysql:database=hpr_hpr:hostname=localhost
#user: hpr-generator (Suggested user with read-only privileges)
#password: ********* (Password for user)
# Configure the location of the templates and the generated HTML
[app_paths]
templates_path: ./templates
output_path: ./public_html
# Configure the root template page which pulls in the navigation and # Configure the root template page which pulls in the navigation and
# content templates used by each page. An optional baseurl property may # content templates used by each page. An optional baseurl property may

View File

@@ -1,5 +1,4 @@
<!--% PROCESS 'shared-episode-summary.tpl.html' %--> <!--% PROCESS 'shared-episode-summary.tpl.html' %-->
<!--% PROCESS 'shared-avatar.tpl.html' %-->
<!--% PROCESS 'shared-utils.tpl.html' %--> <!--% PROCESS 'shared-utils.tpl.html' %-->
<!--% PROCESS 'shared-listen-now.tpl.html' %--> <!--% PROCESS 'shared-listen-now.tpl.html' %-->
<!--% PROCESS "queries-episode-${constants.database}.tpl.html" %--> <!--% PROCESS "queries-episode-${constants.database}.tpl.html" %-->

View File

@@ -55,8 +55,7 @@
<!--% this_host = hosts.$id %--> <!--% this_host = hosts.$id %-->
<h2 class="title">Correspondent</h2> <h2 class="title">Correspondent</h2>
<h2><!--% this_host.host %--></h2> <h2><!--% this_host.host %--></h2>
<p><img src="<!--% absolute_path(baseurl) %-->images/<!--% get_avatar(this_host.hostid) %-->" <p><!--% get_avatar(this_host.hostid, this_host.host) %--><br>
height="80" alt="Host Image" /><br>
<label>Host ID</label>: <!--% this_host.hostid %--><br><br> <label>Host ID</label>: <!--% this_host.hostid %--><br><br>
<label>email:</label> <u><!--% this_host.email %--></u><br> <label>email:</label> <u><!--% this_host.email %--></u><br>
<label>episodes:</label> <strong><!--% hpr_show_count + twat_show_count %--></strong> <label>episodes:</label> <strong><!--% hpr_show_count + twat_show_count %--></strong>

View File

@@ -1,9 +1,10 @@
<!--% PROCESS 'shared-utils.tpl.html' %--> <!--% PROCESS 'shared-utils.tpl.html' %-->
<!--% PROCESS 'shared-avatar.tpl.html' %-->
<article> <article>
<h2 class="title">Correspondents</h2> <h2 class="title">Correspondents</h2>
<p>For more information on how to become a Correspondent see our <a href="<!--% absolute_path(baseurl) %-->contribute.html">contribute</a></center> page. To add a logo here, either email one to admin at hpr or setup your email on <a href="https://en.gravatar.com/">Gravatar</a>. To protect your browsing privacy we gather the images every hour and serve them directly from HPR.<p /> <p>For more information on how to become a Correspondent see our <a href="<!--% absolute_path(baseurl) %-->contribute.html">contribute</a></center> page. To add a logo here, either email one to admin at hpr or setup your email on <a href="https://en.gravatar.com/">Gravatar</a>. To protect your browsing privacy we gather the images every hour and serve them directly from HPR.<p />
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% PROCESS 'shared-avatar.tpl.html' %--> <!--% host_cnt = 0 %-->
<table class="hosts"> <table class="hosts">
<th >Avatar</th> <th >Avatar</th>
<th >Name &amp; Host ID</th> <th >Name &amp; Host ID</th>
@@ -17,14 +18,14 @@
on h.hostid = e.hostid ' on h.hostid = e.hostid '
) %--> ) %-->
<tr height="80"> <tr height="80">
<td><img src="<!--% absolute_path(baseurl) %-->images/<!--% get_avatar(host.hostid) %-->" height="80" width="80" alt="avatar" /></td> <td><!--% get_avatar(host.hostid, host.host, host_cnt > 8) %--></td>
<td><strong><!--% host.host %--></strong><br> <td><strong><!--% host.host %--></strong><br>
Host ID: <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(host.hostid) %-->.html"><!--% host.hostid %--></a></td> Host ID: <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(host.hostid) %-->.html"><!--% host.hostid %--></a></td>
<td><!--% host.license %--></td> <td><!--% host.license %--></td>
<td><!--% host.date %--></td> <td><!--% host.date %--></td>
</tr> </tr><!--% host_cnt = host_cnt + 1 %-->
<!--% END %--> <!--% END %-->
</table> </table>
<p><a href="<!--% absolute_path(baseurl) %-->contribute.html">Become a Correspondent</a></p> <p><a href="<!--% absolute_path(baseurl) %-->contribute.html">Become a Correspondent</a></p>

View File

@@ -16,10 +16,10 @@
<h3><!--% episode.summary %--></h3> <h3><!--% episode.summary %--></h3>
<p class="meta"><!--% episode_navigation %--> <p class="meta"><!--% episode_navigation %-->
</p> </p>
<p><!--% IF get_avatar(episode.hostid) != 'hpr_logo.png' %--> <p><!--% show_avatar(episode.hostid, episode.host) %-->
<img src="<!--% absolute_path(baseurl) %-->images/<!--% get_avatar(episode.hostid) %-->" height="80" width="80" alt="" /></a><br><!--% END %-->
Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(episode.hostid) %-->.html"><!--% episode.host %--></a> on <span><!--% episode.date %--></span> is flagged as <span><!--% display_explicit(episode.explicit) %--></span> and is released under a <span><!--% episode.license %--> license</span>. <br> Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(episode.hostid) %-->.html"><!--% episode.host %--></a> on <span><!--% episode.date %--></span> is flagged as <span><!--% display_explicit(episode.explicit) %--></span> and is released under a <span><!--% episode.license %--> license</span>. <br>
<!--% display_tags(episode.tags) %--> <br> <!--% display_tags(episode.tags) %--> <br>
<!--% listen_now(episode, "hpr", baseurl, media_baseurl) %-->
<!--% display_listen_in(episode.id) %--> | <!--% display_listen_in(episode.id) %--> |
<!--% display_comments_tally(episode.id, episode.eps_tally) %--> <!--% display_comments_tally(episode.id, episode.eps_tally) %-->
</p> </p>
@@ -28,10 +28,7 @@ Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pa
</header> </header>
<div><!--% episode.notes %--></div> <div><!--% episode.notes %--></div>
<footer> <footer>
<!--% show_transcript(episode, "hpr", baseurl, media_baseurl) %--> <!--% show_transcript(episode, "hpr", baseurl, media_baseurl) %-->
<!--% listen_now(episode, "hpr", baseurl, media_baseurl) %-->
<p> <p>
<!--% episode_navigation %--> <!--% episode_navigation %-->
</p> </p>

View File

@@ -5,6 +5,24 @@
<!--% PROCESS 'shared-call_for_shows.tpl.html' %--> <!--% PROCESS 'shared-call_for_shows.tpl.html' %-->
<!--% INCLUDE 'content-index-announcement.tpl.html' %--> <!--% INCLUDE 'content-index-announcement.tpl.html' %-->
<!--% PROCESS "queries-index-${constants.database}.tpl.html" %--> <!--% PROCESS "queries-index-${constants.database}.tpl.html" %-->
<!--% MACRO tidy_notes(all_lines) BLOCK %-->
<!--% lines = all_lines %-->
<!--% after_html = all_lines %-->
<!--% img_re = '(?six)^(.*?)\<img ([^\>]+\>)(.+)$' %-->
<!--% lazy_re = '(?i)loading="lazy"' %-->
<!--% WHILE (matches = lines.match(img_re)) %-->
<!--% img_tag = matches.1 %-->
<!--% after_html = matches.2 %-->
<!--% matches.0 %-->
<!--% IF (img_tag.search(lazy_re)) %-->
<img <!--% img_tag %-->
<!--% ELSE %-->
<img loading="lazy" <!--% img_tag %-->
<!--% END %-->
<!--% lines = after_html %-->
<!--% END %-->
<!--% after_html %-->
<!--% END %-->
<hr> <hr>
<article> <article>
<header> <header>
@@ -35,6 +53,7 @@
<hr> <hr>
<!--% PROCESS 'shared-episode-summary.tpl.html' %--> <!--% PROCESS 'shared-episode-summary.tpl.html' %-->
<h1>Latest Shows</h1> <h1>Latest Shows</h1>
<!--% host_cnt = 0 %-->
<!--% FOREACH latest_episodes IN DBI.query(query_latest_episodes) <!--% FOREACH latest_episodes IN DBI.query(query_latest_episodes)
%--> %-->
<hr> <hr>
@@ -42,21 +61,20 @@
<header> <header>
<h1><a href="<!--% absolute_path(baseurl) %-->eps/hpr<!--% zero_pad_left(latest_episodes.id) %-->/index.html">hpr<!--% latest_episodes.id %--> :: <!--% latest_episodes.title %--></a></h1> <h1><a href="<!--% absolute_path(baseurl) %-->eps/hpr<!--% zero_pad_left(latest_episodes.id) %-->/index.html">hpr<!--% latest_episodes.id %--> :: <!--% latest_episodes.title %--></a></h1>
<h3><!--% latest_episodes.summary%--></h3> <h3><!--% latest_episodes.summary%--></h3>
<p class="meta"$><!--% IF get_avatar(latest_episodes.hostid) != 'hpr_logo.png' %--> <p class="meta"$><!--% show_avatar(latest_episodes.hostid, latest_episodes.host, host_cnt) %-->
<img src="<!--% absolute_path(baseurl) %-->images/<!--% get_avatar(latest_episodes.hostid) %-->" height="80" width="80" alt="" /></a><!--% END %--> Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(latest_episodes.hostid) %-->.html"><!--% latest_episodes.host %--></a> on <!--% latest_episodes.date %--> is flagged as <!--% display_explicit(latest_episodes.explicit) %--> and released under a <!--% latest_episodes.license %--> license. <br>
<br>Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(latest_episodes.hostid) %-->.html"><!--% latest_episodes.host %--></a> on <!--% latest_episodes.date %--> is flagged as <!--% display_explicit(latest_episodes.explicit) %--> and released under a <!--% latest_episodes.license %--> license. <br>
<!--% display_tags(latest_episodes.tags) %--><br> <!--% display_tags(latest_episodes.tags) %--><br>
<!--% listen_now(latest_episodes, "hpr", baseurl, media_baseurl) %-->
<small><!--% display_listen_in(latest_episodes.id) %--> <!--% show_series(latest_episodes.series, latest_episodes.seriesid) %--> | <small><!--% display_listen_in(latest_episodes.id) %--> <!--% show_series(latest_episodes.series, latest_episodes.seriesid) %--> |
<!--% display_comments_tally(latest_episodes.id, latest_episodes.eps_tally) %--></small> <!--% display_comments_tally(latest_episodes.id, latest_episodes.eps_tally) %--></small>
</p> </p>
</header> </header>
<!--% latest_episodes.notes %--> <!--% tidy_notes(latest_episodes.notes) %-->
<footer> <footer>
<!--% show_transcript(latest_episodes, "hpr", baseurl, media_baseurl) %--> <!--% show_transcript(latest_episodes, "hpr", baseurl, media_baseurl) %-->
<!--% listen_now(latest_episodes, "hpr", baseurl, media_baseurl) %-->
</footer> </footer>
</article> </article>
<!--% host_cnt = host_cnt + 1 %-->
<!--% END %--> <!--% END %-->
<article> <article>
<header> <header>

View File

@@ -52,10 +52,10 @@
<h3><!--% episode.summary %--></h3> <h3><!--% episode.summary %--></h3>
<p class="meta"><!--% episode_navigation %--> <p class="meta"><!--% episode_navigation %-->
</p> </p>
<p><!--% IF get_avatar(episode.hostid) != 'hpr_logo.png' %--> <p><!--% show_avatar(episode.hostid, episode.host) %-->
<img src="<!--% absolute_path(baseurl) %-->images/<!--% get_avatar(episode.hostid) %-->" height="80" width="80" alt="" /></a><br><!--% END %-->
Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(episode.hostid) %-->.html"><!--% episode.host %--></a> on <span><!--% episode.date %--></span> is flagged as <span><!--% display_explicit(episode.explicit) %--></span> and is released under a <span><!--% episode.license %--> license</span>. <br> Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(episode.hostid) %-->.html"><!--% episode.host %--></a> on <span><!--% episode.date %--></span> is flagged as <span><!--% display_explicit(episode.explicit) %--></span> and is released under a <span><!--% episode.license %--> license</span>. <br>
<!--% display_tags(episode.tags) %--> <br> <!--% display_tags(episode.tags) %--> <br>
<!--% listen_now(episode, "twat", baseurl, media_baseurl) %-->
<!--% display_listen_in(episode.id, "twat") %--> <!--% display_listen_in(episode.id, "twat") %-->
</p> </p>
<h3><!--% show_series(episode.series, episode.seriesid, "Part of the series") %--></h3> <h3><!--% show_series(episode.series, episode.seriesid, "Part of the series") %--></h3>
@@ -63,7 +63,6 @@ Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pa
</header> </header>
<div><!--% episode.notes %--></div> <div><!--% episode.notes %--></div>
<footer> <footer>
<!--% listen_now(episode, "twat", baseurl, media_baseurl) %-->
<p> <p>
<!--% episode_navigation %--> <!--% episode_navigation %-->
</p> </p>

View File

@@ -6,5 +6,5 @@
<li><a href="<!--% absolute_path(baseurl) %-->correspondents/index.html">Hosts</a></li> <li><a href="<!--% absolute_path(baseurl) %-->correspondents/index.html">Hosts</a></li>
<li><a href="<!--% absolute_path(baseurl) %-->contact.html">Contact</a></li> <li><a href="<!--% absolute_path(baseurl) %-->contact.html">Contact</a></li>
<li><a href="<!--% absolute_path(baseurl) %-->promote.html">Promote HPR</a></li> <li><a href="<!--% absolute_path(baseurl) %-->promote.html">Promote HPR</a></li>
<li><a href="<!--% absolute_path(baseurl) %-->comments_viewer.php">Show Comments</a></li> <li><a href="<!--% absolute_path(baseurl) %-->comments_viewer.html">Show Comments</a></li>
</ul> </ul>

View File

@@ -1,5 +1,16 @@
<!--% MACRO get_avatar(host_id) BLOCK %--> <!--% MACRO lazy_load(is_lazy) BLOCK %-->
<!--% IF is_lazy %-->loading="lazy"<!--% END %-->
<!--% END %-->
<!--% MACRO get_avatar_src(host_id) BLOCK %-->
<!--% TRY %--> <!--% TRY %-->
<!--% USE File ("./public_html/images/hosts/${host_id}.png") %-->hosts/<!--% File.name %--> <!--% USE File ("./public_html/images/hosts/${host_id}.png") %-->hosts/<!--% File.name %-->
<!--% CATCH File %-->hpr_logo.png<!--% END %--> <!--% CATCH File %-->hpr_logo.png<!--% END %-->
<!--% END %--> <!--% END %-->
<!--% MACRO get_avatar(host_id, host_name, is_lazy_loaded) BLOCK %-->
<img src="<!--% absolute_path(baseurl) %-->images/<!--% get_avatar_src(host_id) %-->" height="80" width="80" alt="Thumbnail of <!--% host_name | html %-->" <!--% lazy_load(is_lazy_loaded) %--> />
<!--% END %-->
<!--% MACRO show_avatar(host_id, host_name, is_lazy_loaded) BLOCK %-->
<!--% IF get_avatar_src(host_id) != 'hpr_logo.png' %-->
<a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(host_id) %-->.html"><!--% get_avatar(host_id, host_name, is_lazy_loaded) %--></a><br>
<!--% END %-->
<!--% END %-->

184
utils/lib_utils.sh Normal file
View File

@@ -0,0 +1,184 @@
#!/bin/bash -
#===============================================================================
#
# FILE: lib_utils.sh
#
# USAGE: ./lib_utils.sh
#
# DESCRIPTION: functions for scripts used to update local HPR installations
# using the HPR static site generator
#
# OPTIONS: ---
# REQUIREMENTS: mysql2sqlite (https://github.com/dumblob/mysql2sqlite)
# BUGS: ---
# NOTES: ---
# AUTHOR: Roan "Rho`n" Horning <roan.horning@gmail.com>
# CREATED: 02/26/2023 03:27:08 PM -5 UTC
# REVISION: ---
# LICENSE: GNU AGPLv3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#===============================================================================
set -o nounset # Treat unset variables as an error
#--- FUNCTION ----------------------------------------------------------------
# NAME: make_working_dir
# DESCRIPTION: Creates a local temporary working directory
# SEE: https://stackoverflow.com/questions/4632028/how-to-create-a-temporary-directory#answer-34676160
# PARAMETERS:
# RETURNS: The path to the working directory
#-------------------------------------------------------------------------------
function make_working_dir {
# the directory of the script
local DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# the temp directory used, within $DIR
# omit the -p parameter to create a temporal directory in
# the default location
local WORK_DIR=`mktemp -d -p "$DIR"`
# check if tmp dir was created
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temp dir"
exit 1
fi
echo $WORK_DIR
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: clean_working_dir
# DESCRIPTION: Remove local temporary working directory
# PARAMETERS: WORK_DIR -- Temporay directory to be delted
# RETURNS:
#-------------------------------------------------------------------------------
function clean_working_dir {
if [[ -d $1 ]] && expr $1 : '.*/tmp.*' ; then
rm -rf $1
echo "Deleted temp working directory $1"
else
echo "Did not delete directory: $1"
echo "Not a temporary directory."
fi
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: download_hpr_sql
# DESCRIPTION: Download the HPR SQL dump file into a working directory
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
function download_hpr_sql {
if [[ ! -d $1 ]] || ! expr $1 : '.*/tmp.*' ;
then
echo "Please provide the temporary directory when calling this function"
return 1
fi
local CURL=`which curl`
local WGET=`which wget`
local HPR_URL=https://www.hackerpublicradio.org/hpr.sql
if [ -f $1/hpr.sql ];
then
echo "Removing temporary hpr.sql"
rm $1/hpr.sql
else
echo "No temporary hpr.sql to remove"
fi
if [ "$CURL" != "" ];
then
curl $HPR_URL --output $1/hpr.sql
echo "Downloaded hpr.sql via curl"
elif [ "$WGET" != "" ];
then
wget --directory-prefix=$1 $HPR_URL
echo "Downloaded hpr.sql via wget"
else
echo "Could not download file. Please install either curl or wget."
return 1
fi
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: make_hpr_sqlite_db
# DESCRIPTION: Converts the hpr sql file into an sqlite db file
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
function make_hpr_sqlite_db {
if [[ ! -d $1 ]] || ! expr $1 : '.*/tmp.*' ;
then
echo "Please provide the temporary directory when calling this function"
return 1
fi
local MYSQL2SQLITE=`which mysql2sqlite`
local BIN_PATH=""
if [ "$MYSQL2SQLITE" = "" ];
then
if [ $# -gt 1 ] && [ -z "$2" ];
then
BIN_PATH=$2
else
BIN_PATH=`find . -type f -name "mysql2sqlite" -print | head -1`
if [ "$BIN_PATH" != "" ];
then
BIN_PATH=${BIN_PATH/mysql2sqlite//}
else
echo "Could not find mysql2sqlite script."
return 1
fi
fi
fi
echo $BIN_PATH
if [ -f $1/hpr.db ];
then
rm $1/hpr.db
fi
# Remove lines from hpr.sql that mysql2sqlite can't handle
sed '/^DELIMITER ;;/,/^DELIMITER ;/d' < $1/hpr.sql > $1/hpr-sqlite.sql
${BIN_PATH}mysql2sqlite $1/hpr-sqlite.sql | sqlite3 $1/hpr.db
echo "Created hpr.db"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: copy_to_public_dir
# DESCRIPTION: Move HPR sql and db files to public website folder
# PARAMETERS:
# RETURNS:
#-------------------------------------------------------------------------------
function copy_to_public_dir {
if [ $# -gt 1 ] && [ ! -z "$1" ] && [ ! -z "$2" ];
then
cp $1/hpr.sql $2/hpr.sql
cp $1/hpr.db $2/hpr.db
return 0
else
echo "Bad arguments. Can't copy files to public directory."
fi
}

289
utils/mysql2sqlite Executable file
View File

@@ -0,0 +1,289 @@
#!/usr/bin/awk -f
# Authors: @esperlu, @artemyk, @gkuenning, @dumblob
# FIXME detect empty input file and issue a warning
function printerr( s ){ print s | "cat >&2" }
BEGIN {
if( ARGC != 2 ){
printerr( \
"USAGE:\n"\
" mysql2sqlite dump_mysql.sql > dump_sqlite3.sql\n" \
" OR\n" \
" mysql2sqlite dump_mysql.sql | sqlite3 sqlite.db\n" \
"\n" \
"NOTES:\n" \
" Dash in filename is not supported, because dash (-) means stdin." )
no_END = 1
exit 1
}
# Find INT_MAX supported by both this AWK (usually an ISO C signed int)
# and SQlite.
# On non-8bit-based architectures, the additional bits are safely ignored.
# 8bit (lower precision should not exist)
s="127"
# "63" + 0 avoids potential parser misbehavior
if( (s + 0) "" == s ){ INT_MAX_HALF = "63" + 0 }
# 16bit
s="32767"
if( (s + 0) "" == s ){ INT_MAX_HALF = "16383" + 0 }
# 32bit
s="2147483647"
if( (s + 0) "" == s ){ INT_MAX_HALF = "1073741823" + 0 }
# 64bit (as INTEGER in SQlite3)
s="9223372036854775807"
if( (s + 0) "" == s ){ INT_MAX_HALF = "4611686018427387904" + 0 }
# # 128bit
# s="170141183460469231731687303715884105728"
# if( (s + 0) "" == s ){ INT_MAX_HALF = "85070591730234615865843651857942052864" + 0 }
# # 256bit
# s="57896044618658097711785492504343953926634992332820282019728792003956564819968"
# if( (s + 0) "" == s ){ INT_MAX_HALF = "28948022309329048855892746252171976963317496166410141009864396001978282409984" + 0 }
# # 512bit
# s="6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048"
# if( (s + 0) "" == s ){ INT_MAX_HALF = "3351951982485649274893506249551461531869841455148098344430890360930441007518386744200468574541725856922507964546621512713438470702986642486608412251521024" + 0 }
# # 1024bit
# s="89884656743115795386465259539451236680898848947115328636715040578866337902750481566354238661203768010560056939935696678829394884407208311246423715319737062188883946712432742638151109800623047059726541476042502884419075341171231440736956555270413618581675255342293149119973622969239858152417678164812112068608"
# if( (s + 0) "" == s ){ INT_MAX_HALF = "44942328371557897693232629769725618340449424473557664318357520289433168951375240783177119330601884005280028469967848339414697442203604155623211857659868531094441973356216371319075554900311523529863270738021251442209537670585615720368478277635206809290837627671146574559986811484619929076208839082406056034304" + 0 }
# # higher precision probably not needed
FS=",$"
print "PRAGMA synchronous = OFF;"
print "PRAGMA journal_mode = MEMORY;"
print "BEGIN TRANSACTION;"
}
# historically 3 spaces separate non-argument local variables
function bit_to_int( str_bit, powtwo, i, res, bit, overflow ){
powtwo = 1
overflow = 0
# 011101 = 1*2^0 + 0*2^1 + 1*2^2 ...
for( i = length( str_bit ); i > 0; --i ){
bit = substr( str_bit, i, 1 )
if( overflow || ( bit == 1 && res > INT_MAX_HALF ) ){
printerr( \
NR ": WARN Bit field overflow, number truncated (LSBs saved, MSBs ignored)." )
break
}
res = res + bit * powtwo
# no warning here as it might be the last iteration
if( powtwo > INT_MAX_HALF ){ overflow = 1; continue }
powtwo = powtwo * 2
}
return res
}
# CREATE TRIGGER statements have funny commenting. Remember we are in trigger.
/^\/\*.*(CREATE.*TRIGGER|create.*trigger)/ {
gsub( /^.*(TRIGGER|trigger)/, "CREATE TRIGGER" )
print
inTrigger = 1
next
}
# The end of CREATE TRIGGER has a stray comment terminator
/(END|end) \*\/;;/ { gsub( /\*\//, "" ); print; inTrigger = 0; next }
# The rest of triggers just get passed through
inTrigger != 0 { print; next }
# CREATE VIEW looks like a TABLE in comments
/^\/\*.*(CREATE.*TABLE|create.*table)/ {
inView = 1
next
}
# end of CREATE VIEW
/^(\).*(ENGINE|engine).*\*\/;)/ {
inView = 0
next
}
# content of CREATE VIEW
inView != 0 { next }
# skip comments
/^\/\*/ { next }
# skip PARTITION statements
/^ *[(]?(PARTITION|partition) +[^ ]+/ { next }
# print all INSERT lines
( /^ *\(/ && /\) *[,;] *$/ ) || /^(INSERT|insert|REPLACE|replace)/ {
prev = ""
# first replace \\ by \_ that mysqldump never generates to deal with
# sequnces like \\n that should be translated into \n, not \<LF>.
# After we convert all escapes we replace \_ by backslashes.
gsub( /\\\\/, "\\_" )
# single quotes are escaped by another single quote
gsub( /\\'/, "''" )
gsub( /\\n/, "\n" )
gsub( /\\r/, "\r" )
gsub( /\\"/, "\"" )
gsub( /\\\032/, "\032" ) # substitute char
gsub( /\\_/, "\\" )
# sqlite3 is limited to 16 significant digits of precision
while( match( $0, /0x[0-9a-fA-F]{17}/ ) ){
hexIssue = 1
sub( /0x[0-9a-fA-F]+/, substr( $0, RSTART, RLENGTH-1 ), $0 )
}
if( hexIssue ){
printerr( \
NR ": WARN Hex number trimmed (length longer than 16 chars)." )
hexIssue = 0
}
print
next
}
# CREATE DATABASE is not supported
/^(CREATE DATABASE|create database)/ { next }
# print the CREATE line as is and capture the table name
/^(CREATE|create)/ {
if( $0 ~ /IF NOT EXISTS|if not exists/ || $0 ~ /TEMPORARY|temporary/ ){
caseIssue = 1
printerr( \
NR ": WARN Potential case sensitivity issues with table/column naming\n" \
" (see INFO at the end)." )
}
if( match( $0, /`[^`]+/ ) ){
tableName = substr( $0, RSTART+1, RLENGTH-1 )
}
aInc = 0
prev = ""
firstInTable = 1
print
next
}
# Replace `FULLTEXT KEY` (probably other `XXXXX KEY`)
/^ (FULLTEXT KEY|fulltext key)/ { gsub( /[A-Za-z ]+(KEY|key)/, " KEY" ) }
# Get rid of field lengths in KEY lines
/ (PRIMARY |primary )?(KEY|key)/ { gsub( /\([0-9]+\)/, "" ) }
aInc == 1 && /PRIMARY KEY|primary key/ { next }
# Replace COLLATE xxx_xxxx_xx statements with COLLATE BINARY
/ (COLLATE|collate) [a-z0-9_]*/ { gsub( /(COLLATE|collate) [a-z0-9_]*/, "COLLATE BINARY" ) }
# Print all fields definition lines except the `KEY` lines.
/^ / && !/^( (KEY|key)|\);)/ {
if( match( $0, /[^"`]AUTO_INCREMENT|auto_increment[^"`]/) ){
aInc = 1
gsub( /AUTO_INCREMENT|auto_increment/, "PRIMARY KEY AUTOINCREMENT" )
}
gsub( /(UNIQUE KEY|unique key) (`.*`|".*") /, "UNIQUE " )
gsub( /(CHARACTER SET|character set) [^ ]+[ ,]/, "" )
# FIXME
# CREATE TRIGGER [UpdateLastTime]
# AFTER UPDATE
# ON Package
# FOR EACH ROW
# BEGIN
# UPDATE Package SET LastUpdate = CURRENT_TIMESTAMP WHERE ActionId = old.ActionId;
# END
gsub( /(ON|on) (UPDATE|update) (CURRENT_TIMESTAMP|current_timestamp)(\(\))?/, "" )
gsub( /(DEFAULT|default) (CURRENT_TIMESTAMP|current_timestamp)(\(\))?/, "DEFAULT current_timestamp")
gsub( /(COLLATE|collate) [^ ]+ /, "" )
gsub( /(ENUM|enum)[^)]+\)/, "text " )
gsub( /(SET|set)\([^)]+\)/, "text " )
gsub( /UNSIGNED|unsigned/, "" )
gsub( /_utf8mb3/, "" )
gsub( /` [^ ]*(INT|int|BIT|bit)[^ ]*/, "` integer" )
gsub( /" [^ ]*(INT|int|BIT|bit)[^ ]*/, "\" integer" )
ere_bit_field = "[bB]'[10]+'"
if( match($0, ere_bit_field) ){
sub( ere_bit_field, bit_to_int( substr( $0, RSTART +2, RLENGTH -2 -1 ) ) )
}
# remove USING BTREE and other suffixes for USING, for example: "UNIQUE KEY
# `hostname_domain` (`hostname`,`domain`) USING BTREE,"
gsub( / USING [^, ]+/, "" )
# field comments are not supported
gsub( / (COMMENT|comment).+$/, "" )
# Get commas off end of line
gsub( /,.?$/, "" )
if( prev ){
if( firstInTable ){
print prev
firstInTable = 0
}
else {
print "," prev
}
}
else {
# FIXME check if this is correct in all cases
if( match( $1,
/(CONSTRAINT|constraint) ["].*["] (FOREIGN KEY|foreign key)/ ) ){
print ","
}
}
prev = $1
}
/ ENGINE| engine/ {
if( prev ){
if( firstInTable ){
print prev
firstInTable = 0
}
else {
print "," prev
}
}
prev=""
print ");"
next
}
# `KEY` lines are extracted from the `CREATE` block and stored in array for later print
# in a separate `CREATE KEY` command. The index name is prefixed by the table name to
# avoid a sqlite error for duplicate index name.
/^( (KEY|key)|\);)/ {
if( prev ){
if( firstInTable ){
print prev
firstInTable = 0
}
else {
print "," prev
}
}
prev = ""
if( $0 == ");" ){
print
}
else {
if( match( $0, /`[^`]+/ ) ){
indexName = substr( $0, RSTART+1, RLENGTH-1 )
}
if( match( $0, /\([^()]+/ ) ){
indexKey = substr( $0, RSTART+1, RLENGTH-1 )
}
# idx_ prefix to avoid name clashes (they really happen!)
key[tableName] = key[tableName] "CREATE INDEX \"idx_" \
tableName "_" indexName "\" ON \"" tableName "\" (" indexKey ");\n"
}
}
END {
if( no_END ){ exit 1}
# print all KEY creation lines.
for( table in key ){ printf key[table] }
print "END TRANSACTION;"
if( caseIssue ){
printerr( \
"INFO Pure sqlite identifiers are case insensitive (even if quoted\n" \
" or if ASCII) and doesnt cross-check TABLE and TEMPORARY TABLE\n" \
" identifiers. Thus expect errors like \"table T has no column named F\".")
}
}

54
utils/update-hpr-db.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/bash -
#===============================================================================
#
# FILE: update-hpr-db.sh
#
# USAGE: ./update-hpr-db.sh
#
# DESCRIPTION: Download MySQL hpr.sql file and create SQLite3 file
#
# OPTIONS: ---
# REQUIREMENTS: lib_utils.sh
# BUGS: ---
# NOTES: ---
# AUTHOR: Roan "Rho`n" Horning (roan.horning@gmail.com)
# ORGANIZATION:
# CREATED: 03/05/2023 07:21:29 PM
# REVISION: ---
# LICENSE: GNU AGPLv3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#===============================================================================
set -o nounset # Treat unset variables as an error
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#
# Load library functions
#
LIB="$BASEDIR/lib_utils.sh"
[ -e $LIB ] || { echo "Unable to load functions.\n$LIB not found."; exit; }
source $LIB
WORKING_DIR=`make_working_dir`
download_hpr_sql $WORKING_DIR
make_hpr_sqlite_db $WORKING_DIR
copy_to_public_dir $WORKING_DIR `pwd`
clean_working_dir $WORKING_DIR

72
utils/update-hpr.sh Executable file
View File

@@ -0,0 +1,72 @@
#!/bin/bash -
#===============================================================================
#
# FILE: update-hpr.sh
#
# USAGE: ./update-hpr.sh
#
# DESCRIPTION: Script to update local statically generated HPR website
#
# OPTIONS: ---
# REQUIREMENTS: lib_utils.sh
# BUGS: ---
# NOTES: ---
# AUTHOR: Roan "Rho`n" Horning (roan.horning@gmail.com),
# ORGANIZATION:
# CREATED: 03/03/2023 09:26:29 PM
# REVISION: ---
# LICENSE: GNU AGPLv3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#===============================================================================
set -o nounset # Treat unset variables as an error
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#
# Load library functions
#
LIB="$BASEDIR/lib_utils.sh"
[ -e $LIB ] || { echo "Unable to load functions.\n$LIB not found."; exit; }
source $LIB
WORKING_DIR=`make_working_dir`
download_hpr_sql $WORKING_DIR
make_hpr_sqlite_db $WORKING_DIR
copy_to_public_dir $WORKING_DIR `pwd`
mv hpr.sql public_html/
echo "Update static HTML files"
# Clean up previously generated files
rm -rf public_html/*.html public_html/correspondents public_html/eps public_html/series
git restore public_html/will-my-show-be-of-interest-to-hackers.html
# stash changes to configuration file to preserve DB settings
git stash
git pull
git stash pop
./site-generator --quiet --all
clean_working_dir $WORKING_DIR