diff -r a29623b68ca2 -r 212150407fcc setup/setup.c --- a/setup/setup.c Mon Jun 13 12:18:42 2016 +0100 +++ b/setup/setup.c Tue Jul 14 13:17:21 2020 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011 J. Ali Harlow + * Copyright (C) 2009, 2011, 2016 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,25 +33,89 @@ void setup(const char *argv0) { - char *path; - gchar *s,*prefix; + char *yum_uri,*local_database,*active_database,*alternate_database; + gchar *s,*prefix,*distribution,*vendor_prefix; int ch,changed; struct comps *comps; struct comps_group *group; struct comps_requirement *pkg; struct plover_vector *packages=NULL; GError *error=NULL; - path=plover_get_program_directory(argv0); - s=g_strconcat(path,"/repodata/comps.xml",NULL); - comps=plover_comps_new_from_file(s); + s=plover_get_program(argv0); + yum_uri=razor_path_to_uri(s); + g_free(s); + s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL); + comps=plover_comps_new_from_uri(s,&error); + g_free(s); + if (g_error_matches(error,PLOVER_RAZOR_ERROR, + RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE)) + { + g_clear_error(&error); + free(yum_uri); + s=plover_get_program_directory(argv0); + yum_uri=razor_path_to_uri(s); + g_free(s); + s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL); + comps=plover_comps_new_from_uri(s,&error); + } if (!comps) { - perror(s); + fprintf(stderr,"%s\n",error->message); + g_error_free(error); exit(1); } - g_free(s); - prefix=plover_default_prefix_for_vendor(comps->vendor); - if (!plover_installed_files_match_prefix(prefix)) + prefix=plover_comps_get_default_prefix(comps); + if (prefix) + { + s=g_strconcat(prefix,"/var/lib/razor",NULL); + local_database=razor_path_to_uri(s); + g_free(s); + } + else + local_database=NULL; + switch(comps->database) + { + case COMPS_DATABASE_DISTRIBUTION_LOCAL: + active_database=local_database; + alternate_database=NULL; + break; + case COMPS_DATABASE_GLOBAL: + active_database=NULL; + alternate_database=local_database; + break; + } + if (prefix) + { + distribution=g_strdup(comps->distribution); + plover_comps_set_distribution(comps,NULL); + vendor_prefix=plover_comps_get_default_prefix(comps); + plover_comps_set_distribution(comps,distribution); + g_free(distribution); + razor_set_database_uri(alternate_database); + if (plover_installed_files_match_prefix(vendor_prefix)==1) + { + printf("There is an existing installation under %s\n" + "which is not compatible with this distribution. In order\n" + "to continue, the existing installation must be uninstalled.\n" + "Do you want to remove all packages in the existing installion? ", + prefix); + ch=getchar(); + if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n') + exit(1); + while(ch!='\n' && ch!=EOF) + ch=getchar(); + if (plover_remove(NULL,&error)) + { + fprintf(stderr,"%s\n",error->message); + g_error_free(error); + exit(1); + } + } + g_free(vendor_prefix); + } + razor_set_database_uri(active_database); + free(local_database); + if (prefix && !plover_installed_files_match_prefix(prefix)) { printf("The existing installation is not under %s\n" "In order to continue, all the existing packages must be removed.\n" @@ -98,7 +162,7 @@ fprintf(stderr,"No packages to install\n"); exit(1); } - if (!plover_install(path,prefix,packages->strings,&error)) + if (!plover_install_uri(yum_uri,prefix,packages->strings,&error)) { fprintf(stderr,"%s\n",error->message); g_error_free(error); @@ -106,7 +170,7 @@ } plover_vector_free(packages); g_free(prefix); - free(path); + free(yum_uri); } int main(int argc,char **argv)