ali@3: /* ali@59: * Copyright (C) 2009, 2011, 2016 J. Ali Harlow ali@3: * ali@3: * This program is free software; you can redistribute it and/or modify ali@3: * it under the terms of the GNU General Public License as published by ali@3: * the Free Software Foundation; either version 2 of the License, or ali@3: * (at your option) any later version. ali@3: * ali@3: * This program is distributed in the hope that it will be useful, ali@3: * but WITHOUT ANY WARRANTY; without even the implied warranty of ali@3: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ali@3: * GNU General Public License for more details. ali@3: * ali@3: * You should have received a copy of the GNU General Public License along ali@3: * with this program; if not, write to the Free Software Foundation, Inc., ali@3: * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ali@3: */ ali@3: ali@3: #include ali@13: #include ali@61: #include ali@3: #include ali@3: #include "config.h" ali@3: #include "plover/plover.h" ali@3: #include "whelk/whelk.h" ali@3: ali@3: LUALIB_API int luaopen_posix(lua_State *L); ali@3: ali@61: void update(const char *argv0) ali@3: { ali@61: char *yum_uri,*local_database,*active_database,*alternate_database; ali@61: gchar *s,*prefix,*distribution,*vendor_prefix; ali@13: int ch; ali@3: struct comps *comps; ali@24: GError *error=NULL; ali@59: s=plover_get_program(argv0); ali@61: yum_uri=razor_path_to_uri(s); ali@59: 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@3: if (!comps) ali@3: { ali@61: fprintf(stderr,"%s\n",error->message); ali@61: g_error_free(error); ali@3: exit(1); ali@3: } 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: alternate_database=NULL; ali@61: break; ali@61: case COMPS_DATABASE_GLOBAL: ali@61: active_database=NULL; 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: 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@61: free(local_database); ali@3: plover_comps_free(comps); ali@61: if (!plover_update_uri(yum_uri,prefix,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: g_free(prefix); ali@61: free(yum_uri); ali@3: } ali@3: ali@3: int main(int argc,char **argv) ali@3: { 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@61: update(argv[0]); ali@13: exit(0); ali@3: }