1
0

Moved helper scripts to bin/ dir.

This commit is contained in:
2017-12-18 15:02:24 +01:00
parent 9d3ad675ef
commit f37b98cbee
11 changed files with 25 additions and 7 deletions

24
bin/clean_dupes.php Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env php
<?php
$bkup_dir = __DIR__ . '/../data/';
$file_list = glob($bkup_dir . '*.xml');
$hashes = array();
foreach ($file_list as $file) {
$filename = basename($file);
$file_hash = sha1_file($file);
if (isset($hashes[$file_hash])) {
$old_file = $hashes[$file_hash];
if (md5_file($file) == md5_file($bkup_dir . $old_file)) {
echo 'Duplicate file: ' . $filename . ' (first: ' . $old_file . ')' . PHP_EOL;
unlink($file);
continue;
}
echo 'Possible SHA1 collision?' . PHP_EOL;
}
$hashes[$file_hash] = $filename;
}

5
bin/get_data.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
MYDIR=$(dirname "$(readlink -f "$0")")
. "${MYDIR}/../config.ini"
rsync -av "${SYNC_REMOTE_DIR}/data/*" "${MYDIR}/../data/"

3
bin/initdb.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
MYDIR=$(dirname "$(readlink -f "$0")")
sqlite3 "${MYDIR}/../otadb.db3" < "${MYDIR}/../sql/dbschema.sql"

43
bin/parse_files.php Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env php
<?php
require_once __DIR__ . '/../lib/autoloader.php';
use \TclUpdates\GotuObject;
use \TclUpdates\XmlParser;
use \TclUpdates\SQLiteWriter;
$bkup_dir = __DIR__ . '/../data/';
$file_list = glob($bkup_dir . '*.xml');
$sqlw = new SQLiteWriter();
foreach ($file_list as $file) {
$filename = basename($file);
$file_stamp = substr($filename, 0, strpos($filename, '.'));
$file_date = gmdate('c', intval($file_stamp));
$data = file_get_contents($file);
$xp = new XmlParser();
$load_ok = $xp->loadXmlFromString($data);
if (!$load_ok) {
echo 'Could not load ' . $filename . '!' . PHP_EOL;
continue;
}
if (!$xp->validateGOTU()) {
echo 'XML not valid in ' . $filename . '!' . PHP_EOL;
continue;
}
echo 'Processing ' . $filename . ' ...';
$g = GotuObject::fromXmlParser($xp);
//print_r($g);
if ($g->tv) {
$result = $sqlw->addGotu($g, $file_date);
if ($result !== false) {
echo ' added as #' . $result . PHP_EOL;
} else {
echo ' NOT ADDED.' . PHP_EOL;
}
} else {
echo ' not a check XML' . PHP_EOL;
}
}

5
bin/put_data.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
MYDIR=$(dirname "$(readlink -f "$0")")
. "${MYDIR}/../config.ini"
rsync -av "${MYDIR}/../data" "${SYNC_REMOTE_DIR}/"

4
bin/put_db.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
. "${MYDIR}/../config.ini"
rsync -av "${MYDIR}/../otadb.db3" "${SYNC_REMOTE_DIR}/"