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;
37 char *active_database=NULL,*alternate_database=NULL;
38 gchar *s,*prefix,*distribution,*vendor_prefix;
41 struct comps_group *group;
42 struct comps_requirement *pkg;
43 struct plover_vector *packages=NULL;
45 s=plover_get_program(argv0);
46 yum_uri=razor_path_to_uri(s);
48 s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
49 comps=plover_comps_new_from_uri(s,&error);
51 if (g_error_matches(error,PLOVER_RAZOR_ERROR,
52 RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE))
54 g_clear_error(&error);
56 s=plover_get_program_directory(argv0);
57 yum_uri=razor_path_to_uri(s);
59 s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
60 comps=plover_comps_new_from_uri(s,&error);
64 fprintf(stderr,"%s\n",error->message);
68 prefix=plover_comps_get_default_prefix(comps);
71 s=g_strconcat(prefix,"/var/lib/razor",NULL);
72 local_database=razor_path_to_uri(s);
77 switch(comps->database)
79 case COMPS_DATABASE_DISTRIBUTION_LOCAL:
80 active_database=local_database;
82 case COMPS_DATABASE_GLOBAL:
83 alternate_database=local_database;
88 distribution=g_strdup(comps->distribution);
89 plover_comps_set_distribution(comps,NULL);
90 vendor_prefix=plover_comps_get_default_prefix(comps);
91 plover_comps_set_distribution(comps,distribution);
93 razor_set_database_uri(alternate_database);
94 if (plover_installed_files_match_prefix(vendor_prefix)==1)
96 printf("There is an existing installation under %s\n"
97 "which is not compatible with this distribution. In order\n"
98 "to continue, the existing installation must be uninstalled.\n"
99 "Do you want to remove all packages in the existing installion? ",
102 if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
104 while(ch!='\n' && ch!=EOF)
106 if (plover_remove(NULL,&error))
108 fprintf(stderr,"%s\n",error->message);
113 g_free(vendor_prefix);
115 razor_set_database_uri(active_database);
116 free(local_database);
117 if (prefix && !plover_installed_files_match_prefix(prefix))
119 printf("The existing installation is not under %s\n"
120 "In order to continue, all the existing packages must be removed.\n"
121 "Do you want to remove all existing packages? ",prefix);
123 if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
125 while(ch!='\n' && ch!=EOF)
127 if (plover_remove(NULL,&error))
129 fprintf(stderr,"%s\n",error->message);
134 group=plover_comps_lookup_group(comps,"base");
137 fprintf(stderr,"No base group found in comps.xml\n");
140 packages=plover_vector_new();
144 for(pkg=group->packages;pkg;pkg=pkg->next)
146 if (plover_vector_contains(packages,pkg->name))
148 if (pkg->type==COMPS_REQUIREMENT_DEFAULT ||
149 pkg->type==COMPS_REQUIREMENT_MANDATORY ||
150 pkg->type==COMPS_REQUIREMENT_CONDITIONAL &&
151 plover_vector_contains(packages,pkg->requires))
154 plover_vector_append(packages,pkg->name);
158 plover_comps_free(comps);
161 fprintf(stderr,"No packages to install\n");
164 if (!plover_install_uri(yum_uri,prefix,packages->strings,&error))
166 fprintf(stderr,"%s\n",error->message);
170 plover_vector_free(packages);
175 int main(int argc,char **argv)
178 plover_exception_handler_init();
179 razor_set_lua_loader("posix",(void (*)())luaopen_posix);
180 razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
181 if (argc>1 && !strcmp(argv[1],"-u"))
183 if (!plover_remove(NULL,&error))
185 fprintf(stderr,"%s\n",error->message);