ali@0: /* ali@61: * Copyright (C) 2009, 2011, 2016 J. Ali Harlow ali@0: * ali@0: * This program is free software; you can redistribute it and/or modify ali@0: * it under the terms of the GNU General Public License as published by ali@0: * the Free Software Foundation; either version 2 of the License, or ali@0: * (at your option) any later version. ali@0: * ali@0: * This program is distributed in the hope that it will be useful, ali@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of ali@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ali@0: * GNU General Public License for more details. ali@0: * ali@0: * You should have received a copy of the GNU General Public License along ali@0: * with this program; if not, write to the Free Software Foundation, Inc., ali@0: * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ali@0: */ ali@0: ali@0: #include ali@0: #include ali@0: #include ali@0: #include ali@0: #ifdef WIN32 ali@0: #include ali@0: #include ali@0: #endif ali@0: #include ali@0: #include "config.h" ali@0: #include "plover/plover.h" ali@0: #include "whelk/whelk.h" ali@0: ali@0: LUALIB_API int luaopen_posix(lua_State *L); ali@0: ali@3: void setup(const char *argv0) ali@0: { ali@99: char *yum_uri,*local_database; ali@99: char *active_database=NULL,*alternate_database=NULL; ali@61: gchar *s,*prefix,*distribution,*vendor_prefix; ali@13: int ch,changed; ali@0: struct comps *comps; ali@0: struct comps_group *group; ali@0: struct comps_requirement *pkg; ali@24: struct plover_vector *packages=NULL; ali@24: GError *error=NULL; ali@61: s=plover_get_program(argv0); ali@61: yum_uri=razor_path_to_uri(s); ali@61: g_free(s); ali@61: s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL); ali@61: comps=plover_comps_new_from_uri(s,&error); ali@61: g_free(s); ali@61: if (g_error_matches(error,PLOVER_RAZOR_ERROR, ali@61: RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE)) ali@61: { ali@61: g_clear_error(&error); ali@61: free(yum_uri); ali@61: s=plover_get_program_directory(argv0); ali@61: yum_uri=razor_path_to_uri(s); ali@61: g_free(s); ali@61: s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL); ali@61: comps=plover_comps_new_from_uri(s,&error); ali@61: } ali@0: if (!comps) ali@0: { ali@61: fprintf(stderr,"%s\n",error->message); ali@61: g_error_free(error); ali@0: exit(1); ali@0: } ali@61: prefix=plover_comps_get_default_prefix(comps); ali@61: if (prefix) ali@61: { ali@61: s=g_strconcat(prefix,"/var/lib/razor",NULL); ali@61: local_database=razor_path_to_uri(s); ali@61: g_free(s); ali@61: } ali@61: else ali@61: local_database=NULL; ali@61: switch(comps->database) ali@61: { ali@61: case COMPS_DATABASE_DISTRIBUTION_LOCAL: ali@61: active_database=local_database; ali@61: break; ali@61: case COMPS_DATABASE_GLOBAL: ali@61: alternate_database=local_database; ali@61: break; ali@61: } ali@61: if (prefix) ali@61: { ali@61: distribution=g_strdup(comps->distribution); ali@61: plover_comps_set_distribution(comps,NULL); ali@61: vendor_prefix=plover_comps_get_default_prefix(comps); ali@61: plover_comps_set_distribution(comps,distribution); ali@61: g_free(distribution); ali@61: razor_set_database_uri(alternate_database); ali@61: if (plover_installed_files_match_prefix(vendor_prefix)==1) ali@61: { ali@61: printf("There is an existing installation under %s\n" ali@61: "which is not compatible with this distribution. In order\n" ali@61: "to continue, the existing installation must be uninstalled.\n" ali@61: "Do you want to remove all packages in the existing installion? ", ali@61: prefix); ali@61: ch=getchar(); ali@61: if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n') ali@61: exit(1); ali@61: while(ch!='\n' && ch!=EOF) ali@61: ch=getchar(); ali@61: if (plover_remove(NULL,&error)) ali@61: { ali@61: fprintf(stderr,"%s\n",error->message); ali@61: g_error_free(error); ali@61: exit(1); ali@61: } ali@61: } ali@61: g_free(vendor_prefix); ali@61: } ali@61: razor_set_database_uri(active_database); ali@61: free(local_database); ali@61: if (prefix && !plover_installed_files_match_prefix(prefix)) ali@13: { ali@13: printf("The existing installation is not under %s\n" ali@13: "In order to continue, all the existing packages must be removed.\n" ali@13: "Do you want to remove all existing packages? ",prefix); ali@13: ch=getchar(); ali@13: if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n') ali@13: exit(1); ali@13: while(ch!='\n' && ch!=EOF) ali@13: ch=getchar(); ali@24: if (plover_remove(NULL,&error)) ali@24: { ali@24: fprintf(stderr,"%s\n",error->message); ali@24: g_error_free(error); ali@24: exit(1); ali@24: } ali@13: } ali@0: group=plover_comps_lookup_group(comps,"base"); ali@0: if (!group) ali@0: { ali@0: fprintf(stderr,"No base group found in comps.xml\n"); ali@0: exit(1); ali@0: } ali@24: packages=plover_vector_new(); ali@0: do ali@0: { ali@0: changed=0; ali@0: for(pkg=group->packages;pkg;pkg=pkg->next) ali@0: { ali@24: if (plover_vector_contains(packages,pkg->name)) ali@0: continue; ali@0: if (pkg->type==COMPS_REQUIREMENT_DEFAULT || ali@0: pkg->type==COMPS_REQUIREMENT_MANDATORY || ali@0: pkg->type==COMPS_REQUIREMENT_CONDITIONAL && ali@24: plover_vector_contains(packages,pkg->requires)) ali@0: { ali@0: changed++; ali@24: plover_vector_append(packages,pkg->name); ali@0: } ali@0: } ali@0: } while(changed); ali@3: plover_comps_free(comps); ali@0: if (!packages->len) ali@0: { ali@0: fprintf(stderr,"No packages to install\n"); ali@0: exit(1); ali@0: } ali@61: if (!plover_install_uri(yum_uri,prefix,packages->strings,&error)) ali@24: { ali@24: fprintf(stderr,"%s\n",error->message); ali@24: g_error_free(error); ali@24: exit(1); ali@24: } ali@24: plover_vector_free(packages); ali@24: g_free(prefix); ali@61: free(yum_uri); ali@0: } ali@0: ali@0: int main(int argc,char **argv) ali@0: { ali@24: GError *error=NULL; ali@31: plover_exception_handler_init(); ali@38: razor_set_lua_loader("posix",(void (*)())luaopen_posix); ali@38: razor_set_lua_loader("whelk",(void (*)())luaopen_whelk); ali@0: if (argc>1 && !strcmp(argv[1],"-u")) ali@24: { ali@24: if (!plover_remove(NULL,&error)) ali@24: { ali@24: fprintf(stderr,"%s\n",error->message); ali@24: g_error_free(error); ali@24: exit(1); ali@24: } ali@24: } ali@0: else ali@3: setup(argv[0]); ali@13: exit(0); ali@0: }