150 fprintf(stdout,
"Usage: gem65 [OPTION] [ACTION] [FILE|DIR]\n");
151 fprintf(stdout,
"Install a GRASS extension from FILE or DIR.\n");
152 fprintf(stdout,
"Manage (installed) GRASS extension(s).\n");
153 fprintf(stdout,
"\nPossible ACTIONs are:\n");
154 fprintf(stdout,
" -i, --install=EXT\tinstall a GRASS extension\n");
156 " -u, --uninstall=EXT\tremove an extension from GRASS\n");
158 " -q, --query=EXT\tdisplay information about extension/list installed\n");
160 " -d, --details=EXT\tdisplay additional details about an extension\n");
162 " -c, --clean=EXT\tclean extension's source code directories\n");
164 " -t, --test=EXT\tconfigure and compile extension, but don't install\n");
166 " -l, --license=EXT\tshow copyright information for an extension\n");
168 " -r, --restore\t\trecreate HTML links and GIS Manager entries\n");
169 fprintf(stdout,
" -h, --help\t\tdisplay this help and exit\n");
171 " -V, --version\t\toutput version information and exit\n\n");
172 fprintf(stdout,
"\nPossible OPTIONs are:\n");
173 fprintf(stdout,
" -g, --grass=PATH\tpath to GRASS installation dir\n");
175 " -b, --binary=NAME\tno compilation: use binary files for system NAME\n");
177 " -f, --force\t\tforce action, regardless of dependencies\n");
179 " -v, --verbose\t\tdisplay detailed status information\n");
180 fprintf(stdout,
" -s, --skip-config\tskip configure script\n");
182 " -x, --config-opts=OPTS\tpass OPTS to configure script\n");
184 " -o, --options=OPTS\toptions to pass to the C compiler/linker\n");
186 " -C, --config-cmd=CMD\tDefine custom 'configure' command (default=configure)\n");
188 " -m, --make-cmd=CMD\tDefine custom 'make' command (default=make)\n");
190 "\nWhen run from within a GRASS session, locations of libs, header files\n");
192 "and installation target dir will be assumed to match those of the active\n");
193 fprintf(stdout,
"GRASS version. ");
195 "Option -g can be used to override these or install extensions\nfrom outside");
196 fprintf(stdout,
"of a GRASS session.\n");
198 "Per default, extensions will be compiled from source and then installed.\n");
200 "If the exension package contains binaries for the user's platform, they can\n");
201 fprintf(stdout,
"be installed instead using the -b option. ");
203 "For installation from source code, a C compiler and make tools are needed.\n");
204 fprintf(stdout,
"\nExample:\n");
206 "\tgem65 -b macosx --grass=/usr/local/grass-6.5.0 -i myExtension\n");
208 "Installs the MacOS X binaries for 'myExtension' in /usr/local/grass-6.5.0.\n");
222 "extension '%s' not accessible: (%s)\n", package,
245 "extension '%s' not accessible: (%s)\n", package,
249 dump_ascii(
"license",
"Detailed information");
260 fprintf(stdout,
"gem65 (GRASS extensions manager) %.2f\n",
PROGVERSION);
261 fprintf(stdout,
"Written by Benjamin Ducke\n");
262 fprintf(stdout,
"\nCopyright (C) 2005 Benjamin Ducke\n");
264 "This is free software; see the source for copying conditions. There is NO\n");
266 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
286 sprintf(str,
"%s/etc/config.system", gisbase);
287 fp = fopen(str,
"r");
290 (
"could not open %s for read access. Using default configure options.\n",
302 int main(
int argc,
char *argv[])
308 char *grass_revision;
312 char version_file[
MAXSTR];
317 int pkg_major, pkg_minor, pkg_revision;
321 char pkg_short_name[
MAXSTR];
326 int major, minor, revision;
334 int is_directory = 0;
339 int option_index = 0;
340 static struct option long_options[] = {
341 {
"install", 1,
NULL,
'i'},
342 {
"uninstall", 1,
NULL,
'u'},
343 {
"query", 2,
NULL,
'q'},
344 {
"details", 1,
NULL,
'd'},
345 {
"clean", 1,
NULL,
'c'},
346 {
"test", 1,
NULL,
't'},
347 {
"license", 1,
NULL,
'l'},
348 {
"restore", 0,
NULL,
'r'},
349 {
"help", 0,
NULL,
'h'},
350 {
"version", 0,
NULL,
'V'},
352 {
"grass", 1,
NULL,
'g'},
353 {
"options", 1,
NULL,
'o'},
354 {
"binary", 1,
NULL,
'b'},
355 {
"force", 0,
NULL,
'f'},
356 {
"verbose", 0,
NULL,
'v'},
357 {
"skip-config", 0,
NULL,
's'},
358 {
"config-opts", 1,
NULL,
'x'},
360 {
"config-cmd", 1,
NULL,
'C'},
361 {
"make-cmd", 1,
NULL,
'm'},
402 fprintf(stdout,
"\033[0m");
405 strncpy(invocation, argv[0], MAXSTR);
406 invocation[MAXSTR-1] =
'\0';
409 setvbuf(stdout, (
char *)
NULL, _IONBF, 0);
426 getopt_long(argc, argv,
":i:u:q:d:c:C:t:l:m:o:x:rhVg:b:fvs",
427 long_options, &option_index);
428 while (option != -1) {
432 "unknown option or action specified.\n");
438 if ((optopt ==
'i') || (optopt ==
'u') || (optopt ==
'd') ||
439 (optopt ==
'c') || (optopt ==
't') || (optopt ==
'l') ||
442 "missing file or directory name.\n");
449 "missing name of binary architecture.\n");
462 if ((option ==
'i') || (option ==
'u') || (option ==
'q') ||
463 (option ==
'd') || (option ==
'c') || (option ==
't') ||
464 (option ==
'l') || (option ==
'r') || (option ==
'h') ||
503 if (optarg !=
NULL) {
505 strcpy(package, optarg);
507 strcpy(orgname, optarg);
513 gisbase =
malloc(
sizeof(
char) * (strlen(optarg) + 1));
514 strcpy(gisbase, optarg);
517 bins =
malloc(
sizeof(
char) * (strlen(optarg) + 1));
518 strcpy(bins, optarg);
541 strcat(coptions, optarg);
553 getopt_long(argc, argv,
":i:u:q:d:c:t:l:o:x:rhVg:b:fvs",
554 long_options, &option_index);
570 if (action ==
HELP) {
585 strcpy(
TMP_NULL,
"/tmp/grass.extension.log.XXXXXX");
600 if (gisbase ==
NULL) {
602 gisbase =
getenv(
"GISBASE");
603 if (gisbase ==
NULL) {
606 "GISBASE environment variable not set and path to GRASS not given.\n");
611 fprintf(stdout,
"Path to GRASS is %s.\n", gisbase);
614 restore(gisbase, grass_version);
618 if (action ==
LIST) {
621 if (gisbase ==
NULL) {
623 gisbase =
getenv(
"GISBASE");
624 if (gisbase ==
NULL) {
627 "GISBASE environment variable not set and path to GRASS not given.\n");
632 fprintf(stdout,
"Path to GRASS is %s.\n", gisbase);
639 if ((strstr(package,
"http://")) || (strstr(package,
"ftp://"))) {
642 url =
malloc(
sizeof(
char) * MAXSTR);
643 strcpy(url, package);
644 filepart = strrchr(url,
'/');
646 strcpy(package, filepart);
651 fprintf(stdout,
"Extension location is '%s'.\n", package);
655 error =
stat(package, &buf);
658 "extension FILE or DIR '%s' invalid: %s\n", package,
661 if (S_ISDIR(buf.st_mode)) {
664 fprintf(stdout,
"Extension files stored in a directory.\n");
670 "Extension files stored in a package file.\n");
679 while (dir_entry !=
NULL) {
680 if ((strcmp(dir_entry->d_name,
".")) &&
681 (strcmp(dir_entry->d_name,
".."))
686 if (S_ISDIR(buf2.st_mode)) {
693 strcpy(package, tmp);
695 if (dir_found == 0) {
697 "no top-level directory found in extension package.\n");
710 strcpy(pkg_short_name, package);
719 if (gisbase ==
NULL) {
721 gisbase =
getenv(
"GISBASE");
723 run_post(package, action, bins, gisbase);
727 fprintf(stdout,
"Extension will be installed from '%s'\n", package);
737 if (action ==
QUERY) {
739 pkg_short_name, invocation, orgname);
753 if (action ==
CLEAN) {
763 if (gisbase ==
NULL) {
765 gisbase =
getenv(
"GISBASE");
766 if (gisbase ==
NULL) {
769 "GISBASE environment variable not set and path to GRASS not given.\n");
774 fprintf(stdout,
"Path to GRASS is %s.\n", gisbase);
778 grass_version =
getenv(
"GRASS_VERSION");
779 if (grass_version ==
NULL) {
781 sprintf(version_file,
"%s/etc/VERSIONNUMBER", gisbase);
782 f = fopen(version_file,
"r");
786 "Could not read GRASS version. Did you specify the right path?\n");
789 grass_version =
malloc(
sizeof(
char) * 16);
790 error = fscanf(f,
"%s", grass_version);
794 "Could not read GRASS version. Did you specify the right path?\n");
799 if (grass_version !=
NULL) {
801 tmp = strdup(grass_version);
803 grass_major = strtok(tmp,
".");
804 grass_minor = strtok(
NULL,
".");
805 grass_revision = strtok(
NULL,
".");
807 major = strtol(grass_major,
NULL, 10);
808 minor = strtol(grass_minor,
NULL, 10);
809 revision = strtol(grass_revision,
NULL, 10);
811 grass_version =
malloc(
sizeof(
char) * MAXSTR);
812 sprintf(grass_version,
"%i.%i.%i", major, minor, revision);
814 fprintf(stdout,
"GRASS version is %s.\n", grass_version);
819 "extensions only work with GRASS version 6 and above.\n");
826 sprintf(coptions,
"-L%s/lib -I/usr/local/grasslib/include/ ", gisbase);
830 source_install(package, gisbase, pkg_short_name, pkg_major, pkg_minor,
831 pkg_revision, grass_version);
836 uninstall(package, pkg_short_name, gisbase, grass_version);
841 test_install(package, gisbase, pkg_short_name, pkg_major, pkg_minor,
842 pkg_revision, grass_version);
848 bin_install(package, gisbase, bins, pkg_short_name, pkg_major,
849 pkg_minor, pkg_revision, grass_version);
void query_extension(char *package, char *name, int major, int minor, int revision, char *short_name, char *invocation, char *org_name)
void source_install(char *package, char *gisbase, char *pkg_short_name, int pkg_major, int pkg_minor, int pkg_revision, char *grass_version)
void list_extensions(char *gisbase)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void bin_install(char *package, char *gisbase, char *bins, char *pkg_short_name, int pkg_major, int pkg_minor, int pkg_revision, char *grass_version)
EXTERN char CONFIG_OPTS[MAXSTR]
EXTERN char CONFIG_CMD[MAXSTR]
EXTERN char TMPDIR[MAXSTR]
EXTERN char GISMAN2_CMD[MAXSTR]
EXTERN char TMP_NULL[MAXSTR]
void print_error(int err_code, char *msg,...)
void uninstall(char *package, char *pkg_short_name, char *gisbase, char *grass_version)
EXTERN char TMP_HTML[MAXSTR]
void test_install(char *package, char *gisbase, char *pkg_short_name, int pkg_major, int pkg_minor, int pkg_revision, char *grass_version)
void get_configure_options(char *gisbase)
void show_license(char *package)
void unpack_extension(char *package)
EXTERN char QGIS_CMD[MAXSTR]
EXTERN char UNINSTALL_CMD[MAXSTR]
EXTERN char TMP_AUTHORS[MAXSTR]
void show_details(char *package)
EXTERN char TMP_BUGS[MAXSTR]
EXTERN char HTML_CMD[MAXSTR]
void check_extension(char *package, char *name, int *major, int *minor, int *revision)
int main(int argc, char *argv[])
EXTERN char TMP_DESCR[MAXSTR]
#define ERR_NO_ACCESS_EXT
EXTERN char TMPDB[MAXSTR]
void restore(char *gisbase, char *grass_version)
void run_post(char *package, int action, char *bins, char *gisbase)
EXTERN char MAKE_CMD[MAXSTR]
void print_warning(char *msg,...)
EXTERN char TMP_INFO[MAXSTR]
EXTERN char TMP_DEPS[MAXSTR]
EXTERN char GEM_C_OPTS[MAXSTR]
int source_clean(char *package)
EXTERN char GISMAN_CMD[MAXSTR]
EXTERN char TMP_GISMAN[MAXSTR]