1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #include <yaz/options.h>
36 #include <idzebra/version.h>
37 #include <idzebra/api.h>
41 static void filter_cb(void *cd, const char *name)
46 static void show_filters(ZebraService zs)
48 zebra_filter_info(zs, 0, filter_cb);
51 int main(int argc, char **argv)
58 int enable_commit = 1;
60 Res res = res_open(0, 0);
61 Res default_res = res_open(0, 0);
63 int trans_started = 0;
72 sprintf(nbuf, "%.40s(%ld)", *argv, (long) getpid());
73 yaz_log_init_prefix(nbuf);
75 /* For indexing driver support */
76 char *useIndexDriver = NULL;
80 fprintf(stderr, "%s [options] command <dir> ...\n"
82 " update <dir> Update index with files below <dir>.\n"
83 " If <dir> is empty filenames are read from stdin.\n"
84 " delete <dir> Delete index with files below <dir>.\n"
85 " create <db> Create database <db>\n"
86 " drop <db> Drop database <db>\n"
87 " commit Commit changes\n"
88 " clean Clean shadow files\n"
90 " -t <type> Index files as <type> (grs or text).\n"
91 " -c <config> Read configuration file <config>.\n"
92 " -g <group> Index files according to group settings.\n"
93 " -d <database> Records belong to Z39.50 database <database>.\n"
94 " -m <mbytes> Use <mbytes> before flushing keys to disk.\n"
95 " -n Don't use shadow system.\n"
96 " -s Show analysis on stdout, but do no work.\n"
97 " -v <level> Set logging to <level>.\n"
98 " -l <file> Write log to <file>.\n"
99 " -L Don't follow symbolic links.\n"
100 " -f <n> Display information for the first <n> records.\n"
101 " -i <driver> Select which index driver to use.\n"
102 " Note: when using a driver, the <dir> gets passed\n"
103 " to the driver as an argument.\n"
104 " Current drivers available:\n"
105 " - indexplugin_mysql\n\n"
106 " -V Show version.\n", *argv
110 res_set(default_res, "profilePath", DEFAULT_PROFILE_PATH);
111 res_set(default_res, "modulePath", DEFAULT_MODULE_PATH);
112 while ((ret = options("sVt:c:g:d:m:v:nf:l:L:i:", argv, argc, &arg)) != -2)
116 if(cmd == 0) /* command */
120 const char *config = configName ? configName : "zebra.cfg";
121 zs = zebra_start_res(config, default_res, res);
124 yaz_log(YLOG_FATAL, "Cannot read config %s", config);
127 zh = zebra_open(zs, 0);
128 zebra_shadow_enable(zh, enable_commit);
132 zebra_select_database(zh, database) == ZEBRA_FAIL)
134 yaz_log(YLOG_FATAL, "Could not select database %s "
136 database, zebra_errCode(zh) );
139 if (!strcmp(arg, "update"))
141 else if (!strcmp(arg, "update1"))
143 else if (!strcmp(arg, "update2"))
145 else if (!strcmp(arg, "dump"))
147 else if (!strcmp(arg, "del") || !strcmp(arg, "delete"))
149 else if (!strcmp(arg, "adelete"))
151 else if (!strcmp(arg, "init"))
155 else if (!strcmp(arg, "drop"))
159 else if (!strcmp(arg, "create"))
163 else if (!strcmp(arg, "commit"))
167 else if (!strcmp(arg, "clean"))
171 else if (!strcmp(arg, "stat") || !strcmp(arg, "status"))
173 zebra_register_statistics(zh, 0);
175 else if (!strcmp(arg, "dumpdict"))
177 zebra_register_statistics(zh, 1);
179 else if (!strcmp(arg, "compact"))
183 else if (!strcmp(arg, "filters"))
189 yaz_log(YLOG_FATAL, "unknown command: %s", arg);
195 ZEBRA_RES res = ZEBRA_OK;
199 if (zebra_begin_trans(zh, 1) != ZEBRA_OK)
205 res = zebra_repository_index(zh, arg, action_update, useIndexDriver);
208 res = zebra_repository_index(zh, arg, action_delete, useIndexDriver);
211 res = zebra_repository_index(zh, arg, action_a_delete, useIndexDriver);
214 res = zebra_repository_show(zh, arg);
218 res = zebra_create_database(zh, arg);
221 res = zebra_drop_database(zh, arg);
228 const char *add = zebra_errAdd(zh);
229 yaz_log(YLOG_FATAL, "Operation failed: %s %s",
230 zebra_errString(zh), add ? add : "");
233 if (zebra_end_trans(zh) != ZEBRA_OK)
234 yaz_log(YLOG_WARN, "zebra_end_trans failed");
241 log_event_end(NULL, NULL);
246 char version_str[20];
248 zebra_get_version(version_str, sys_str);
250 printf("Zebra %s\n", version_str);
251 printf("(C) 1994-2009, Index Data ApS\n");
252 printf("Zebra is free software, covered by the GNU General Public License, and you are\n");
253 printf("welcome to change it and/or distribute copies of it under certain conditions.\n");
254 printf("SHA1 ID: %s\n", sys_str);
255 if (strcmp(version_str, ZEBRAVER))
256 printf("zebraidx compiled version %s\n", ZEBRAVER);
258 printf("Using ICU\n");
262 yaz_log_init_level(yaz_log_mask_str(arg));
264 useIndexDriver = arg;
266 yaz_log_init_file(arg);
268 res_set(res, "memMax", arg);
272 res_set(res, "openRW", "0");
274 res_set(res, "group", arg);
276 res_set(res, "fileVerboseLimit", arg);
280 res_set(res, "recordType", arg);
284 res_set(res, "followLinks", "0");
286 yaz_log(YLOG_WARN, "unknown option '-%s'", arg);
290 if (zebra_end_trans(zh) != ZEBRA_OK)
291 yaz_log(YLOG_WARN, "zebra_end_trans failed");
297 res_close(default_res);
305 * c-file-style: "Stroustrup"
306 * indent-tabs-mode: nil
308 * vim: shiftwidth=4 tabstop=8 expandtab