ali@0: /* ali@13: * Copyright (C) 2009, 2011 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@24: char *path; ali@24: gchar *s,*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@3: path=plover_get_program_directory(argv0); ali@24: s=g_strconcat(path,"/repodata/comps.xml",NULL); ali@0: comps=plover_comps_new_from_file(s); ali@0: if (!comps) ali@0: { ali@0: perror(s); ali@0: exit(1); ali@0: } ali@24: g_free(s); ali@3: prefix=plover_default_prefix_for_vendor(comps->vendor); ali@13: if (!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@24: if (!plover_install(path,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@3: free(path); ali@0: } ali@0: ali@0: int main(int argc,char **argv) ali@0: { ali@24: GError *error=NULL; ali@0: razor_set_lua_loader("posix",luaopen_posix); ali@0: razor_set_lua_loader("whelk",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: }