|
| 1 | +#!/usr/bin/php |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Initialise the System |
| 5 | + * |
| 6 | + * SPDX-License-Identifier: MIT |
| 7 | + */ |
| 8 | + |
| 9 | +$config_file = sprintf('%s/etc/config.php', __DIR__); |
| 10 | +if (is_file($config_file)) { |
| 11 | + echo "Already Configured\n"; |
| 12 | + exit(1); |
| 13 | +} |
| 14 | + |
| 15 | +touch($config_file); |
| 16 | + |
| 17 | +require_once(__DIR__ . '/boot.php'); |
| 18 | + |
| 19 | +$raw = sodium_crypto_box_keypair(); |
| 20 | +$pk0 = sodium_crypto_box_publickey($raw); |
| 21 | +$sk0 = sodium_crypto_box_secretkey($raw); |
| 22 | +$pk0b64 = enb64($pk0); |
| 23 | +$sk0b64 = enb64($sk0); |
| 24 | + |
| 25 | + |
| 26 | +$config_text = <<<TXT |
| 27 | +<?php |
| 28 | +/** |
| 29 | + * OpenTHC Pub Configuration |
| 30 | + */ |
| 31 | +
|
| 32 | +\$ret = []; |
| 33 | +
|
| 34 | +\$ret['app'] = [ |
| 35 | + 'base' => '$argv[1]' |
| 36 | +]; |
| 37 | +
|
| 38 | +\$ret['pub'] = [ |
| 39 | + 'public' => '$pk0b64', |
| 40 | + 'secret' => '$sk0b64', |
| 41 | +]; |
| 42 | +
|
| 43 | +return \$ret; |
| 44 | +TXT; |
| 45 | + |
| 46 | +file_put_contents($config_file, $config_text); |
| 47 | + |
| 48 | +$dbc = new \Edoceo\Radix\DB\SQL(sprintf('sqlite:%s/var/pub.sqlite', __DIR__)); |
| 49 | +$dbc->query('CREATE TABLE account (id PRIMARY KEY, created_at TEXT DEFAULT CURRENT_TIMESTAMP, link, body, meta)'); |
| 50 | +$dbc->insert('account', [ |
| 51 | + 'id' => $pk0b64, |
| 52 | + 'link' => '/pk', |
| 53 | + 'body' => 'This is the account for the Site Operator', |
| 54 | +]); |
| 55 | + |
| 56 | +$dbc->query('CREATE TABLE message (id PRIMARY KEY, created_at TEXT DEFAULT CURRENT_TIMESTAMP, pk_source, pk_target, nonce, crypt)'); |
| 57 | + |
| 58 | +# sqlite3 $FILE <EOF |
| 59 | +# CREATE TRIGGER update_at_now BEFORE INSERT UPDATE ON account |
| 60 | +# BEGIN |
| 61 | +# NEW.updated_at = now(); |
| 62 | +# END; |
| 63 | +# EOF |
| 64 | + |
| 65 | +# sqlite3 $FILE <EOF |
| 66 | +# CREATE TRIGGER update_at_now BEFORE INSERT UPDATE ON message |
| 67 | +# BEGIN |
| 68 | +# NEW.updated_at = now(); |
| 69 | +# END; |
| 70 | +# EOF |
| 71 | + |
| 72 | +chown(sprintf('%s/var/pub.sqlite', __DIR__), 'www-data'); |
| 73 | +chgrp(sprintf('%s/var/pub.sqlite', __DIR__), 'www-data'); |
0 commit comments