Fix bug causing a transaction without a base to be treated as a programming error
2 * Copyright (C) 2009, 2011, 2016 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "plover/plover.h"
30 #include "whelk/whelk.h"
32 LUALIB_API int luaopen_posix(lua_State *L);
34 void setup(const char *argv0)
36 char *yum_uri,*local_database,*active_database,*alternate_database;
37 gchar *s,*prefix,*distribution,*vendor_prefix;
40 struct comps_group *group;
41 struct comps_requirement *pkg;
42 struct plover_vector *packages=NULL;
44 s=plover_get_program(argv0);
45 yum_uri=razor_path_to_uri(s);
47 s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
48 comps=plover_comps_new_from_uri(s,&error);
50 if (g_error_matches(error,PLOVER_RAZOR_ERROR,
51 RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE))
53 g_clear_error(&error);
55 s=plover_get_program_directory(argv0);
56 yum_uri=razor_path_to_uri(s);
58 s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
59 comps=plover_comps_new_from_uri(s,&error);
63 fprintf(stderr,"%s\n",error->message);
67 prefix=plover_comps_get_default_prefix(comps);
70 s=g_strconcat(prefix,"/var/lib/razor",NULL);
71 local_database=razor_path_to_uri(s);
76 switch(comps->database)
78 case COMPS_DATABASE_DISTRIBUTION_LOCAL:
79 active_database=local_database;
80 alternate_database=NULL;
82 case COMPS_DATABASE_GLOBAL:
84 alternate_database=local_database;
89 distribution=g_strdup(comps->distribution);
90 plover_comps_set_distribution(comps,NULL);
91 vendor_prefix=plover_comps_get_default_prefix(comps);
92 plover_comps_set_distribution(comps,distribution);
94 razor_set_database_uri(alternate_database);
95 if (plover_installed_files_match_prefix(vendor_prefix)==1)
97 printf("There is an existing installation under %s\n"
98 "which is not compatible with this distribution. In order\n"
99 "to continue, the existing installation must be uninstalled.\n"
100 "Do you want to remove all packages in the existing installion? ",
103 if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
105 while(ch!='\n' && ch!=EOF)
107 if (plover_remove(NULL,&error))
109 fprintf(stderr,"%s\n",error->message);
114 g_free(vendor_prefix);
116 razor_set_database_uri(active_database);
117 free(local_database);
118 if (prefix && !plover_installed_files_match_prefix(prefix))
120 printf("The existing installation is not under %s\n"
121 "In order to continue, all the existing packages must be removed.\n"
122 "Do you want to remove all existing packages? ",prefix);
124 if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
126 while(ch!='\n' && ch!=EOF)
128 if (plover_remove(NULL,&error))
130 fprintf(stderr,"%s\n",error->message);
135 group=plover_comps_lookup_group(comps,"base");
138 fprintf(stderr,"No base group found in comps.xml\n");
141 packages=plover_vector_new();
145 for(pkg=group->packages;pkg;pkg=pkg->next)
147 if (plover_vector_contains(packages,pkg->name))
149 if (pkg->type==COMPS_REQUIREMENT_DEFAULT ||
150 pkg->type==COMPS_REQUIREMENT_MANDATORY ||
151 pkg->type==COMPS_REQUIREMENT_CONDITIONAL &&
152 plover_vector_contains(packages,pkg->requires))
155 plover_vector_append(packages,pkg->name);
159 plover_comps_free(comps);
162 fprintf(stderr,"No packages to install\n");
165 if (!plover_install_uri(yum_uri,prefix,packages->strings,&error))
167 fprintf(stderr,"%s\n",error->message);
171 plover_vector_free(packages);
176 int main(int argc,char **argv)
179 plover_exception_handler_init();
180 razor_set_lua_loader("posix",(void (*)())luaopen_posix);
181 razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
182 if (argc>1 && !strcmp(argv[1],"-u"))
184 if (!plover_remove(NULL,&error))
186 fprintf(stderr,"%s\n",error->message);