Added tt-rss-mobilize plugin for supporting Readability and other

mobilizer services out of the box.
This commit is contained in:
andy 2014-05-14 12:02:45 +02:00
parent ff6c069a85
commit 25277b2b2f
6 changed files with 117 additions and 45 deletions

View File

@ -27,11 +27,15 @@ WORKDIR /var/www/ttrss
RUN cp config.php-dist config.php
RUN sed -i -e "/'SELF_URL_PATH'/s/ '.*'/ 'http:\/\/localhost\/'/" config.php
# install feedly theme
# install Feedly theme
RUN git clone https://github.com/levito/tt-rss-feedly-theme.git
RUN ln -s /var/www/ttrss/tt-rss-feedly-theme/feedly /var/www/ttrss/themes/feedly
RUN ln -s /var/www/ttrss/tt-rss-feedly-theme/feedly.css /var/www/ttrss/themes/feedly.css
# install ttrss-mobilize plugin
RUN git clone https://github.com/sepich/tt-rss-mobilize.git /var/www/ttrss/plugins/mobilize
ADD ttrss-plugin-mobilize.pgsql /var/www/ttrss/plugins/mobilize/ttrss-plugin-mobilize.pgsql
# apply ownership of ttrss + addons to www-data
RUN chown www-data:www-data -R /var/www
@ -44,6 +48,9 @@ ENV DB_USER ttrss
ENV DB_PASS ttrss
# always re-configure database with current ENV when RUNning container, then monitor all services
ADD run.sh /run.sh
ADD utils.php /utils.php
ADD configure-db.php /configure-db.php
ADD configure-plugin-mobilize.php /configure-plugin-mobilize.php
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD php /configure-db.php && supervisord -c /etc/supervisor/conf.d/supervisord.conf
CMD sh /run.sh && supervisord -c /etc/supervisor/conf.d/supervisord.conf

View File

@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php
include '/utils.php';
$ename = 'DB';
$eport = 5432;
$confpath = '/var/www/ttrss/config.php';
@ -69,46 +71,3 @@ foreach ($config as $name => $value) {
$contents = preg_replace('/(define\s*\(\'' . $name . '\',\s*)(.*)(\);)/', '$1"' . $value . '"$3', $contents);
}
file_put_contents($confpath, $contents);
function env($name, $default = null)
{
$v = getenv($name) ?: $default;
if ($v === null) {
error('The env ' . $name . ' does not exist');
}
return $v;
}
function error($text)
{
echo 'Error: ' . $text . PHP_EOL;
exit(1);
}
function dbconnect($config)
{
$map = array('host' => 'HOST', 'port' => 'PORT', 'dbname' => 'NAME', 'user' => 'USER', 'password' => 'PASS');
$dsn = $config['DB_TYPE'] . ':';
foreach ($map as $d => $h) {
if (isset($config['DB_' . $h])) {
$dsn .= $d . '=' . $config['DB_' . $h] . ';';
}
}
$pdo = new \PDO($dsn);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
}
function dbcheck($config)
{
try {
dbconnect($config);
return true;
}
catch (PDOException $e) {
return false;
}
}

View File

@ -0,0 +1,49 @@
#!/usr/bin/env php
<?php
include '/utils.php';
$ename = 'DB';
$eport = 5432;
$confpath = '/var/www/ttrss/config.php';
// check DB_NAME, which will be set automatically for a linked "db" container
if (!env($ename . '_PORT', '')) {
error('The env ' . $ename .'_PORT does not exist. Make sure to run with "--link mypostgresinstance:' . $ename . '"');
}
$config = array();
$config['DB_TYPE'] = 'pgsql';
$config['DB_HOST'] = env($ename . '_PORT_' . $eport . '_TCP_ADDR');
$config['DB_PORT'] = env($ename . '_PORT_' . $eport . '_TCP_PORT');
// database credentials for this instance
// database name (DB_NAME) can be supplied or detaults to "ttrss"
// database user (DB_USER) can be supplied or defaults to database name
// database pass (DB_PASS) can be supplied or defaults to database user
$config['DB_NAME'] = env($ename . '_NAME', 'ttrss');
$config['DB_USER'] = env($ename . '_USER', $config['DB_NAME']);
$config['DB_PASS'] = env($ename . '_PASS', $config['DB_USER']);
$pdo = dbconnect($config);
try {
$pdo->query('SELECT 1 FROM plugin_mobilize_feeds');
// reached this point => table found, assume db is complete
}
catch (PDOException $e) {
echo 'Database table for mobilize plugin not found, applying schema... ' . PHP_EOL;
$schema = file_get_contents('plugins/mobilize/ttrss-plugin-mobilize.pgsql');
$schema = preg_replace('/--(.*?);/', '', $schema);
$schema = preg_replace('/[\r\n]/', ' ', $schema);
$schema = trim($schema, ' ;');
foreach (explode(';', $schema) as $stm) {
$pdo->exec($stm);
}
unset($pdo);
}
$contents = file_get_contents($confpath);
foreach ($config as $name => $value) {
$contents = preg_replace('/(define\s*\(\'' . $name . '\',\s*)(.*)(\);)/', '$1"' . $value . '"$3', $contents);
}
file_put_contents($confpath, $contents);

3
run.sh Normal file
View File

@ -0,0 +1,3 @@
#/bin/sh
php /configure-db.php && \
php /configure-plugin-mobilize.php

View File

@ -0,0 +1,9 @@
CREATE TABLE "plugin_mobilize_feeds" ( "id" int NOT NULL, "owner_uid" int NOT NULL, "mobilizer_id" int NOT NULL, PRIMARY KEY ("id","owner_uid") );
CREATE TABLE "plugin_mobilize_mobilizers" ( "id" int NOT NULL, "description" varchar(255) NOT NULL, "url" varchar(1000) NOT NULL, PRIMARY KEY ("id") ) ;
INSERT INTO "plugin_mobilize_mobilizers" ( "id", "description", "url") VALUES
(0, 'Readability', 'http://www.readability.com/m?url=%s'),
(1, 'Instapaper', 'http://www.instapaper.com/m?u=%s'),
(2, 'Google Mobilizer', 'http://www.google.com/gwt/x?u=%s'),
(3, 'Original Stripped', 'http://strip=%s'),
(4, 'Original', '%s');

45
utils.php Normal file
View File

@ -0,0 +1,45 @@
<?
function env($name, $default = null)
{
$v = getenv($name) ?: $default;
if ($v === null) {
error('The env ' . $name . ' does not exist');
}
return $v;
}
function error($text)
{
echo 'Error: ' . $text . PHP_EOL;
exit(1);
}
function dbconnect($config)
{
$map = array('host' => 'HOST', 'port' => 'PORT', 'dbname' => 'NAME', 'user' => 'USER', 'password' => 'PASS');
$dsn = $config['DB_TYPE'] . ':';
foreach ($map as $d => $h) {
if (isset($config['DB_' . $h])) {
$dsn .= $d . '=' . $config['DB_' . $h] . ';';
}
}
$pdo = new \PDO($dsn);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
}
function dbcheck($config)
{
try {
dbconnect($config);
return true;
}
catch (PDOException $e) {
return false;
}
}
?>