-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_init
executable file
·79 lines (69 loc) · 1.69 KB
/
db_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/env php
<?php
// CLI script to create Librarian records.
// Usage: db_init command
//
// commands:
// source name
// create a Librarian source with the given name
// store name capacity
// create a store with the given name and capacity (in bytes)
// test_setup
// create records for testing
require_once("test_setup.inc");
require_once("hera_util.inc");
require_once("hl_db.inc");
function usage() {
echo "usage: db_init.php command
commands:
source name: create Librarian source
store name capacity: create store
test_setup: create records for testing
";
exit;
}
function create_source($name, $subsystem) {
$source = new StdClass;
$source->name = $name;
$source->authenticator = random_string();
$source->create_time = time();
echo "creating $subsystem source $name; authenticator: $source->authenticator\n";
return source_insert($source);
}
function create_store($store) {
$store->create_time = time();
return store_insert($store);
}
function test_setup() {
global $test_stores, $test_source_names, $test_config;
foreach ($test_source_names as $u) {
if (!create_source($u, 'Librarian')) {
echo db_error()."\n";
}
}
foreach ($test_stores as $s) {
if (!create_store($s)) {
echo db_error()."\n";
}
}
}
if ($argc < 2) {
usage();
}
$config = get_server_config();
if (!init_db($config)) {
die("can't connect to DB\n");
}
switch ($argv[1]) {
case 'source':
create_source($argv[2]);
break;
case 'store':
create_store($argv[2], $argv[3], $argv[4]);
break;
case 'test_setup':
test_setup();
break;
default: usage();
}
?>