150 fprintf(stdout,
"Usage: gem64 [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 "\tgem64 -b macosx --grass=/usr/local/grass-6.4.0 -i myExtension\n");
208 "Installs the MacOS X binaries for 'myExtension' in /usr/local/grass-6.4.0.\n");
218 sprintf(tmp,
"%s",
basename(package));
222 "extension '%s' not accessible: (%s)\n", package,
241 sprintf(tmp,
"%s",
basename(package));
245 "extension '%s' not accessible: (%s)\n", package,
249 dump_ascii(
"license",
"Detailed information");
260 fprintf(stdout,
"gem64 (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");
404 tmp = malloc(
sizeof(
char) *
MAXSTR);
405 strcpy(invocation, argv[0]);
408 setvbuf(stdout, (
char *)
NULL, _IONBF, 0);
425 getopt_long(argc, argv,
":i:u:q:d:c:C:t:l:m:o:x:rhVg:b:fvs",
426 long_options, &option_index);
427 while (option != -1) {
431 "unknown option or action specified.\n");
437 if ((optopt ==
'i') || (optopt ==
'u') || (optopt ==
'd') ||
438 (optopt ==
'c') || (optopt ==
't') || (optopt ==
'l') ||
441 "missing file or directory name.\n");
448 "missing name of binary architecture.\n");
461 if ((option ==
'i') || (option ==
'u') || (option ==
'q') ||
462 (option ==
'd') || (option ==
'c') || (option ==
't') ||
463 (option ==
'l') || (option ==
'r') || (option ==
'h') ||
502 if (optarg !=
NULL) {
504 strcpy(package, optarg);
506 strcpy(orgname, optarg);
512 gisbase = malloc(
sizeof(
char) * (strlen(optarg) + 1));
513 strcpy(gisbase, optarg);
516 bins = malloc(
sizeof(
char) * (strlen(optarg) + 1));
517 strcpy(bins, optarg);
540 strcat(coptions, optarg);
552 getopt_long(argc, argv,
":i:u:q:d:c:t:l:o:x:rhVg:b:fvs",
553 long_options, &option_index);
565 sprintf(
GEM_C_OPTS,
"GEM_C_OPTS=%s", coptions);
569 if (action ==
HELP) {
584 strcpy(
TMP_NULL,
"/tmp/grass.extension.log.XXXXXX");
599 if (gisbase ==
NULL) {
601 gisbase =
getenv(
"GISBASE");
602 if (gisbase ==
NULL) {
605 "GISBASE environment variable not set and path to GRASS not given.\n");
610 fprintf(stdout,
"Path to GRASS is %s.\n", gisbase);
613 restore(gisbase, grass_version);
617 if (action ==
LIST) {
620 if (gisbase ==
NULL) {
622 gisbase =
getenv(
"GISBASE");
623 if (gisbase ==
NULL) {
626 "GISBASE environment variable not set and path to GRASS not given.\n");
631 fprintf(stdout,
"Path to GRASS is %s.\n", gisbase);
638 if ((strstr(package,
"http://")) || (strstr(package,
"ftp://"))) {
641 url = malloc(
sizeof(
char) * MAXSTR);
642 strcpy(url, package);
643 filepart = strrchr(url,
'/');
645 strcpy(package, filepart);
650 fprintf(stdout,
"Extension location is '%s'.\n", package);
654 error = stat(package, &buf);
657 "extension FILE or DIR '%s' invalid: %s\n", package,
660 if (S_ISDIR(buf.st_mode)) {
663 fprintf(stdout,
"Extension files stored in a directory.\n");
669 "Extension files stored in a package file.\n");
678 while (dir_entry !=
NULL) {
679 if ((strcmp(dir_entry->d_name,
".")) &&
680 (strcmp(dir_entry->d_name,
".."))
683 sprintf(tmp,
"%s/%s",
TMPDIR, dir_entry->d_name);
685 if (S_ISDIR(buf2.st_mode)) {
692 strcpy(package, tmp);
694 if (dir_found == 0) {
696 "no top-level directory found in extension package.\n");
709 strcpy(pkg_short_name, package);
718 if (gisbase ==
NULL) {
720 gisbase =
getenv(
"GISBASE");
722 run_post(package, action, bins, gisbase);
726 fprintf(stdout,
"Extension will be installed from '%s'\n", package);
736 if (action ==
QUERY) {
738 pkg_short_name, invocation, orgname);
752 if (action ==
CLEAN) {
762 if (gisbase ==
NULL) {
764 gisbase =
getenv(
"GISBASE");
765 if (gisbase ==
NULL) {
768 "GISBASE environment variable not set and path to GRASS not given.\n");
773 fprintf(stdout,
"Path to GRASS is %s.\n", gisbase);
777 grass_version =
getenv(
"GRASS_VERSION");
778 if (grass_version ==
NULL) {
780 sprintf(version_file,
"%s/etc/VERSIONNUMBER", gisbase);
781 f = fopen(version_file,
"r");
785 "Could not read GRASS version. Did you specify the right path?\n");
788 grass_version = malloc(
sizeof(
char) * 16);
789 error = fscanf(f,
"%s", grass_version);
793 "Could not read GRASS version. Did you specify the right path?\n");
798 if (grass_version !=
NULL) {
800 tmp = strdup(grass_version);
802 grass_major = strtok(tmp,
".");
803 grass_minor = strtok(
NULL,
".");
804 grass_revision = strtok(
NULL,
".");
806 major = strtol(grass_major,
NULL, 10);
807 minor = strtol(grass_minor,
NULL, 10);
808 revision = strtol(grass_revision,
NULL, 10);
810 grass_version = malloc(
sizeof(
char) * MAXSTR);
811 sprintf(grass_version,
"%i.%i.%i", major, minor, revision);
813 fprintf(stdout,
"GRASS version is %s.\n", grass_version);
818 "extensions only work with GRASS version 6 and above.\n");
825 sprintf(coptions,
"-L%s/lib -I/usr/local/grasslib/include/ ", gisbase);
829 source_install(package, gisbase, pkg_short_name, pkg_major, pkg_minor,
830 pkg_revision, grass_version);
835 uninstall(package, pkg_short_name, gisbase, grass_version);
840 test_install(package, gisbase, pkg_short_name, pkg_major, pkg_minor,
841 pkg_revision, grass_version);
847 bin_install(package, gisbase, bins, pkg_short_name, pkg_major,
848 pkg_minor, pkg_revision, grass_version);