setup/setup.c
changeset 69 1748c5d94fe2
parent 38 a29623b68ca2
child 99 0121592e2512
     1.1 --- a/setup/setup.c	Mon Jun 13 12:18:42 2016 +0100
     1.2 +++ b/setup/setup.c	Wed Apr 25 11:46:40 2018 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (C) 2009, 2011  J. Ali Harlow <ali@juiblex.co.uk>
     1.6 + * Copyright (C) 2009, 2011, 2016  J. Ali Harlow <ali@juiblex.co.uk>
     1.7   *
     1.8   * This program is free software; you can redistribute it and/or modify
     1.9   * it under the terms of the GNU General Public License as published by
    1.10 @@ -33,25 +33,89 @@
    1.11  
    1.12  void setup(const char *argv0)
    1.13  {
    1.14 -    char *path;
    1.15 -    gchar *s,*prefix;
    1.16 +    char *yum_uri,*local_database,*active_database,*alternate_database;
    1.17 +    gchar *s,*prefix,*distribution,*vendor_prefix;
    1.18      int ch,changed;
    1.19      struct comps *comps;
    1.20      struct comps_group *group;
    1.21      struct comps_requirement *pkg;
    1.22      struct plover_vector *packages=NULL;
    1.23      GError *error=NULL;
    1.24 -    path=plover_get_program_directory(argv0);
    1.25 -    s=g_strconcat(path,"/repodata/comps.xml",NULL);
    1.26 -    comps=plover_comps_new_from_file(s);
    1.27 +    s=plover_get_program(argv0);
    1.28 +    yum_uri=razor_path_to_uri(s);
    1.29 +    g_free(s);
    1.30 +    s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
    1.31 +    comps=plover_comps_new_from_uri(s,&error);
    1.32 +    g_free(s);
    1.33 +    if (g_error_matches(error,PLOVER_RAZOR_ERROR,
    1.34 +      RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE))
    1.35 +    {
    1.36 +	g_clear_error(&error);
    1.37 +	free(yum_uri);
    1.38 +	s=plover_get_program_directory(argv0);
    1.39 +	yum_uri=razor_path_to_uri(s);
    1.40 +	g_free(s);
    1.41 +	s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
    1.42 +	comps=plover_comps_new_from_uri(s,&error);
    1.43 +    }
    1.44      if (!comps)
    1.45      {
    1.46 -	perror(s);
    1.47 +	fprintf(stderr,"%s\n",error->message);
    1.48 +	g_error_free(error);
    1.49  	exit(1);
    1.50      }
    1.51 -    g_free(s);
    1.52 -    prefix=plover_default_prefix_for_vendor(comps->vendor);
    1.53 -    if (!plover_installed_files_match_prefix(prefix))
    1.54 +    prefix=plover_comps_get_default_prefix(comps);
    1.55 +    if (prefix)
    1.56 +    {
    1.57 +	s=g_strconcat(prefix,"/var/lib/razor",NULL);
    1.58 +	local_database=razor_path_to_uri(s);
    1.59 +	g_free(s);
    1.60 +    }
    1.61 +    else
    1.62 +	local_database=NULL;
    1.63 +    switch(comps->database)
    1.64 +    {
    1.65 +	case COMPS_DATABASE_DISTRIBUTION_LOCAL:
    1.66 +	    active_database=local_database;
    1.67 +	    alternate_database=NULL;
    1.68 +	    break;
    1.69 +	case COMPS_DATABASE_GLOBAL:
    1.70 +	    active_database=NULL;
    1.71 +	    alternate_database=local_database;
    1.72 +	    break;
    1.73 +    }
    1.74 +    if (prefix)
    1.75 +    {
    1.76 +	distribution=g_strdup(comps->distribution);
    1.77 +	plover_comps_set_distribution(comps,NULL);
    1.78 +	vendor_prefix=plover_comps_get_default_prefix(comps);
    1.79 +	plover_comps_set_distribution(comps,distribution);
    1.80 +	g_free(distribution);
    1.81 +	razor_set_database_uri(alternate_database);
    1.82 +	if (plover_installed_files_match_prefix(vendor_prefix)==1)
    1.83 +	{
    1.84 +	    printf("There is an existing installation under %s\n"
    1.85 +	      "which is not compatible with this distribution. In order\n"
    1.86 +	      "to continue, the existing installation must be uninstalled.\n"
    1.87 +	      "Do you want to remove all packages in the existing installion? ",
    1.88 +	      prefix);
    1.89 +	    ch=getchar();
    1.90 +	    if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
    1.91 +		exit(1);
    1.92 +	    while(ch!='\n' && ch!=EOF)
    1.93 +		ch=getchar();
    1.94 +	    if (plover_remove(NULL,&error))
    1.95 +	    {
    1.96 +		fprintf(stderr,"%s\n",error->message);
    1.97 +		g_error_free(error);
    1.98 +		exit(1);
    1.99 +	    }
   1.100 +	}
   1.101 +	g_free(vendor_prefix);
   1.102 +    }
   1.103 +    razor_set_database_uri(active_database);
   1.104 +    free(local_database);
   1.105 +    if (prefix && !plover_installed_files_match_prefix(prefix))
   1.106      {
   1.107  	printf("The existing installation is not under %s\n"
   1.108  	  "In order to continue, all the existing packages must be removed.\n"
   1.109 @@ -98,7 +162,7 @@
   1.110  	fprintf(stderr,"No packages to install\n");
   1.111  	exit(1);
   1.112      }
   1.113 -    if (!plover_install(path,prefix,packages->strings,&error))
   1.114 +    if (!plover_install_uri(yum_uri,prefix,packages->strings,&error))
   1.115      {
   1.116  	fprintf(stderr,"%s\n",error->message);
   1.117  	g_error_free(error);
   1.118 @@ -106,7 +170,7 @@
   1.119      }
   1.120      plover_vector_free(packages);
   1.121      g_free(prefix);
   1.122 -    free(path);
   1.123 +    free(yum_uri);
   1.124  }
   1.125  
   1.126  int main(int argc,char **argv)