pull-masterversions.php 2.04 KB
Newer Older
David Morley's avatar
David Morley committed
1 2 3
<?php
//* Copyright (c) 2017, David Morley. This file is licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file. */

noplanman's avatar
noplanman committed
4 5 6 7 8 9 10 11 12 13
use RedBeanPHP\R;

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';

define('PODUPTIME', microtime(true));

// Set up global DB connection.
R::setup("pgsql:host={$pghost};dbname={$pgdb}", $pguser, $pgpass, true);
R::testConnection() || die('Error in DB connection');
dmorley's avatar
dmorley committed
14
R::usePartialBeans(true);
David Morley's avatar
David Morley committed
15 16

$softwares = [
noplanman's avatar
noplanman committed
17 18 19
  'diaspora'     => ['url' => 'https://raw.githubusercontent.com/diaspora/diaspora/master/config/defaults.yml', 'regex' => '/number:.*"(.*)"/'],
  'friendica'    => ['url' => 'https://raw.githubusercontent.com/friendica/friendica/master/boot.php', 'regex' => '/define.*\'FRIENDICA_VERSION\'.*\'(.*)\'/'],
  'redmatrix'    => ['url' => 'https://raw.githubusercontent.com/redmatrix/hubzilla/master/boot.php', 'regex' => '/define.*\'STD_VERSION\'.*\'(.*)\'/'],
dmorley's avatar
dmorley committed
20
  'socialhome'   => ['url' => 'https://raw.githubusercontent.com/jaywink/socialhome/master/socialhome/__init__.py', 'regex' => '/__version__ =.*"(.*)"/'],
David Morley's avatar
David Morley committed
21
  'social-relay' => ['url' => 'https://raw.githubusercontent.com/jaywink/social-relay/master/social_relay/config.py', 'regex' => '/VERSION.*"(.*)"/'],
dmorley's avatar
dmorley committed
22
  'ganggo'       => ['url' => 'https://raw.githubusercontent.com/ganggo/ganggo/master/package.json', 'regex' => '/"version": "(.*)"/'],
David Morley's avatar
David Morley committed
23 24 25 26 27 28 29 30 31 32 33
];

foreach ($softwares as $software => $details) {
  $mv = curl_init();
  curl_setopt($mv, CURLOPT_URL, $details['url']);
  curl_setopt($mv, CURLOPT_CONNECTTIMEOUT, 5);
  curl_setopt($mv, CURLOPT_RETURNTRANSFER, 1);
  $outputmv = curl_exec($mv);
  curl_close($mv);

  if ($masterversion = preg_match($details['regex'], $outputmv, $version) ? $version[1] : '') {
noplanman's avatar
noplanman committed
34 35 36 37 38 39 40 41
    try {
      $m             = R::dispense('masterversions');
      $m['software'] = $software;
      $m['version']  = $masterversion;
      R::store($m);
    } catch (\RedBeanPHP\RedException $e) {
      die('Error in SQL query: ' . $e->getMessage());
    }
David Morley's avatar
David Morley committed
42 43 44 45
  }

  printf('%s:%s ', $software, $masterversion ?: 'n/a');
}