/* * Copyright (C) 2009, 2011 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include #include #ifdef WIN32 #include #include #endif #include #include "config.h" #include "plover/plover.h" #include "whelk/whelk.h" LUALIB_API int luaopen_posix(lua_State *L); void setup(const char *argv0) { char *path; gchar *s,*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); if (!comps) { perror(s); exit(1); } g_free(s); prefix=plover_default_prefix_for_vendor(comps->vendor); if (!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" "Do you want to remove all existing packages? ",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); } } group=plover_comps_lookup_group(comps,"base"); if (!group) { fprintf(stderr,"No base group found in comps.xml\n"); exit(1); } packages=plover_vector_new(); do { changed=0; for(pkg=group->packages;pkg;pkg=pkg->next) { if (plover_vector_contains(packages,pkg->name)) continue; if (pkg->type==COMPS_REQUIREMENT_DEFAULT || pkg->type==COMPS_REQUIREMENT_MANDATORY || pkg->type==COMPS_REQUIREMENT_CONDITIONAL && plover_vector_contains(packages,pkg->requires)) { changed++; plover_vector_append(packages,pkg->name); } } } while(changed); plover_comps_free(comps); if (!packages->len) { fprintf(stderr,"No packages to install\n"); exit(1); } if (!plover_install(path,prefix,packages->strings,&error)) { fprintf(stderr,"%s\n",error->message); g_error_free(error); exit(1); } plover_vector_free(packages); g_free(prefix); free(path); } int main(int argc,char **argv) { GError *error=NULL; plover_exception_handler_init(); razor_set_lua_loader("posix",(void (*)())luaopen_posix); razor_set_lua_loader("whelk",(void (*)())luaopen_whelk); if (argc>1 && !strcmp(argv[1],"-u")) { if (!plover_remove(NULL,&error)) { fprintf(stderr,"%s\n",error->message); g_error_free(error); exit(1); } } else setup(argv[0]); exit(0); }